Boundary::isBoundaryCharacter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %
Metric Value
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 12/23/14
5
 * Time: 1:34 PM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Sql\QueryFormatter\Tokenizer\Parser;
12
13
use NilPortugues\Sql\QueryFormatter\Tokenizer\Tokenizer;
14
15
/**
16
 * Class Boundary.
17
 */
18 View Code Duplication
final class Boundary
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    /**
21
     * @param Tokenizer $tokenizer
22
     * @param string    $string
23
     * @param array     $matches
24
     */
25
    public static function isBoundary(Tokenizer $tokenizer, $string, array &$matches)
26
    {
27
        if (!$tokenizer->getNextToken() &&
28
            self::isBoundaryCharacter($string, $matches, $tokenizer->getRegexBoundaries())
29
        ) {
30
            $tokenizer->setNextToken(self::getBoundaryCharacter($matches));
31
        }
32
    }
33
34
    /**
35
     * @param string $string
36
     * @param array  $matches
37
     * @param string $regexBoundaries
38
     *
39
     * @return bool
40
     */
41
    protected static function isBoundaryCharacter($string, array &$matches, $regexBoundaries)
42
    {
43
        return (1 == \preg_match('/^('.$regexBoundaries.')/', $string, $matches));
44
    }
45
46
    /**
47
     * @param array $matches
48
     *
49
     * @return array
50
     */
51
    protected static function getBoundaryCharacter(array &$matches)
52
    {
53
        return [
54
            Tokenizer::TOKEN_VALUE => $matches[1],
55
            Tokenizer::TOKEN_TYPE => Tokenizer::TOKEN_TYPE_BOUNDARY,
56
        ];
57
    }
58
}
59