DivisionToken   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 41
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegexPattern() 4 4 1
A getPrecedence() 4 4 1
A getAssociativity() 4 4 1
A execute() 11 11 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
 * This file is part of the fubhy/math-php package.
5
 *
6
 * (c) Sebastian Siemssen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Fubhy\Math\Token\Operator;
13
14
use Fubhy\Math\Token\BaseToken;
15
use Fubhy\Math\Token\NumberToken;
16
use Moontoast\Math\BigNumber;
17
18
/**
19
 * Token class for the '/' operator.
20
 *
21
 * @author Sebastian Siemssen <[email protected]>
22
 */
23 View Code Duplication
class DivisionToken extends BaseToken implements OperatorTokenInterface
0 ignored issues
show
Duplication introduced by
This class 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...
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public static function getRegexPattern()
29
    {
30
        return '\/';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getPrecedence()
37
    {
38
        return 1;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getAssociativity()
45
    {
46
        return OperatorTokenInterface::ASSOCIATIVITY_LEFT;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function execute(&$stack)
53
    {
54
        $a = array_pop($stack);
55
        $b = array_pop($stack);
56
57
        $result = (new BigNumber($b->getValue()))
58
            ->divide($a->getValue())
59
            ->getValue();
60
61
        return new NumberToken($b->getOffset(), $result);
62
    }
63
}
64