Analysis result

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

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: 6

Warning: 0

Severity Type Message Location
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 Method name "CSV::set_filepath" is not in camel caps format Line 12, column 12
5 ERROR Method name "CSV::set_header_row" is not in camel caps format Line 20, column 12
5 ERROR Method name "CSV::write_csv" is not in camel caps format Line 27, column 12
5 ERROR Method name "CSV::get_csv" is not in camel caps format Line 52, column 12
5 ERROR Method name "CSV::ValidateFilepath" is not in camel caps format Line 75, column 13