Completed
Push — master ( 7a7da5...1e2def )
by Omar
02:35
created

LocalLocation::getRosterListCommand()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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