Completed
Pull Request — master (#82)
by
unknown
02:06
created

OperatorTools::inlineMixedInstructions()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 13
nc 8
nop 2
1
<?php
2
3
namespace RulerZ\Target\Operators;
4
5
class OperatorTools
6
{
7
    public static function inlineMixedInstructions(array $instructions, $operator = null)
8
    {
9
        $elements = [];
10
11
        foreach ($instructions as $instruction) {
12
            if ($instruction instanceof RuntimeOperator) {
13
                $elements[] = $instruction->format(true);
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