HasCommands::commands()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
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