FileResource::getFile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3.576

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 6
cts 10
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 0
crap 3.576
1
<?php
2
3
namespace TreeHouse\Feeder\Resource;
4
5
use TreeHouse\Feeder\Exception\TransportException;
6
use TreeHouse\Feeder\Transport\TransportInterface;
7
8
class FileResource implements ResourceInterface
9
{
10
    /**
11
     * @var TransportInterface
12
     */
13
    protected $transport;
14
15
    /**
16
     * @var \SplFileObject
17
     */
18
    protected $file;
19
20
    /**
21
     * @param TransportInterface $transport
22
     */
23 42
    public function __construct(TransportInterface $transport)
24
    {
25 42
        $this->transport = $transport;
26 42
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31 10
    public function getTransport()
32
    {
33 10
        return $this->transport;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 2
    public function setFile(\SplFileObject $file)
40
    {
41 2
        $this->file = $file;
42 2
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 38 View Code Duplication
    public function getFile()
0 ignored issues
show
Duplication introduced by
This method 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...
48
    {
49 38
        if ($this->file === null) {
50
            try {
51 38
                $this->file = $this->transport->getFile();
52 38
            } catch (\RuntimeException $e) {
53
                throw new TransportException(
54
                    sprintf('Could not open file "%s": %s', $this->transport->getDestination(), $e->getMessage()),
55
                    null,
56
                    $e
57
                );
58
            }
59 38
        }
60
61 38
        return $this->file;
62
    }
63
}
64