1 | <?php |
||
21 | class RegexHelper { |
||
22 | |||
23 | /** |
||
24 | * @var string regex to match variables |
||
25 | */ |
||
26 | private static $variable = '[?$](\w+)'; |
||
27 | |||
28 | /** |
||
29 | * @var string regex to match IRIs |
||
30 | */ |
||
31 | private static $iri = '[^\s<>"{}|\\\\^`]+'; |
||
32 | |||
33 | /** |
||
34 | * @var string regex to match prefixes |
||
35 | */ |
||
36 | private static $prefix = '\w+'; |
||
37 | |||
38 | /** |
||
39 | * @var string regex to match names after prefixes |
||
40 | */ |
||
41 | private static $name = '\w+'; |
||
42 | |||
43 | /** |
||
44 | * @var string regex to match strings and numbers |
||
45 | */ |
||
46 | private static $native = '([0-9]+|".*")'; |
||
47 | |||
48 | /** |
||
49 | * @var string[] list of natively supported functions |
||
50 | */ |
||
51 | private static $functions = array( |
||
52 | 'COUNT', 'SUM', 'MIN', 'MAX', 'AVG', 'SAMPLE', 'GROUP_CONCAT', 'STR', |
||
53 | 'LANG', 'LANGMATCHES', 'DATATYPE', 'BOUND', 'IRI', 'URI', 'BNODE', |
||
54 | 'RAND', 'ABS', 'CEIL', 'FLOOR', 'ROUND', 'CONCAT', 'STRLEN', 'UCASE', |
||
55 | 'LCASE', 'ENCODE_FOR_URI', 'CONTAINS', 'STRSTARTS', 'STRENDS', |
||
56 | 'STRBEFORE', 'STRAFTER', 'YEAR', 'MONTH', 'DAY', 'HOURS', 'MINUTES', |
||
57 | 'SECONDS', 'TIMEZONE', 'TZ', 'NOW', 'UUID', 'STRUUID', 'MD5', 'SHA1', |
||
58 | 'SHA256', 'SHA384', 'SHA512', 'COALESCE', 'IF', 'STRLANG', 'STRDT', |
||
59 | 'sameTerm', 'isIRI', 'isURI', 'isBLANK', 'isLITERAL', 'isNUMERIC', |
||
60 | 'REGEX', 'SUBSTR', 'REPLACE' |
||
61 | ); |
||
62 | |||
63 | /** |
||
64 | * Checks if the expression matches the given regex. |
||
65 | * |
||
66 | * @param string $regex |
||
67 | * @param string $expression |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function matchesRegex( $regex, $expression ) { |
||
73 | |||
74 | /** |
||
75 | * Returns all matching groups for the given regex. |
||
76 | * String and IRI equences are automatically escaped. |
||
77 | * |
||
78 | * @param string $regex |
||
79 | * @param string $expression |
||
80 | * @param int $group |
||
81 | * @return string[] |
||
82 | */ |
||
83 | public function getMatches( $regex, $expression, $group = 1 ) { |
||
94 | |||
95 | /** |
||
96 | * Escapes all sequences (IRIs and strings) and sets the replacements. |
||
97 | * |
||
98 | * @param string $expression |
||
99 | * @param string[] $replacements |
||
100 | * @return string |
||
101 | */ |
||
102 | public function escapeSequences( $expression, &$replacements = null ) { |
||
116 | |||
117 | private function resolveMagic( $regex ) { |
||
131 | |||
132 | private function getPrefixedIriRegex() { |
||
135 | |||
136 | private function getPathRegex() { |
||
140 | |||
141 | private function getFunctionRegex() { |
||
145 | |||
146 | } |
||
147 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.