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

Factory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 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