Completed
Push — master ( b89699...d123dc )
by Johnny
01:05
created

Argument::usageInfo()   A

Complexity

Conditions 6
Paths 16

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.0444
c 0
b 0
f 0
cc 6
nc 16
nop 0
crap 6
1
<?php
2
namespace Redbox\Cli\Arguments;
3
use Redbox\Cli\Object\ArgumentObject;
4
5
/**
6
 * The Argument class represents one single argument
7
 * set to the Manager. To make sure its universal we use
8
 * the ArgumentObject as an abstract to this class.
9
 *
10
 * @package Redbox\Cli\Arguments
11
 */
12
class Argument extends ArgumentObject
13
{
14
    const LINE_FMT = "\t%s\n\t\t%s\n";
15
16
    public $prefix;
17
    public $defaultValue;
18
    public $longPrefix;
19
    public $description;
20
    public $required;
21
    public $noValue;
22
    public $name;
23
24
    /**
25
     * Returns the usage information for this argument something like
26
     * -u user, --user user, (default: me_myself_i)
27
     *
28
     * @return string
29
     */
30 12
    public function usageInfo()
31
    {
32 12
        $arg = array();
33 12
        if ($this->prefix) {
34 8
            $arg[] = '-'.$this->prefix.' '.$this->name;
35
        }
36 12
        if ($this->longPrefix) {
37 8
            $arg[] = '--'.$this->longPrefix.' '.$this->name;
38
        }
39 12
        if ($this->defaultValue) {
40 4
            $arg[] = '(default: '.$this->defaultValue.')';
41
        }
42 12
        if (!$this->prefix && !$this->longPrefix) {
43 2
            $arg[] = $this->name;
44
        }
45 12
        $arg = implode(', ', $arg);
46 12
        return $arg;
47
    }
48
49
    /**
50
     * Returns a usage line something like.
51
     * -u user, --user user, (default: me_myself_i)
52
     *   Username
53
     *
54
     * @return string
55
     */
56 7
    public function usageLine()
57
    {
58 7
        $arg = $this->usageInfo();
59 7
        return sprintf(self::LINE_FMT, $arg, $this->description);
60
    }
61
}