HasCommands   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
c 0
b 0
f 0
dl 0
loc 29
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCommands() 0 6 2
A initCommands() 0 5 2
A commands() 0 4 2
1
<?php
2
3
namespace Nip\Container\ServiceProviders\Providers\Traits;
4
5
/**
6
 * Trait HasCommands
7
 * @package Nip\Container\ServiceProvider\Traits
8
 */
9
trait HasCommands
10
{
11
    protected $commands = null;
12
13
    /**
14
     * @param array|mixed $commands
15
     */
16
    public function commands($commands)
17
    {
18
        $commands = is_array($commands) ? $commands : func_get_args();
19
        $this->commands = array_merge($commands);
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function getCommands(): array
26
    {
27
        if ($this->commands === null) {
28
            $this->initCommands();
29
        }
30
        return $this->commands;
31
    }
32
33
    protected function initCommands()
34
    {
35
        $this->commands = [];
36
        if (method_exists($this, 'registerCommands')) {
37
            $this->registerCommands();
38
        }
39
    }
40
}
41