StringTokenizer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 21
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 16 5
1
<?php
2
3
namespace MagentoHackathon;
4
5
use MagentoHackathon\Api\TokenizerInterface;
6
7
/**
8
 * Service Class for get all string tokens as array.
9
 */
10
class StringTokenizer implements TokenizerInterface
11
{
12
    /**
13
     * @inheritDoc
14
     */
15
    public function execute(string $filePath): array
16
    {
17
        if (!file_exists($filePath)) {
18
            return [];
19
        }
20
21
        $content = file_get_contents($filePath);
22
        $tokens = token_get_all($content);
23
24
        $stringTokens = [];
25
        foreach ($tokens as $token) {
26
            if (is_array($token) && $token[0] === T_STRING) {
27
                $stringTokens[] = $token[1];
28
            }
29
        }
30
        return $stringTokens;
31
    }
32
}
33