This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types = 1); |
||
2 | /** |
||
3 | * Finds intervals inside strings |
||
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 IntervalFinder |
||
14 | { |
||
15 | # Leading separator |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
16 | const LEADING_SEPARATOR = "(?<leadingSeparator>\s?(?:in)\s?)"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
(?<leadingSeparator>\s?(?:in)\s?) 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 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 ( 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: 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. ![]() |
|||
17 | |||
18 | # Regex to match a valid interval and any trailing string, holds the interval in $matches['interval'], the rest in $matches['trailing'] |
||
0 ignored issues
–
show
|
|||
19 | const INTERVAL_WITH_TRAILING_DATA = "^(?<interval>(?&timepart)++)(?<trailing>.+)*?$/uix"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
^(?<interval>(?&timepart...)(?<trailing>.+)*?$/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 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 ( 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: 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. ![]() |
|||
20 | |||
21 | # Regex to handle an input that may have multiple intervals along with leading and/or trailing data |
||
0 ignored issues
–
show
|
|||
22 | const MULTIPLE_INTERVALS = <<<'REGEX' |
||
23 | ^(?<leading>.*?)? |
||
24 | (?<sep>(?&leadingSeparator))? |
||
25 | (?<interval>(?&timepart)++) |
||
26 | (?<trailing>.*) |
||
27 | /uix |
||
28 | REGEX; |
||
29 | |||
30 | /** |
||
31 | * @var ParserSettings |
||
32 | */ |
||
33 | private $settings; |
||
34 | |||
35 | /** |
||
36 | * @var Normalizer |
||
37 | */ |
||
38 | private $normalizer; |
||
39 | |||
40 | /** |
||
41 | * IntervalFinder constructor. |
||
42 | * |
||
43 | * Default settings are : |
||
44 | * |
||
45 | * string $symbolSeparator = ',', |
||
46 | * string $wordSeparator = null |
||
47 | * |
||
48 | * @param \IntervalParser\ParserSettings $settings |
||
49 | * @param \IntervalParser\Normalizer $normalizer |
||
50 | */ |
||
51 | 4 | public function __construct(ParserSettings $settings, Normalizer $normalizer) |
|
52 | { |
||
53 | 4 | $this->settings = $settings; |
|
54 | 4 | $this->normalizer = $normalizer; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * Looks for a valid interval along with leading and/or trailing data IF the respective flags are set. |
||
59 | * TimeInterval is essentially DateInterval with extra information such as interval offset & length, leading/trailing data. |
||
0 ignored issues
–
show
|
|||
60 | * |
||
61 | * @param string $input |
||
62 | * @param int $flags |
||
63 | * @return TimeInterval|array |
||
64 | * @throws InvalidFlagException |
||
65 | * @throws FormatException |
||
66 | */ |
||
67 | 4 | public function find(string $input, int $flags = IntervalFlags::INTERVAL_ONLY) |
|
68 | { |
||
69 | if ($flags |
||
70 | 4 | & ~IntervalFlags::INTERVAL_ONLY |
|
71 | 4 | & ~IntervalFlags::REQUIRE_TRAILING |
|
72 | 4 | & ~IntervalFlags::REQUIRE_LEADING |
|
73 | 4 | & ~IntervalFlags::MULTIPLE_INTERVALS |
|
74 | ) { throw new InvalidFlagException("You have tried to use an invalid flag combination."); } |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
You have tried to use an invalid flag combination. 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 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 ( 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: 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. ![]() |
|||
75 | |||
76 | 4 | if ($flags & IntervalFlags::INTERVAL_ONLY) { |
|
77 | |||
78 | $input = $this->normalizer->normalize($input); |
||
79 | |||
80 | $definition = Pattern::DEFINE . Pattern::INTEGER . Pattern::TIME_PART . ')'; |
||
81 | $expression = $definition . Pattern::INTERVAL_ONLY; |
||
82 | |||
83 | if (preg_match($expression, $input)) { |
||
84 | $intervalOffset = 0; |
||
85 | $intervalLength = strlen($input); |
||
86 | |||
87 | # create and return the interval object |
||
0 ignored issues
–
show
|
|||
88 | $interval = \DateInterval::createFromDateString($input); |
||
89 | return new TimeInterval($interval, $intervalOffset, $intervalLength); |
||
90 | } |
||
91 | |||
92 | throw new FormatException("Given input is not a valid interval."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Given input is not a valid interval. 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 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 ( 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: 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. ![]() |
|||
93 | } |
||
94 | |||
95 | 4 | if ($flags == (IntervalFlags::REQUIRE_LEADING | IntervalFlags::REQUIRE_TRAILING)) { |
|
96 | |||
97 | 1 | $expression = $this->settings->getLeadingSeparatorExpression(); |
|
98 | |||
99 | 1 | $leadingSeparation = preg_match($expression, $input, $matches, PREG_OFFSET_CAPTURE); |
|
100 | 1 | if (!$leadingSeparation) { |
|
101 | throw new FormatException("Allowing leading data requires using a separator. Ie. foo in <interval>"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Allowing leading data re.... Ie. foo in <interval> 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 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 ( 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: 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. ![]() |
|||
102 | } |
||
103 | |||
104 | 1 | $leadingData = $matches[1][0] ?? null; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
105 | 1 | $intervalAndTrailingData = $matches[2][0] ?? null; |
|
106 | |||
107 | # throw early for missing parts |
||
0 ignored issues
–
show
|
|||
108 | 1 | if (!$leadingData) { |
|
0 ignored issues
–
show
The expression
$leadingData of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
109 | throw new FormatException("Given input does not contain a valid leading data."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Given input does not contain a valid leading data. 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 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 ( 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: 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. ![]() |
|||
110 | } |
||
111 | 1 | if (!$intervalAndTrailingData) { |
|
0 ignored issues
–
show
The expression
$intervalAndTrailingData of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
112 | throw new FormatException("Given input does not contain a valid interval and/or trailing data."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Given input does not con...l and/or trailing data. 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 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 ( 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: 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. ![]() |
|||
113 | } |
||
114 | |||
115 | 1 | $intervalOffset = $matches[2][1] ?? null; |
|
116 | |||
117 | # If interval contains non-strtotime-compatible abbreviations, replace 'em |
||
0 ignored issues
–
show
|
|||
118 | 1 | $intervalAndTrailingData = $this->normalizer->normalize($intervalAndTrailingData); |
|
119 | |||
120 | 1 | $definition = Pattern::DEFINE . Pattern::INTEGER . Pattern::TIME_PART . ')'; |
|
121 | 1 | $expression = $definition . self::INTERVAL_WITH_TRAILING_DATA; |
|
122 | |||
123 | 1 | if (preg_match($expression, $intervalAndTrailingData, $parts)) { |
|
124 | |||
125 | 1 | $interval = $parts['interval']; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
126 | 1 | $trailingData = $parts['trailing']; |
|
127 | 1 | $intervalLength = strlen($interval); |
|
128 | |||
129 | # create and return the interval object |
||
0 ignored issues
–
show
|
|||
130 | 1 | $interval = \DateInterval::createFromDateString($interval); |
|
131 | 1 | return new TimeInterval($interval, $intervalOffset, $intervalLength, $leadingData, $trailingData); |
|
132 | } |
||
133 | |||
134 | throw new FormatException("Given input does not contain a valid interval and/or trailing data."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Given input does not con...l and/or trailing data. 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 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 ( 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: 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. ![]() |
|||
135 | } |
||
136 | |||
137 | 3 | if ($flags & IntervalFlags::REQUIRE_LEADING) { |
|
138 | |||
139 | 1 | $expression = $this->settings->getLeadingSeparatorExpression(); |
|
140 | |||
141 | 1 | $leadingSeparation = preg_match($expression, $input, $matches, PREG_OFFSET_CAPTURE); |
|
142 | 1 | if (!$leadingSeparation) { |
|
143 | throw new FormatException("Allowing leading data requires using a separator. Ie. foo in <interval>"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Allowing leading data re.... Ie. foo in <interval> 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 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 ( 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: 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. ![]() |
|||
144 | } |
||
145 | |||
146 | 1 | $leadingData = $matches[1][0] ?? null; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 21 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
147 | 1 | $intervalAndPossibleTrailingData = $matches[2][0] ?? null; |
|
148 | |||
149 | 1 | if (!$leadingData) { |
|
0 ignored issues
–
show
The expression
$leadingData of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
150 | throw new FormatException("Could not find any valid leading data."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Could not find any valid leading data. 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 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 ( 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: 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. ![]() |
|||
151 | } |
||
152 | |||
153 | 1 | if (!$intervalAndPossibleTrailingData) { |
|
0 ignored issues
–
show
The expression
$intervalAndPossibleTrailingData of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
154 | throw new FormatException("Could not find any valid interval and/or leading data."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Could not find any valid...al and/or leading data. 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 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 ( 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: 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. ![]() |
|||
155 | } |
||
156 | |||
157 | 1 | $intervalOffset = $matches[2][1] ?? null; |
|
158 | |||
159 | # If interval contains non-strtotime-compatible abbreviations, replace 'em |
||
0 ignored issues
–
show
|
|||
160 | 1 | $safeInterval = $this->normalizer->normalize($intervalAndPossibleTrailingData); |
|
161 | |||
162 | # since above normalization is expected to not return any trailing data, only check for a valid interval |
||
0 ignored issues
–
show
|
|||
163 | 1 | $definition = Pattern::DEFINE . Pattern::INTEGER . Pattern::TIME_PART . ')'; |
|
164 | 1 | $expression = $definition . Pattern::INTERVAL_ONLY; |
|
165 | |||
166 | 1 | if (preg_match($expression, $safeInterval, $parts)) { |
|
167 | 1 | $interval = $parts['interval']; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
168 | 1 | $intervalLength = strlen($interval); |
|
169 | |||
170 | # create the interval object |
||
0 ignored issues
–
show
|
|||
171 | 1 | $interval = \DateInterval::createFromDateString($interval); |
|
172 | 1 | return new TimeInterval($interval, $intervalOffset, $intervalLength, $leadingData); |
|
173 | } |
||
174 | |||
175 | throw new FormatException("Given input does not contain a valid interval. Keep in mind trailing data is not allowed with current flag."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Given input does not con...owed with current flag. 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 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 ( 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: 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. ![]() |
|||
176 | } |
||
177 | |||
178 | 2 | if ($flags & IntervalFlags::REQUIRE_TRAILING) { |
|
179 | |||
180 | 2 | $definition = Pattern::DEFINE . Pattern::INTEGER . Pattern::TIME_PART . ')'; |
|
181 | 2 | $expression = $definition . self::INTERVAL_WITH_TRAILING_DATA; |
|
182 | |||
183 | # If interval contains non-strtotime-compatible abbreviations, replace 'em |
||
0 ignored issues
–
show
|
|||
184 | 2 | $safeInterval = $this->normalizer->normalize($input); |
|
185 | |||
186 | # Separate interval from trailing data |
||
0 ignored issues
–
show
|
|||
187 | 2 | if (preg_match($expression, $safeInterval, $parts)) { |
|
188 | 2 | $trailingData = $parts['trailing'] ?? null; |
|
189 | 2 | $interval = $parts['interval'] ?? null; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
190 | |||
191 | 2 | if (!$interval) { |
|
0 ignored issues
–
show
The expression
$interval of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
192 | throw new FormatException("Could not find any valid interval."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Could not find any valid interval. 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 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 ( 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: 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. ![]() |
|||
193 | } |
||
194 | |||
195 | 2 | if (!$trailingData) { |
|
0 ignored issues
–
show
The expression
$trailingData of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
196 | throw new FormatException("Could not find any valid trailing data."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Could not find any valid trailing data. 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 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 ( 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: 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. ![]() |
|||
197 | } |
||
198 | |||
199 | 2 | $intervalLength = strlen($interval); |
|
200 | 2 | $intervalOffset = 0; # since we don't allow leading data here |
|
0 ignored issues
–
show
|
|||
201 | |||
202 | # create the interval object |
||
0 ignored issues
–
show
|
|||
203 | 2 | $interval = \DateInterval::createFromDateString($interval); |
|
204 | 2 | return new TimeInterval($interval, $intervalOffset, $intervalLength, null, $trailingData); |
|
205 | } |
||
206 | |||
207 | throw new FormatException("Given input does not contain a valid interval. Keep in mind leading data is not allowed with current flag."); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Given input does not con...owed with current flag. 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 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 ( 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: 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. ![]() |
|||
208 | } |
||
209 | |||
210 | if ($flags & IntervalFlags::MULTIPLE_INTERVALS) { |
||
211 | |||
212 | $payload = []; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
213 | $separator = ($this->settings->getSeparationType() == 'symbol') |
||
214 | ? $this->settings->getSymbolSeparator() |
||
215 | : $this->settings->getWordSeparator(); |
||
216 | |||
217 | $expression = "/(?J)\b(?:(?<match>.*?)\s?{$separator})\s?|\b(?<match>.*)/ui"; |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $separator instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
218 | |||
219 | if (preg_match_all($expression, $input, $intervals, PREG_SET_ORDER)) { |
||
220 | |||
221 | $intervalSet = array_filter(array_map(function($set) { |
||
222 | foreach ($iter = new IntervalIterator($set) as $key => $interval) { |
||
223 | if ($iter->key() === 'match') { |
||
224 | return $interval; |
||
225 | } |
||
226 | } |
||
227 | }, $intervals)); |
||
228 | |||
229 | foreach ($intervalSet as $key => $interval) { |
||
230 | |||
231 | $definition = Pattern::DEFINE . self::LEADING_SEPARATOR . Pattern::INTEGER . Pattern::TIME_PART . ')'; |
||
0 ignored issues
–
show
|
|||
232 | $expression = $definition . self::MULTIPLE_INTERVALS; |
||
233 | |||
234 | preg_match($expression, $interval, $matches); |
||
235 | $matches = array_filter($matches); |
||
236 | |||
237 | $leadingData = $matches['leading'] ?? null; |
||
238 | $leadingSep = $matches['sep'] ?? null; |
||
239 | $interval = $matches['interval'] ?? null; |
||
240 | $trailing = $matches['trailing'] ?? null; |
||
241 | |||
242 | if (!$leadingData) $leadingData = $leadingSep ?? ""; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
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 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 ( 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: 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. ![]() |
|||
243 | |||
244 | $intervalOffset = (!$leadingSep) ? 0 : strlen($leadingData) + strlen($leadingSep); |
||
245 | |||
246 | # If interval contains non-strtotime-compatible abbreviations, replace them |
||
0 ignored issues
–
show
|
|||
247 | $safeInterval = $this->normalizer->normalize($interval . $trailing); |
||
248 | |||
249 | # Separate intervals from trailing data |
||
0 ignored issues
–
show
|
|||
250 | if (preg_match($expression, $safeInterval, $parts)) { |
||
251 | $trailingData = $parts['trailing'] ?? null; |
||
252 | $interval = $parts['interval'] ?? null; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
253 | if (!$interval) continue; |
||
0 ignored issues
–
show
The expression
$interval of type string|null is loosely compared to false ; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
254 | |||
255 | $intervalLength = strlen($interval); |
||
256 | # create the interval object |
||
0 ignored issues
–
show
|
|||
257 | $interval = \DateInterval::createFromDateString($interval); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
258 | $payload[] = new TimeInterval($interval, $intervalOffset, $intervalLength, $leadingData, $trailingData); |
||
0 ignored issues
–
show
|
|||
259 | } |
||
260 | } |
||
261 | |||
262 | if ($payload) return $payload; |
||
0 ignored issues
–
show
The expression
$payload of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
263 | } |
||
264 | } |
||
265 | } |
||
266 | } |
||
267 |