Test Failed
Push — master ( 3ca5bd...939415 )
by Kirill
02:50
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 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\Lexer;
11
12
use Parle\Lexer as Parle;
13
use Railt\Lexer\Driver\NativeRegex;
14
use Railt\Lexer\Driver\ParleLexer;
15
16
/**
17
 * The `Factory` class exists as a convenient way to
18
 * pick the best available lexer implementation.
19
 */
20
final class Factory
21
{
22
    /**
23
     * Creates a new lexer instance
24
     *
25
     * ```php
26
     * $lexer = Railt\Lexer\Factory::create();
27
     * ```
28
     *
29
     * This method always returns an instance implementing `LexerInterface` interface,
30
     * the actual lexer implementation is an implementation detail.
31
     *
32
     * This method should usually only be called once at the beginning of the program.
33
     *
34
     * @param array $tokens
35
     * @param array $skip
36
     * @return LexerInterface
37
     * @throws Exception\BadLexemeException
38
     */
39
    public static function create(array $tokens = [], array $skip = []): LexerInterface
40
    {
41
        if (\class_exists(Parle::class, false)) {
42
            return new ParleLexer($tokens, $skip);
43
        }
44
45
        return new NativeRegex($tokens, $skip);
46
        // @codeCoverageIgnoreEnd
47
    }
48
}
49