Completed
Push — master ( 0c1f61...7ddb9b )
by Ilias
02:22
created

DefaultStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 37
ccs 16
cts 18
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A executeFor() 0 20 3
A shouldExecuteFor() 0 4 1
1
<?php
2
3
4
namespace CondParse\ParseStrategy;
5
6
7
use CondParse\TokenParserParameter;
8
9
class DefaultStrategy implements ParseStrategyInterface
10
{
11
12
    /**
13
     * @param TokenParserParameter $parserParameter
14
     * @return bool
15
     */
16
    public function shouldExecuteFor(TokenParserParameter $parserParameter)
17
    {
18
        return true;
19
    }
20
21
    /**
22
     * @param TokenParserParameter $parserParameter
23
     * @return void
24
     */
25 3
    public function executeFor(TokenParserParameter $parserParameter)
26
    {
27
        while (
28 3
            ! $parserParameter->getOperatorStack()->isEmpty()
29 3
            && $parserParameter->getTokenMap()
30 3
                ->compareOperatorPrecedence(
31 3
                    $parserParameter->getLexerToken(),
32 3
                    $parserParameter->getOperatorStack()->top()
33 3
                ) <= 0
34 3
        ) {
35 3
            $parserParameter->getOperandStack()->push(
36
                $parserParameter
37 3
                    ->getTokenMap()
38 3
                    ->buildOperand($parserParameter->getOperatorStack()->pop())
39 3
                    ->consumeTokens($parserParameter->getOperandStack())
40 3
            );
41 3
        }
42
43 3
        $parserParameter->getOperatorStack()->push($parserParameter->getLexerToken());
44 3
    }
45
}
46