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

TokensTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalizeTokens() 0 17 4
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
}