Completed
Pull Request — master (#82)
by
unknown
18:01
created

OperatorTools::inlineMixedInstructions()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 8
nop 3
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
1
<?php
2
3
namespace RulerZ\Target\Operators;
4
5
class OperatorTools
6
{
7
    public static function inlineMixedInstructions(array $instructions, $operator = null, $useStringBreakingLogic = true)
8
    {
9
        $elements = [];
10
11
        foreach ($instructions as $instruction) {
12
            if ($instruction instanceof RuntimeOperator) {
13
                $elements[] = $instruction->format($useStringBreakingLogic);
14
            } else if ($instruction instanceof CompileTimeOperator) {
15
                $elements[] = sprintf('%s', $instruction->format(false));
16
            } else {
17
                $elements[] = sprintf('%s', $instruction);
18
            }
19
        }
20
21
        if (null === $operator) {
22
            return join('', $elements);
23
        } else {
24
            return join(' '.$operator.' ', $elements);
25
        }
26
    }
27
}
28