Completed
Push — develop ( cba78f...09bcdb )
by Nicolas
12:47
created

DocBlock::getMethodOptions()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
rs 9.2
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
3
namespace devtransition\jobbers\helper;
4
5
use yii\base\Exception;
6
use yii\helpers\VarDumper;
7
8
class DocBlock
9
{
10
11
    private $_reflector;
12
13
    const ALLOWED_CLASS_OPTIONS = [
14
        'timeout',
15
        'prio',
16
    ];
17
18
    const ALLOWED_METHOD_OPTIONS = [
19
        'timeout',
20
        'prio',
21
    ];
22
23
    /**
24
     * @param $class
25
     */
26
    public function __construct(&$class)
27
    {
28
        $this->_class = $class;
0 ignored issues
show
Bug introduced by
The property _class 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...
29
        $this->_reflector = new \Nette\Reflection\ClassType($this->_class);
30
    }
31
32 View Code Duplication
    public function getClassOptions()
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...
33
    {
34
        $annotation = $this->_reflector->getAnnotation('jobbers');
35
36
        if (!$annotation) {
37
            return [];
38
        }
39
40
        foreach ($annotation as $option => $value) {
0 ignored issues
show
Bug introduced by
The expression $annotation of type object<Nette\Reflection\IAnnotation> is not traversable.
Loading history...
41
            if (!in_array($option, self::ALLOWED_METHOD_OPTIONS)) {
42
                throw new \Exception("option [$option] unknown");
43
            }
44
        }
45
46
        return (array)$annotation;
47
    }
48
49 View Code Duplication
    public function getMethodOptions($method)
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...
50
    {
51
        $annotation = $this->_reflector->getMethod($method)->getAnnotation('jobbers');
52
53
        if (!$annotation) {
54
            return [];
55
        }
56
57
        foreach ($annotation as $option => $value) {
58
            if (!in_array($option, self::ALLOWED_METHOD_OPTIONS)) {
59
                throw new \Exception("option [$option] unknown");
60
            }
61
        }
62
63
        return (array)$annotation;
64
    }
65
66
}