Passed
Push — master ( 3376db...1497f5 )
by Mike
12:25
created

DumperDependencyProvider::getCommandList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
4
namespace Nexus\Dumper;
5
6
7
use Nexus\Dumper\Communication\Command\DumpLocalCommand;
8
use Xervice\Core\Dependency\DependencyProviderInterface;
9
use Xervice\Core\Dependency\Provider\AbstractProvider;
10
11
/**
12
 * @method \Xervice\Core\Locator\Locator getLocator()
13
 */
14
class DumperDependencyProvider extends AbstractProvider
15
{
16
    const DOCKER_FACADE = 'docker.facade';
17
    const SHELL_FACADE = 'shell.facade';
18
    const COMMAND_LIST = 'command.list';
19
20
    /**
21
     * @param \Xervice\Core\Dependency\DependencyProviderInterface $container
22
     */
23
    public function handleDependencies(DependencyProviderInterface $container)
24
    {
25
        $this->addShellFacade($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Nexus\Dumper\DumperDepen...vider::addShellFacade() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
26
        $this->addDockerFacade($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Nexus\Dumper\DumperDepen...ider::addDockerFacade() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
27
28
        $container[self::COMMAND_LIST] = function(DependencyProviderInterface $container) {
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
            return $this->getCommandList();
30
        };
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    protected function getCommandList()
37
    {
38
        return [
39
            new DumpLocalCommand()
40
        ];
41
    }
42
43
    /**
44
     * @param \Xervice\Core\Dependency\DependencyProviderInterface $container
45
     */
46
    private function addShellFacade(DependencyProviderInterface $container): void
47
    {
48
        $container[self::SHELL_FACADE] = function(DependencyProviderInterface $container) {
49
            return $container->getLocator()->shell()->facade();
50
        };
51
    }
52
53
    /**
54
     * @param \Xervice\Core\Dependency\DependencyProviderInterface $container
55
     */
56
    private function addDockerFacade(DependencyProviderInterface $container): void
57
    {
58
        $container[self::DOCKER_FACADE] = function(DependencyProviderInterface $container) {
59
            return $container->getLocator()->dockerClient()->facade();
60
        };
61
    }
62
}