Tokenizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tokenize() 0 7 1
A removeTrailer() 0 7 3
1
<?php
2
namespace Desmond;
3
4
class Tokenizer
5
{
6 365
    public static function tokenize($code)
7
    {
8 365
        $pattern = "/[\s,]*(~@|[\[\]{}()'`~^@]|\"(?:\\\\.|[^\\\\\"])*\"|;.*|[^\s\[\]{}('\"`,;)]*)/";
9 365
        preg_match_all($pattern, $code, $matches);
10 365
        self::removeTrailer($matches[1]);
11 365
        return $matches[1];
12
    }
13
14 365
    private static function removeTrailer(&$matches)
15
    {
16 365
        array_pop($matches);
17 365
        if (count($matches) === 1 && empty($matches[0])) {
18 1
            $matches = [];
19
        }
20
    }
21
}