Numeral::isNumeral()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %
Metric Value
dl 6
loc 6
rs 9.4286
cc 3
eloc 3
nc 2
nop 3
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 12/23/14
5
 * Time: 1:32 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 Numeral.
17
 */
18 View Code Duplication
final class Numeral
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
     * @return array
26
     */
27
    public static function isNumeral(Tokenizer $tokenizer, $string, array &$matches)
28
    {
29
        if (!$tokenizer->getNextToken() && self::isNumeralString($string, $matches, $tokenizer->getRegexBoundaries())) {
30
            $tokenizer->setNextToken(self::getNumeralString($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 isNumeralString($string, array &$matches, $regexBoundaries)
42
    {
43
        return (1 == \preg_match(
44
                '/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.$regexBoundaries.')/',
45
                $string,
46
                $matches
47
            ));
48
    }
49
50
    /**
51
     * @param array $matches
52
     *
53
     * @return array
54
     */
55
    protected static function getNumeralString(array &$matches)
56
    {
57
        return [Tokenizer::TOKEN_VALUE => $matches[1], Tokenizer::TOKEN_TYPE => Tokenizer::TOKEN_TYPE_NUMBER];
58
    }
59
}
60