Completed
Push — master ( 375de1...c13e1e )
by Andrii
13:21
created

Controller   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 19.23 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 2
dl 10
loc 52
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 6 1
A setBefore() 0 4 1
A getBefore() 0 4 1
A setAfter() 0 4 1
A getAfter() 0 4 1
A readline() 0 4 1
A readpassword() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\base;
12
13
use hidev\controllers\CommonBehavior;
14
15
/**
16
 * Basic controller.
17
 */
18
abstract class Controller extends \yii\console\Controller
19
{
20
    use GettersTrait;
21
22
    public $layout = false;
23
24
    protected $_before = [];
25
    protected $_after  = [];
26
27
    public function behaviors()
28
    {
29
        return [
30
            CommonBehavior::class,
31
        ];
32
    }
33
34
    public function setBefore($requests)
35
    {
36
        $this->_before = array_merge($this->getBefore(), $this->normalizeTasks($requests));
0 ignored issues
show
Documentation Bug introduced by
The method normalizeTasks does not exist on object<hidev\base\Controller>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
37
    }
38
39
    public function getBefore()
40
    {
41
        return $this->_before;
42
    }
43
44
    public function setAfter($requests)
45
    {
46
        $this->_after = array_merge($this->getAfter(), $this->normalizeTasks($requests));
0 ignored issues
show
Documentation Bug introduced by
The method normalizeTasks does not exist on object<hidev\base\Controller>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47
    }
48
49
    public function getAfter()
50
    {
51
        return $this->_after;
52
    }
53
54
    public function readline($prompt)
55
    {
56
        return readline($prompt);
57
    }
58
59 View Code Duplication
    public function readpassword($prompt)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        echo $prompt;
62
        system('stty -echo');
63
        $password = rtrim(fgets(STDIN), PHP_EOL);
64
        system('stty echo');
65
        echo "\n";
66
67
        return $password;
68
    }
69
}
70