Analysis result

Scanned at : 2025-10-24
Analyzed by : Coding Standard PSR12

Your PHP Code Snippet

                    
<?php
class CSV{
    public $header_row = array(), $results = array();

    private $filepath = null, $ext = null;

    public function __construct($filepath = null){
        if($filepath)
            $this->set_filepath($filepath);
    }

    public function set_filepath($filepath){
        if(!$this->ValidateFilepath($filepath))
            return false;

        $this->filepath = $filepath;
        return true;
    }

    public function set_header_row($header_row){
        if(!is_array($header_row))
            return null;

        $this->header_row = $header_row;
    }

    public function write_csv($data, $header = null, $filepath = null){
        if($filepath)
            if(!$this->set_filepath($filepath))
                return false;

        if(!is_array($data))
            return;

        if(!($file = fopen($this->filepath, "w")))
            return false;

        if($header && is_array($header))
            fputcsv($file, $header);

        foreach($data as $csv_data){
            if(is_string($csv_data))
                $csv_data = array($csv_data);

            fputcsv($file, $csv_data);
        }
        fclose($file);

        return true;
    }

    public function get_csv($filepath = null, $header = false, $delimiter = ","){
        if($filepath)
            if(!$this->set_filepath($filepath))
                return false;

        if(!($file = fopen($this->filepath, "r")))
            return null;

        while(($data = fgetcsv($file, 10000, $delimiter)))
            array_push($this->results, $data);

        if($header){
            $this->header_row = array_shift($this->results);
            foreach($this->results as $index => $result)
                $this->results[$index] = array_combine($this->header_row, $this->results[$index]);
        }

        fclose($file);

        return $this->results;

    }

    private function ValidateFilepath($filepath){
        $extension = explode(".", $filepath);

        if(count($extension) > 2)
            return false;

        if($extension[1] !== "csv")
            return false;

        $this->ext = "csv";

        return true;
    }

}
                    
                

Like you the result ?

Errors: 56

Warning: 0

Severity Type Message Location
5 ERROR Header blocks must be separated by a single blank line Line 1, column 1
5 ERROR End of line character is invalid; expected "\n" but found "\r\n" Line 1, column 1
5 ERROR Each class must be in a namespace of at least one level (a top-level vendor name) Line 2, column 1
5 ERROR Opening brace of a class must be on the line after the definition Line 2, column 10
5 ERROR There must not be more than one property declared per statement Line 3, column 12
5 ERROR There must not be more than one property declared per statement Line 5, column 13
5 ERROR Opening brace should be on a new line Line 7, column 50
5 ERROR Expected 1 space after IF keyword; 0 found Line 8, column 9
5 ERROR Inline control structures are not allowed Line 8, column 9
5 ERROR Method name "CSV::set_filepath" is not in camel caps format Line 12, column 12
5 ERROR Opening brace should be on a new line Line 12, column 44
5 ERROR Expected 1 space after IF keyword; 0 found Line 13, column 9
5 ERROR Inline control structures are not allowed Line 13, column 9
5 ERROR Method name "CSV::set_header_row" is not in camel caps format Line 20, column 12
5 ERROR Opening brace should be on a new line Line 20, column 48
5 ERROR Expected 1 space after IF keyword; 0 found Line 21, column 9
5 ERROR Inline control structures are not allowed Line 21, column 9
5 ERROR Method name "CSV::write_csv" is not in camel caps format Line 27, column 12
5 ERROR Opening brace should be on a new line Line 27, column 71
5 ERROR Expected 1 space after IF keyword; 0 found Line 28, column 9
5 ERROR Inline control structures are not allowed Line 28, column 9
5 ERROR Expected 1 space after IF keyword; 0 found Line 29, column 13
5 ERROR Inline control structures are not allowed Line 29, column 13
5 ERROR Expected 1 space after IF keyword; 0 found Line 32, column 9
5 ERROR Inline control structures are not allowed Line 32, column 9
5 ERROR Expected 1 space after IF keyword; 0 found Line 35, column 9
5 ERROR Inline control structures are not allowed Line 35, column 9
5 ERROR Expected 1 space after IF keyword; 0 found Line 38, column 9
5 ERROR Inline control structures are not allowed Line 38, column 9
5 ERROR Expected 1 space after FOREACH keyword; 0 found Line 41, column 9
5 ERROR Expected 1 space after closing parenthesis; found 0 Line 41, column 35
5 ERROR Expected 1 space after IF keyword; 0 found Line 42, column 13
5 ERROR Inline control structures are not allowed Line 42, column 13
5 ERROR Method name "CSV::get_csv" is not in camel caps format Line 52, column 12
5 ERROR Opening brace should be on a new line Line 52, column 81
5 ERROR Expected 1 space after IF keyword; 0 found Line 53, column 9
5 ERROR Inline control structures are not allowed Line 53, column 9
5 ERROR Expected 1 space after IF keyword; 0 found Line 54, column 13
5 ERROR Inline control structures are not allowed Line 54, column 13
5 ERROR Expected 1 space after IF keyword; 0 found Line 57, column 9
5 ERROR Inline control structures are not allowed Line 57, column 9
5 ERROR Expected 1 space after WHILE keyword; 0 found Line 60, column 9
5 ERROR Inline control structures are not allowed Line 60, column 9
5 ERROR Expected 1 space after IF keyword; 0 found Line 63, column 9
5 ERROR Expected 1 space after closing parenthesis; found 0 Line 63, column 19
5 ERROR Expected 1 space after FOREACH keyword; 0 found Line 65, column 13
5 ERROR Inline control structures are not allowed Line 65, column 13
5 ERROR Function closing brace must go on the next line following the body; found 1 blank lines before brace Line 73, column 5
5 ERROR Method name "CSV::ValidateFilepath" is not in camel caps format Line 75, column 13
5 ERROR Opening brace should be on a new line Line 75, column 49
5 ERROR Expected 1 space after IF keyword; 0 found Line 78, column 9
5 ERROR Inline control structures are not allowed Line 78, column 9
5 ERROR Expected 1 space after IF keyword; 0 found Line 81, column 9
5 ERROR Inline control structures are not allowed Line 81, column 9
5 ERROR Expected 1 newline at end of file; 0 found Line 89, column 1
5 ERROR The closing brace for the class must go on the next line after the body Line 89, column 1