CommandProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getByName() 0 9 4
A __construct() 0 4 1
1
<?php
2
3
namespace Tkotosz\CommandScheduler\Model;
4
5
use Magento\Framework\Console\CommandList\Proxy as CommandList;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Console\CommandList\Proxy was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Console\Command\Command;
7
use Tkotosz\CommandScheduler\Model\AllowedCommandsContainer;
8
9
class CommandProvider
10
{
11
    /**
12
     * @var CommandList
13
     */
14
    private $commandList;
15
    
16
    /**
17
     * @var AllowedCommandsContainer
18
     */
19
    private $allowedCommandsContainer;
20
    
21
    /**
22
     * @param CommandList              $commandList
23
     * @param AllowedCommandsContainer $allowedCommandsContainer
24
     */
25
    public function __construct(CommandList $commandList, AllowedCommandsContainer $allowedCommandsContainer)
26
    {
27
        $this->commandList = $commandList;
28
        $this->allowedCommandsContainer = $allowedCommandsContainer;
29
    }
30
    
31
    public function getByName(string $name): ?Command
32
    {
33
        foreach ($this->commandList->getCommands() as $command) {
34
            if ($command->getName() === $name && $this->allowedCommandsContainer->hasCommand($command->getName())) {
35
                return $command;
36
            }
37
        }
38
39
        return null;
40
    }
41
}
42