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

DockerClientDependencyProvider::getCommandList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
4
namespace Nexus\DockerClient;
5
6
7
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeRmCommand;
8
use Nexus\DockerClient\Communication\Command\Compose\DockerComposeUpCommand;
9
use Nexus\DockerClient\Communication\Command\Container\StartContainerCommand;
10
use Nexus\DockerClient\Communication\Command\Container\StopContainerCommand;
11
use Nexus\DockerClient\Communication\Command\Exec\DockerExecCommand;
12
use Nexus\DockerClient\Communication\Command\Volume\VolumeCreateCommand;
13
use Nexus\DockerClient\Communication\Command\Volume\VolumeRemoveCommand;
14
use Xervice\Core\Dependency\DependencyProviderInterface;
15
use Xervice\Core\Dependency\Provider\AbstractProvider;
16
17
/**
18
 * @method \Xervice\Core\Locator\Locator getLocator()
19
 */
20
class DockerClientDependencyProvider extends AbstractProvider
21
{
22
    const SHELL_FACADE = 'shell.facade';
23
24
    const COMMAND_LIST = 'command.list';
25
26
    /**
27
     * @param \Xervice\Core\Dependency\DependencyProviderInterface $container
28
     */
29
    public function handleDependencies(DependencyProviderInterface $container)
30
    {
31
        $this->addShellFacade($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Nexus\DockerClient\Docke...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...
32
33
        $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...
34
            return $this->getCommandList();
35
        };
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    protected function getCommandList()
42
    {
43
        return [
44
            new DockerComposeUpCommand(),
45
            new DockerComposeRmCommand(),
46
            new VolumeCreateCommand(),
47
            new VolumeRemoveCommand(),
48
            new DockerExecCommand(),
49
            new StartContainerCommand(),
50
            new StopContainerCommand()
51
        ];
52
    }
53
54
    /**
55
     * @param \Xervice\Core\Dependency\DependencyProviderInterface $container
56
     */
57
    private function addShellFacade(DependencyProviderInterface $container): void
58
    {
59
        $container[self::SHELL_FACADE] = function(DependencyProviderInterface $container) {
60
            return $container->getLocator()->shell()->facade();
61
        };
62
    }
63
}