LocalLocation::getName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace TemplesOfCode\CodeSanity\Location;
4
5
use TemplesOfCode\Sofa\CommandChain;
6
use TemplesOfCode\CodeSanity\Location;
7
use TemplesOfCode\CodeSanity\RosterItem;
8
9
/**
10
 * Class LocalLocation
11
 * @package TemplesOfCode\CodeSanity
12
 */
13
class LocalLocation extends Location
14
{
15
    /*
16
     * @param string $directory
17
     * @return bool
18
     */
19 5
    protected function isReadable($directory)
20
    {
21 5
        return is_readable($directory);
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 6
    public function isValid()
28
    {
29
        /**
30
         * @var bool $verdict
31
         */
32 6
        $verdict = !empty($this->directory) &&
33 5
            $this->isReadable($this->directory)
34 6
        ;
35
36 6
        return $verdict;
37
    }
38
39
    /**
40
     * @return CommandChain
41
     */
42 3
    protected function getRosterListCommand()
43
    {
44
        /**
45
         * todo: explore the OOP approach by iterating through the dir tree with RecursiveDirectoryIterator.
46
         */
47
48 3
        if (!$this->isValid()) {
49 1
            throw new \InvalidArgumentException(sprintf(
50 1
                "Local location validation failed for Location with directory '%s'",
51 1
                $this->directory
52 1
            ));
53
        }
54
55
        /**
56
         * @var CommandChain $pipeChainedCommands
57
         */
58 2
        $pipeChainedCommands = $this->buildPipeChainedCommands();
59
60
        /**
61
         * @var CommandChain $sequenceChainedCommands
62
         */
63 2
        $sequenceChainedCommands = $this->buildSequenceChainedCommands();
64 2
        $sequenceChainedCommands->addCommand($pipeChainedCommands);
65
66 2
        return $sequenceChainedCommands;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public function getName()
73
    {
74 1
        if (empty($this->name)) {
75 1
            $this->name = $this->getDirectory();
76 1
        }
77
78 1
        return $this->name;
79
    }
80
81
    /**
82
     * @param RosterItem $rosterItem
83
     * @return  string
84
     */
85 3
    public function getFullPath(RosterItem $rosterItem)
86
    {
87
        /**
88
         * @var string $targetFileName
89
         */
90 3
        $targetFileName = $rosterItem->getRelativeFileName();
91 3
        $fullPath = sprintf(
92 3
            '%s/%s',
93 3
            $this->getName(),
94
            $targetFileName
95 3
        );
96
97 3
        return $fullPath;
98
    }
99
100
}
101