Completed
Branch develop (f7dc53)
by Anton
05:49
created

TokensTrait::normalizeTokens()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 9
nc 5
nop 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Tokenizer\Traits;
9
10
use Spiral\Tokenizer\TokenizerInterface;
11
12
/**
13
 * Normalizes tokens by forcing them into same format.
14
 */
15
trait TokensTrait
16
{
17
    /**
18
     * Normalize tokens by wrapping every token into array and forcing line value.
19
     *
20
     * @param array $tokens
21
     * @return array
22
     */
23
    private function normalizeTokens(array $tokens)
24
    {
25
        $line = 0;
26
        foreach ($tokens as &$token) {
27
            if (isset($token[TokenizerInterface::LINE])) {
28
                $line = $token[TokenizerInterface::LINE];
29
            }
30
31
            if (!is_array($token)) {
32
                $token = [$token, $token, $line];
33
            }
34
35
            unset($token);
36
        }
37
38
        return $tokens;
39
    }
40
}