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

DeriveHeaderStrategy   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 6 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
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