Completed
Push — master ( e997f4...78645e )
by Pablo
02:18
created

FileReader::trimContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace IgnoreFiles\Infrastructure\Disk;
4
5
class FileReader
6
{
7
    /**
8
     * @var string
9
     */
10
    private $file;
11
12
    /**
13
     * FileReader constructor.
14
     *
15
     * @param string $file
16
     */
17
    public function __construct($file)
18
    {
19
        $this->file = $file;
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function read()
26
    {
27
        if (false === $this->fileExists()) {
28
            return [];
29
        }
30
31
        return $this->getFileContent();
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    private function fileExists()
38
    {
39
        return file_exists($this->file);
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    private function getFileContent()
46
    {
47
        $content = file($this->file);
48
49
        return $this->trimContent($content);
50
    }
51
52
    /**
53
     * @param array $contentData
54
     *
55
     * @return array
56
     */
57
    private function trimContent(array $contentData)
58
    {
59
        $data = [];
60
61
        foreach ($contentData as $item) {
62
            $data[] = trim($item);
63
        }
64
65
        return $data;
66
    }
67
}
68