Completed
Push — prototype ( 3bfdd7...aec713 )
by Peter
07:47
created

ConsoleRoute   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setPath() 0 5 2
A setTitle() 0 5 1
A setDescription() 0 8 2
A setArgumentsDescription() 0 5 1
A setOptionsDescription() 0 5 1
A toArray() 0 4 1
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoConfigLib\Feature\Route;
12
13
use WebinoConfigLib\Feature\Route as BaseRoute;
14
15
/**
16
 * Class Console
17
 */
18
class ConsoleRoute extends BaseRoute
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function __construct($name = null)
24
    {
25
        parent::__construct($name);
26
        $this->setType($this::SIMPLE);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function setPath($path)
33
    {
34
        parent::setPath(is_array($path) ? join(' ', $path) : $path);
35
        return $this;
36
    }
37
38
    /**
39
     * Set route title
40
     *
41
     * @param string $title
42
     * @return $this
43
     */
44
    public function setTitle($title)
45
    {
46
        $this->setDefaults(['title' => (string) $title]);
47
        return $this;
48
    }
49
50
    /**
51
     * Set route description
52
     *
53
     * @param string|array $description
54
     * @return $this
55
     */
56
    public function setDescription($description)
57
    {
58
        is_array($description)
59
            and $description = join(PHP_EOL, $description) ;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
60
61
        $this->setDefaults(['description' => $description]);
62
        return $this;
63
    }
64
65
    /**
66
     * @param array $description
67
     * @return $this
68
     */
69
    public function setArgumentsDescription($description)
70
    {
71
        $this->setDefaults(['argumentsDescription' => $description]);
72
        return $this;
73
    }
74
75
    /**
76
     * @param array $description
77
     * @return $this
78
     */
79
    public function setOptionsDescription($description)
80
    {
81
        $this->setDefaults(['optionsDescription' => $description]);
82
        return $this;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function toArray()
89
    {
90
        return ['console' => parent::toArray()];
91
    }
92
}
93