Completed
Push — master ( c8d577...734a22 )
by Gilles
13s
created

RewriteurlRuleParam::isMatching()   D

Complexity

Conditions 10
Paths 16

Size

Total Lines 36
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 36
rs 4.8196
cc 10
eloc 21
nc 16
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace RewriteUrl\Model;
4
5
use RewriteUrl\Model\Base\RewriteurlRuleParam as BaseRewriteurlRuleParam;
6
7
class RewriteurlRuleParam extends BaseRewriteurlRuleParam
8
{
9
    const PARAM_CONDITION_EQUALS = "equals";
10
    const PARAM_CONDITION_NOT_EQUALS = "not_equals";
11
    const PARAM_CONDITION_EXISTS = "exists";
12
    const PARAM_CONDITION_MISSING = "missing";
13
    const PARAM_CONDITION_EMPTY = "empty";
14
    const PARAM_CONDITION_NOT_EMPTY = "not_empty";
15
16
17
    public function isMatching($getParamArray)
18
    {
19
        if (array_key_exists($this->getParamName(), $getParamArray)) {
20
            $value = $getParamArray[$this->getParamName()];
21
            if (empty($value)) {
22
                if ($this->getParamCondition() === self::PARAM_CONDITION_EMPTY) {
23
                    return true;
24
                }
25
            } else {
26
                if ($this->getParamCondition() === self::PARAM_CONDITION_NOT_EMPTY) {
27
                    return true;
28
                }
29
            }
30
31
            if ($value == $this->getParamValue()) {
32
                if ($this->getParamCondition() === self::PARAM_CONDITION_EQUALS) {
33
                    return true;
34
                }
35
            } else {
36
                if ($this->getParamCondition() === self::PARAM_CONDITION_NOT_EQUALS) {
37
                    return true;
38
                }
39
            }
40
41
            if ($this->getParamCondition() === self::PARAM_CONDITION_EXISTS) {
42
                return true;
43
            }
44
45
        } else {
46
            if ($this->getParamCondition() === self::PARAM_CONDITION_MISSING) {
47
                return true;
48
            }
49
        }
50
51
        return false;
52
    }
53
}
54