Completed
Push — master ( 6db6da...5370d9 )
by Angel
03:42
created

Resource::parseRequest()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9137
c 0
b 0
f 0
cc 6
nc 6
nop 2
1
<?php
2
3
namespace roaresearch\yii2\roa\urlRules;
4
5
use Yii;
6
7
/**
8
 * Default Url Rule to handle resources with collections.
9
 *
10
 * Supports representative URL using ownership slug.
11
 *
12
 * @author Angel (Faryshta) Guevara <[email protected]>
13
 */
14
class Resource extends \yii\rest\UrlRule
15
{
16
    /**
17
     * @inheritdoc
18
     */
19
    public $pluralize = false;
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public $tokens = ['{id}' => '<id:\d+>'];
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function parseRequest($manager, $request)
30
    {
31
        $pathInfo = $request->getPathInfo();
0 ignored issues
show
Unused Code introduced by
$pathInfo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
32
        foreach ($this->rules as $urlName => $rules) {
33
            foreach ($rules as $rule) {
0 ignored issues
show
Bug introduced by
The expression $rules of type object<yii\web\UrlRuleInterface> is not traversable.
Loading history...
34
                /* @var $rule \yii\web\UrlRule */
35
                $result = $rule->parseRequest($manager, $request);
36
                if (YII_DEBUG) {
37
                    Yii::trace([
0 ignored issues
show
Deprecated Code introduced by
The method yii\BaseYii::trace() has been deprecated with message: since 2.0.14. Use [[debug()]] instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
                        'rule' => method_exists($rule, '__toString')
39
                            ? (string)$rule
40
                            : get_class($rule),
41
                        'match' => $result !== false,
42
                        'parent' => static::class,
43
                    ], __METHOD__);
44
                }
45
                if ($result !== false) {
46
                    return $result;
47
                }
48
            }
49
        }
50
51
        return false;
52
    }
53
}
54