Code Duplication    Length = 27-31 lines in 2 locations

src/DeriveHeaderStrategy.php 1 location

@@ 10-40 (lines=31) @@
7
/**
8
 * Header strategy which derives the headers from the first line of the file.
9
 */
10
final class DeriveHeaderStrategy implements HeaderStrategyInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $headers;
16
17
    /**
18
     * Extracts headers from the given SplFileObject.
19
     *
20
     * @param SplFileObject $fileObject The delimited file containing the headers.
21
     *
22
     * @return array
23
     */
24
    public function getHeaders(SplFileObject $fileObject) : array
25
    {
26
        $this->headers = $fileObject->fgetcsv() ?? [];
27
        $fileObject->rewind();
28
        return $this->headers;
29
    }
30
31
    public function isHeaderRow(array $row) : bool
32
    {
33
        return $row === $this->headers;
34
    }
35
36
    public function createDataRow(array $row) : array
37
    {
38
        return array_combine($this->headers, $row);
39
    }
40
}
41

src/ProvidedHeaderStrategy.php 1 location

@@ 10-36 (lines=27) @@
7
/**
8
 * Header strategy which uses the provided headers array.
9
 */
10
final class ProvidedHeaderStrategy implements HeaderStrategyInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $headers;
16
17
    public function __construct(array $headers)
18
    {
19
        $this->headers = $headers;
20
    }
21
22
    public function getHeaders(SplFileObject $fileObject) : array
23
    {
24
        return $this->headers;
25
    }
26
27
    public function isHeaderRow(array $row) : bool
28
    {
29
        return $row === $this->headers;
30
    }
31
32
    public function createDataRow(array $row) : array
33
    {
34
        return array_combine($this->headers, $row);
35
    }
36
}
37