Pattern
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 0
lcom 0
cbo 0
dl 0
loc 33
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
/**
3
 * Set of regular expressions utilized to match/replace/validate parts of a given input.
4
 *
5
 * PHP version 7+
6
 *
7
 * @category   IntervalParser
8
 * @author     Ekin H. Bayar <[email protected]>
9
 * @version    0.2.0
10
 */
11
namespace IntervalParser;
12
13
class Pattern
14
{
15
    /**
16
     * Don't forget to close parentheses when using $define
17
     */
18
    const DEFINE = "/(?(DEFINE)";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /(?(DEFINE) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
19
20
    # Definitions of sub patterns for a valid interval
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
21
    const INTEGER = <<<'REGEX'
22
    (?<integer>
23
       (?:\G|(?!\n))
24
       (\s*\b)?
25
       \d{1,5}
26
       \s*
27
    )
28
REGEX;
29
30
    # Starts with integer followed by time specified
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
31
    const TIME_PART = <<<'REGEX'
32
    (?<timepart>
33
       (?&integer)
34
       ( s(ec(ond)?s?)?
35
       | m(on(ths?)?|in(ute)?s?)?
36
       | h(rs?|ours?)?
37
       | d(ays?)?
38
       | w(eeks?)?
39
       )
40
      )
41
REGEX;
42
43
    # Regex to match a valid interval, holds the value in $matches['interval']
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
44
    const INTERVAL_ONLY = "^(?<interval>(?&timepart)++)$/uix";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ^(?<interval>(?&timepart)++)$/uix does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
45
}
46