Completed
Push — develop ( 6f71dd...40edc3 )
by Tom
11s
created

FoldersCheck::check()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 17

Duplication

Lines 4
Ratio 16 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 25
rs 8.5806
cc 4
eloc 17
nc 4
nop 1
1
<?php
2
3
namespace N98\Magento\Command\System\Check\Filesystem;
4
5
use N98\Magento\Command\CommandAware;
6
use N98\Magento\Command\CommandConfigAware;
7
use N98\Magento\Command\System\Check\Result;
8
use N98\Magento\Command\System\Check\ResultCollection;
9
use N98\Magento\Command\System\Check\SimpleCheck;
10
use N98\Magento\Command\System\CheckCommand;
11
use Symfony\Component\Console\Command\Command;
12
13
class FoldersCheck implements SimpleCheck, CommandAware, CommandConfigAware
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $_commandConfig;
19
20
    /**
21
     * @var CheckCommand
22
     */
23
    protected $_checkCommand;
24
25
    /**
26
     * @param ResultCollection $results
27
     */
28
    public function check(ResultCollection $results)
29
    {
30
        $folders = $this->_commandConfig['filesystem']['folders'];
31
        $magentoRoot = $this->_checkCommand->getApplication()->getMagentoRootFolder();
32
33
        foreach ($folders as $folder => $comment) {
34
            $result = $results->createResult();
35
            if (file_exists($magentoRoot . DIRECTORY_SEPARATOR . $folder)) {
36
                $result->setStatus(Result::STATUS_OK);
37
                $result->setMessage("<info>Folder <comment>" . $folder . "</comment> found.</info>");
38
                if (!is_writeable($magentoRoot . DIRECTORY_SEPARATOR . $folder)) {
39
                    $result->setStatus(Result::STATUS_ERROR);
40
                    $result->setMessage(
41
                        "<error>Folder " . $folder . " is not writeable!</error><comment> Usage: " . $comment .
42
                        "</comment>"
43
                    );
44
                }
45 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
46
                $result->setStatus(Result::STATUS_ERROR);
47
                $result->setMessage(
48
                    "<error>Folder " . $folder . " not found!</error><comment> Usage: " . $comment . "</comment>"
49
                );
50
            }
51
        }
52
    }
53
54
    /**
55
     * @param array $commandConfig
56
     */
57
    public function setCommandConfig(array $commandConfig)
58
    {
59
        $this->_commandConfig = $commandConfig;
60
    }
61
62
    /**
63
     * @param Command $command
64
     */
65
    public function setCommand(Command $command)
66
    {
67
        $this->_checkCommand = $command;
0 ignored issues
show
Documentation Bug introduced by
$command is of type object<Symfony\Component\Console\Command\Command>, but the property $_checkCommand was declared to be of type object<N98\Magento\Command\System\CheckCommand>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
68
    }
69
}
70