1 | <?php |
||
19 | final class LinkParserHelper |
||
20 | { |
||
21 | /** |
||
22 | * Attempt to parse link destination |
||
23 | * |
||
24 | * @param Cursor $cursor |
||
25 | * |
||
26 | * @return null|string The string, or null if no match |
||
27 | */ |
||
28 | 438 | public static function parseLinkDestination(Cursor $cursor): ?string |
|
29 | { |
||
30 | 438 | if ($res = $cursor->match(RegexHelper::REGEX_LINK_DESTINATION_BRACES)) { |
|
31 | // Chop off surrounding <..>: |
||
32 | 36 | return UrlEncoder::unescapeAndEncode( |
|
33 | 36 | RegexHelper::unescape(\substr($res, 1, -1)) |
|
34 | ); |
||
35 | } |
||
36 | |||
37 | 405 | if ($cursor->getCharacter() === '<') { |
|
38 | 9 | return null; |
|
39 | } |
||
40 | |||
41 | 396 | $destination = self::manuallyParseLinkDestination($cursor); |
|
42 | 396 | if ($destination === null) { |
|
43 | return null; |
||
44 | } |
||
45 | |||
46 | 396 | return UrlEncoder::unescapeAndEncode( |
|
47 | 396 | RegexHelper::unescape($destination) |
|
48 | ); |
||
49 | } |
||
50 | |||
51 | 297 | public static function parseLinkLabel(Cursor $cursor): int |
|
52 | { |
||
53 | 297 | $match = $cursor->match('/^\[(?:[^\\\\\[\]]|\\\\.){0,1000}\]/'); |
|
54 | 297 | if ($match === null) { |
|
55 | 219 | return 0; |
|
56 | } |
||
57 | |||
58 | 90 | $length = \mb_strlen($match, 'utf-8'); |
|
59 | |||
60 | 90 | if ($length > 1001) { |
|
61 | return 0; |
||
62 | } |
||
63 | |||
64 | 90 | return $length; |
|
65 | } |
||
66 | |||
67 | 432 | public static function parsePartialLinkLabel(Cursor $cursor): ?string |
|
68 | { |
||
69 | 432 | return $cursor->match('/^(?:[^\\\\\[\]]|\\\\.){0,1000}/'); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Attempt to parse link title (sans quotes) |
||
74 | * |
||
75 | * @param Cursor $cursor |
||
76 | * |
||
77 | * @return null|string The string, or null if no match |
||
78 | */ |
||
79 | 54 | public static function parseLinkTitle(Cursor $cursor): ?string |
|
88 | |||
89 | 111 | public static function parsePartialLinkTitle(Cursor $cursor, string $endDelimiter): ?string |
|
90 | { |
||
91 | 111 | $endDelimiter = \preg_quote($endDelimiter, '/'); |
|
99 | |||
100 | 396 | private static function manuallyParseLinkDestination(Cursor $cursor): ?string |
|
141 | } |
||
142 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: