Completed
Push — 3.0 ( fea5eb...c29f0e )
by Vermeulen
02:17
created

Cli   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 76
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A getCli() 0 4 1
A init() 0 5 1
A toRun() 0 4 1
A run() 0 5 1
A runCliFile() 0 14 2
1
<?php
2
3
namespace BFW\Core\AppSystems;
4
5
class Cli extends AbstractSystem
6
{
7
    /**
8
     * @var \BFW\Core\Cli|null $cli
9
     */
10
    protected $cli;
11
    
12
    /**
13
     * {@inheritdoc}
14
     * 
15
     * @return \BFW\Core\Cli|null
16
     */
17
    public function __invoke()
18
    {
19
        return $this->cli;
20
    }
21
22
    /**
23
     * Getter accessor to cli property
24
     * 
25
     * @return \BFW\Core\Cli|null
26
     */
27
    public function getCli()
28
    {
29
        return $this->cli;
30
    }
31
    
32
    /**
33
     * {@inheritdoc}
34
     * Define the cli property
35
     */
36
    public function init()
37
    {
38
        $this->cli        = new \BFW\Core\Cli;
39
        $this->initStatus = true;
40
    }
41
    
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function toRun()
46
    {
47
        return true;
48
    }
49
    
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function run()
54
    {
55
        $this->runCliFile();
56
        $this->runStatus = true;
57
    }
58
    
59
    /**
60
     * Run the cli file if we're in cli mode
61
     * 
62
     * @return void
63
     * 
64
     * @throws Exception If no file is specified or if the file not exist.
65
     */
66
    protected function runCliFile()
67
    {
68
        if (PHP_SAPI !== 'cli') {
69
            return;
70
        }
71
72
        \BFW\Application::getInstance()
0 ignored issues
show
Documentation Bug introduced by
The method getSubjectList does not exist on object<BFW\Application>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
73
            ->getSubjectList()
74
            ->getSubjectByName('ApplicationTasks')
75
            ->sendNotify('run_cli_file');
76
        
77
        $fileToExec = $this->cli->obtainFileFromArg();
78
        $this->cli->run($fileToExec);
79
    }
80
}
81