Completed
Push — dev ( 122982...5e45c8 )
by Zach
02:18
created

Parser::parseDescription()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Console\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
7
abstract class Parser
8
{
9
    /**
10
     * Command to build.
11
     *
12
     * @var Command
13
     */
14
    protected $command;
15
16
    /**
17
     * Construct.
18
     *
19
     * @param Command $command
20
     */
21
    public function __construct(Command $command)
22
    {
23
        $this->command = $command;
24
    }
25
26
    /**
27
     * Set array modeArray value if value contains *.
28
     *
29
     * @param  string $value
30
     * @param  string $constant
31
     *
32
     * @return string
33
     */
34
    protected function parseArray($value, $constant)
35
    {
36
        if (strpos($value, '*') !== false) {
37
            $this->modeArray[] = $constant;
0 ignored issues
show
Bug introduced by
The property modeArray does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
39
            $value = str_replace('*', '', $value);
40
        }
41
42
        return $value;
43
    }
44
45
    /**
46
     * Parse an argument/option description.
47
     *
48
     * @param string $value
49
     *
50
     * @return array [argument|option, description]
51
     */
52
    protected function parseDescription($value)
53
    {
54
        if (strpos($value, ':') !== false) {
55
            return array_map('trim', explode(':', $value));
56
        }
57
58
        return [$value, null];
59
    }
60
61
    /**
62
     * Calculate the mode score.
63
     *
64
     * @param  array  $modeArray
65
     * @param  string $class
66
     *
67
     * @return int
68
     */
69
    protected function calculateMode(array $modeArray, $class)
70
    {
71
        $mode = 0;
72
73
        foreach ($modeArray as $constant) {
74
            $mode = $mode | constant($class.'::'.$constant);
75
        }
76
77
        return $mode;
78
    }
79
}
80