Completed
Push — master ( 2a128c...18787f )
by Alexey
02:20
created

OperatorToken   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 93
Duplicated Lines 27.96 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 84.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 2
cbo 1
dl 26
loc 93
ccs 32
cts 38
cp 0.8421
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
C getPriority() 26 32 12
A isLeftAssoc() 0 4 1
A isRightAssoc() 0 4 1
A getAllowedOperators() 0 4 1
A sanitize() 0 4 1
A validate() 0 4 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
/**
4
 * OperatorToken.php
5
 *
6
 * @date 28.03.2015 2:48:12
7
 * @copyright Sklyarov Alexey <[email protected]>
8
 */
9
10
namespace Sufir\Calc\Token;
11
12
/**
13
 * OperatorToken
14
 *
15
 * Математический оператор
16
 *
17
 * @author Sklyarov Alexey <[email protected]>
18
 * @package Sufir\Calc\Token
19
 */
20
final class OperatorToken extends AbstractToken
21
{
22
    /**
23
     *
24
     * @var array
25
     */
26
    protected static $operators = array('*', '/', '+', '-', '^');
27
28
    /**
29
     *
30
     * @param type $assoc
31
     * @return integer
32
     */
33 7
    public function getPriority($assoc = 'left')
34
    {
35 7
        if ($assoc === 'right') {
36 5 View Code Duplication
            switch ($this->value) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
37 5
                case '^':
38 1
                    return 5;
39 4
                case '/':
40 1
                    return 4;
41 3
                case '*':
42 1
                    return 3;
43 2
                case '-':
44 1
                    return 2;
45 1
                case '+':
46 1
                    return 1;
47
                default:
48
                    return 0;
49
            }
50
        } else {
51 7 View Code Duplication
            switch ($this->value) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
52 7
                case '^':
53 3
                    return 3;
54 6
                case '*':
55 6
                case '/':
56 4
                    return 2;
57 4
                case '+':
58 4
                case '-':
59 4
                    return 1;
60
                default:
61
                    return 0;
62
            }
63
        }
64
    }
65
66
    /**
67
     *
68
     * @return boolean
69
     */
70 7
    public function isLeftAssoc()
71
    {
72 7
        return !$this->isRightAssoc();
73
    }
74
75
    /**
76
     *
77
     * @return boolean
78
     */
79 7
    public function isRightAssoc()
80
    {
81 7
        return ($this->value === '^');
82
    }
83
84
    /**
85
     *
86
     * @return array
87
     */
88 28
    public static function getAllowedOperators()
89
    {
90 28
        return self::$operators;
91
    }
92
93
    /**
94
     *
95
     * @param string $value
96
     * @return string
97
     */
98 21
    protected function sanitize($value)
99
    {
100 21
        return trim($value);
101
    }
102
103
    /**
104
     *
105
     * @param string $value
106
     * @return boolean
107
     */
108 28
    protected function validate($value)
109
    {
110 28
        return in_array($value, self::getAllowedOperators());
111
    }
112
}
113