Shell   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCmd() 0 8 3
A execute() 0 6 1
A getOutput() 0 4 1
A getError() 0 4 1
A setCommand() 0 5 1
A getCommand() 0 4 1
1
<?php
2
/**
3
 * Jaeger
4
 *
5
 * @copyright	Copyright (c) 2015-2016, mithra62
6
 * @link		http://jaeger-app.com
7
 * @version		1.0
8
 * @filesource 	./Shell.php
9
 */
10
namespace JaegerApp;
11
12
use mikehaertl\shellcommand\Command;
13
14
/**
15
 * Jaeger - Shell Object
16
 *
17
 * Wrapper for a simple command line interface
18
 *
19
 * @package Shell
20
 * @author Eric Lamb <[email protected]>
21
 */
22
class Shell
23
{
24
25
    /**
26
     * The Cmd object
27
     * 
28
     * @var \mikehaertl\shellcommand\Command
29
     */
30
    protected $cmd = null;
31
32
    /**
33
     * The command we want to execute
34
     * 
35
     * @var string
36
     */
37
    protected $command = null;
38
39
    /**
40
     * Returns the Cmd object
41
     * 
42
     * @param string $refresh            
43
     */
44
    protected function getCmd($refresh = false)
45
    {
46
        if (is_null($this->cmd) || $refresh) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $refresh of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
47
            $this->cmd = new Command();
48
        }
49
        
50
        return $this->cmd;
51
    }
52
53
    /**
54
     * Executes the command
55
     * 
56
     * @return boolean
57
     */
58
    public function execute()
59
    {
60
        return $this->getCmd(true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
            ->setCommand($this->getCommand())
62
            ->execute();
63
    }
64
65
    /**
66
     * The command output (stdout).
67
     * Empty if none
68
     * 
69
     * @return mixed
70
     */
71
    public function getOutput()
72
    {
73
        return $this->getCmd()->getOutput();
74
    }
75
76
    /**
77
     * The error message, either stderr or internal message.
78
     * Empty if none.
79
     * 
80
     * @return string
81
     */
82
    public function getError()
83
    {
84
        return $this->getCmd()->getError();
85
    }
86
87
    /**
88
     * Sets the command to execute
89
     * 
90
     * @param string $command            
91
     * @return \mithra62\Shell
92
     */
93
    public function setCommand($command)
94
    {
95
        $this->command = $command;
96
        return $this;
97
    }
98
99
    /**
100
     * Returns the command to execute
101
     * 
102
     * @return string
103
     */
104
    public function getCommand()
105
    {
106
        return $this->command;
107
    }
108
}
109