Completed
Push — master ( 82d1fc...6f9908 )
by Ivannis Suárez
02:50 queued 29s
created

SmartExpressionToStringConverter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A visitOperator() 0 8 2
A requireParentheses() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Visitor\Tests\Fixtures;
12
13
use Cubiche\Core\Visitor\Visitor;
14
15
/**
16
 * Smart Expression to String Converter Class.
17
 *
18
 * @author Karel Osorio Ramírez <[email protected]>
19
 */
20
class SmartExpressionToStringConverter extends ExpressionToStringConverter
21
{
22
    /**
23
     * @param Operator $op
24
     *
25
     * @return string
26
     */
27
    public function visitOperator(Operator $op, $parentOperator = null)
28
    {
29
        $currentOperator = $op->operator();
30
        $expression = $op->firstOperand()->accept($this, $currentOperator).
31
            $currentOperator.$op->secondOperand()->accept($this, $currentOperator);
32
33
        return $this->requireParentheses($currentOperator, $parentOperator) ? '('.$expression.')' : $expression;
34
    }
35
36
    /**
37
     * @param string $currentOperator
38
     * @param string $parentOperator
39
     *
40
     * @return bool
41
     */
42
    protected function requireParentheses($currentOperator, $parentOperator)
43
    {
44
        return $currentOperator === '+' && $parentOperator === '*';
45
    }
46
}
47