first commit - working
This commit is contained in:
		
							
								
								
									
										37
									
								
								src/Models/GitTop100.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/Models/GitTop100.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Top100stars\Models;
 | 
			
		||||
 | 
			
		||||
use Top100stars\Interfaces\IGitTop100CSV;
 | 
			
		||||
 | 
			
		||||
class GitTop100 implements IGitTop100CSV {
 | 
			
		||||
    private $csv = null;
 | 
			
		||||
 | 
			
		||||
    public function __construct(?string $fileName) {
 | 
			
		||||
        if ($fileName!=null) $this->loadCSV($fileName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function loadCSV(string $fileName) {
 | 
			
		||||
        if (($gestor = fopen($fileName, "r")) !== FALSE) {
 | 
			
		||||
            $this->csv = [];
 | 
			
		||||
            while (($datos = fgetcsv($gestor, 1000, ",")) !== FALSE) {
 | 
			
		||||
                $this->csv[] = $datos;
 | 
			
		||||
            }
 | 
			
		||||
            fclose($gestor);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setCSV($csv): IGitTop100CSV
 | 
			
		||||
    {
 | 
			
		||||
        $this->csv = $csv;
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCSV(): ?array {
 | 
			
		||||
        return $this->csv;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user