Completed
Pull Request — master (#13)
by Victor
01:57
created

TextFile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace LazyEight\DiTesto;
4
5
use LazyEight\DiTesto\Collections\ArrayObjectLine;
6
use LazyEight\DiTesto\Interfaces\TraversableFileInterface;
7
8
class TextFile extends AbstractFile implements TraversableFileInterface
9
{
10
    /**
11
     * @var ArrayObjectLine
12
     */
13
    private $lines;
14
15
    /**
16
     * @inheritDoc
17
     */
18 2
    public function __construct($path, $content = '')
19
    {
20 2
        parent::__construct($path, $content);
21 2
        $this->readLines();
22 2
    }
23
24
    /**
25
     * @param string $content
0 ignored issues
show
Bug introduced by
There is no parameter named $content. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
26
     */
27
    private function readLines()
28
    {
29 3
        $this->lines = new ArrayObjectLine(array_map(function ($line) {
30 3
            return new Line($line);
31 3
        }, explode(PHP_EOL, parent::getRawContent())));
1 ignored issue
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getRawContent() instead of readLines()). Are you sure this is correct? If so, you might want to change this to $this->getRawContent().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
32 3
    }
33
34 2
    public function getRawContent(): string
35
    {
36 2
        return $this->lines->getRawContent();
37
    }
38
39 2
    public function setRawContent(string $content)
40
    {
41 2
        parent::setRawContent($content);
42 2
        $this->readLines();
43 2
    }
44
45
    /**
46
     * @return \ArrayIterator
47
     */
48 1
    public function getIterator()
49
    {
50 1
        return $this->lines->getIterator();
51
    }
52
53
    /**
54
     * @param mixed $offset
55
     * @return bool
56
     */
57 2
    public function offsetExists($offset)
58
    {
59 2
        return $this->lines->offsetExists($offset);
60
    }
61
62
    /**
63
     * @param mixed $offset
64
     * @return mixed
65
     */
66 1
    public function offsetGet($offset)
67
    {
68 1
        return $this->lines->offsetGet($offset);
69
    }
70
71
    /**
72
     * @param mixed $offset
73
     * @param mixed $value
74
     */
75 1
    public function offsetSet($offset, $value)
76
    {
77 1
        $this->lines->offsetSet($offset, $value);
78 1
    }
79
80
    /**
81
     * @param mixed $offset
82
     */
83 1
    public function offsetUnset($offset)
84
    {
85 1
        $this->lines->offsetUnset($offset);
86 1
    }
87
88
    /**
89
     * @return int
90
     */
91 1
    public function count()
92
    {
93 1
        return $this->lines->count();
94
    }
95
96
    /**
97
     * @inheritDoc
98
     */
99 1
    public function __toString()
100
    {
101 1
        return $this->getRawContent();
102
    }
103
}
104