Completed
Branch release/1.3 (364b03)
by Johnny
02:53
created

Argument   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 50
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A usageInfo() 0 18 6
A usageLine() 0 5 1
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
}