for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SubjectivePHP\Csv;
use SplFileObject;
final class HeaderStrategy implements HeaderStrategyInterface
{
/**
* @var callable
*/
private $getHeadersCallable;
private function __construct(callable $getHeadersCallable)
$this->getHeadersCallable = $getHeadersCallable;
}
* Create header strategy which derives the headers from the first line of the file.
*
* @return HeaderstrategyInterface
public static function derive() : HeaderStrategyInterface
return new self(
function (SplFileObject $fileObject) : array {
$row = $fileObject->fgetcsv();
$fileObject->rewind();
return $row;
);
* Create header strategy which uses the provided headers array.
public static function provide(array $headers) : HeaderStrategyInterface
function (SplFileObject $fileObject) use ($headers) : array {
$fileObject
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
return $headers;
* Create header strategy which generates a numeric array whose size is the number of columns in the given file.
public static function none() : HeaderStrategyInterface
$firstRow = $fileObject->fgetcsv();
$headers = array_keys($firstRow);
* Extracts headers from the given SplFileObject.
* @param SplFileObject $fileObject The delimited file containing the headers.
* @return array
public function getHeaders(SplFileObject $fileObject) : array
return ($this->getHeadersCallable)($fileObject);
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.