Completed
Pull Request — master (#31)
by Chad
01:44
created

DeriveHeaderStrategy::getHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace SubjectivePHP\Csv;
4
5
use SplFileObject;
6
7
/**
8
 * Header strategy which derives the headers from the first line of the file.
9
 */
10 View Code Duplication
final class DeriveHeaderStrategy implements HeaderStrategyInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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