ServiceCommandResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A commands() 0 14 4
1
<?php
2
3
namespace Gitory\PimpleCli;
4
5
use Pimple\Container;
6
7
class ServiceCommandResolver
8
{
9
    /**
10
     * Service command container
11
     * @var Container
12
     */
13
    private $container;
14
15
    /**
16
     * @var array of Command
17
     */
18
    private $commands;
19
20
    public function __construct(Container $container)
21
    {
22
        $this->container = $container;
23
    }
24
25
    public function commands()
26
    {
27
        if($this->commands === null) {
28
            $this->commands = [];
29
30
            foreach($this->container->keys() as $serviceName) {
31
                if(preg_match('/\.command$/', $serviceName)) {
32
                    $this->commands[] = $this->container[$serviceName];
33
                }
34
            }
35
        }
36
37
        return $this->commands;
38
    }
39
}
40