PHPLanguage::tokens()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 0
cts 17
cp 0
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Console\Language;
11
12
use Railt\Io\Readable;
13
14
/**
15
 * Class PHPLanguage
16
 */
17
class PHPLanguage extends Language
18
{
19
    /**
20
     * @return iterable
21
     */
22 View Code Duplication
    public function tokens(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        return [
25
            'T_COMMENT'       => '//[^\\n]*',
26
            'T_BLOCK_COMMENT' => '/\\*.*?\\*/',
27
            'T_MODIFIER'      => '(public|private|protected|abstract)\b',
28
            'T_DEFINITION'    => '(interface|class|namespace)\b',
29
            'T_KEYWORD'       => '(new|__halt_compiler|and|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|or|print|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor)\b',
30
            'T_TYPE'          => '(int|float|bool|iterable|array|string|resource|object|void)\b',
31
            'T_TAG'           => '(<\?php|\?>|<\?=|<\?)\b',
32
            'T_STRING'        => '("[^"\\\\]+(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]+(\\\\.[^\'\\\\]*)*\')',
33
            'T_SYMBOL'        => '(\?|=>|\->|__METHOD__|__LINE__|__DIR__|__FUNCTION__|__NAMESPACE__|__CLASS__)\b',
34
            'T_VARIABLE'      => '\$\w+',
35
            'T_DIGIT'         => '\d+',
36
            'T_NAME'          => '[a-zA-Z_\\x7f-\\xff\\\\][a-zA-Z0-9_\\x7f-\\xff\\\\]*',
37
        ];
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function colors(): array
44
    {
45
        return [
46
            'T_BLOCK_COMMENT' => 'fg=cyan',
47
            'T_MODIFIER'      => 'fg=blue',
48
            'T_SYMBOL'        => 'fg=blue',
49
            'T_TAG'           => 'fg=red',
50
            'T_TYPE'          => 'fg=yellow',
51
            'T_DEFINITION'    => 'fg=yellow',
52
        ];
53
    }
54
55
    /**
56
     * @param Readable $file
57
     * @return bool
58
     */
59
    public function match(Readable $file): bool
60
    {
61
        return $this->matchExtension($file, ['php', 'php5', 'php7']);
62
    }
63
}
64