MultiplyToken::getAssociativity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 MultiplyToken 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
            ->multiply($a->getValue())
59
            ->getValue();
60
61
        return new NumberToken($b->getOffset(), $result);
62
    }
63
}
64