| @@ -24,19 +24,19 @@ discard block | ||
| 24 | 24 |  { | 
| 25 | 25 | use Traits_Optionable; | 
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * @see https://gist.github.com/gruber/249502 | |
| 29 | - */ | |
| 27 | + /** | |
| 28 | + * @see https://gist.github.com/gruber/249502 | |
| 29 | + */ | |
| 30 | 30 |      const REGEX_URL = '#(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i'; | 
| 31 | 31 | |
| 32 | - /** | |
| 33 | - * @var string | |
| 34 | - */ | |
| 32 | + /** | |
| 33 | + * @var string | |
| 34 | + */ | |
| 35 | 35 | protected $subject; | 
| 36 | 36 | |
| 37 | - /** | |
| 38 | - * @var string[] | |
| 39 | - */ | |
| 37 | + /** | |
| 38 | + * @var string[] | |
| 39 | + */ | |
| 40 | 40 | protected $schemes = array( | 
| 41 | 41 | 'http', | 
| 42 | 42 | 'https', | 
| @@ -62,49 +62,49 @@ discard block | ||
| 62 | 62 | ); | 
| 63 | 63 | } | 
| 64 | 64 | |
| 65 | - /** | |
| 66 | - * Whether to enable sorting the URLs alphabetically (disabled by default). | |
| 67 | - * | |
| 68 | - * @param bool $enabled | |
| 69 | - * @return ConvertHelper_URLFinder | |
| 70 | - */ | |
| 65 | + /** | |
| 66 | + * Whether to enable sorting the URLs alphabetically (disabled by default). | |
| 67 | + * | |
| 68 | + * @param bool $enabled | |
| 69 | + * @return ConvertHelper_URLFinder | |
| 70 | + */ | |
| 71 | 71 | public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder | 
| 72 | 72 |      { | 
| 73 | 73 |          $this->setOption('sorting', $enabled); | 
| 74 | 74 | return $this; | 
| 75 | 75 | } | 
| 76 | 76 | |
| 77 | - /** | |
| 78 | - * Whether to include email addresses in the search. | |
| 79 | - * This is only relevant when using the getURLs() | |
| 80 | - * method. | |
| 81 | - * | |
| 82 | - * @param bool $include | |
| 83 | - * @return ConvertHelper_URLFinder | |
| 84 | - */ | |
| 77 | + /** | |
| 78 | + * Whether to include email addresses in the search. | |
| 79 | + * This is only relevant when using the getURLs() | |
| 80 | + * method. | |
| 81 | + * | |
| 82 | + * @param bool $include | |
| 83 | + * @return ConvertHelper_URLFinder | |
| 84 | + */ | |
| 85 | 85 | public function includeEmails(bool $include=true) : ConvertHelper_URLFinder | 
| 86 | 86 |      { | 
| 87 | 87 |          $this->setOption('include-emails', $include); | 
| 88 | 88 | return $this; | 
| 89 | 89 | } | 
| 90 | 90 | |
| 91 | - /** | |
| 92 | - * Whether to omit the mailto: that is automatically added to all email addresses. | |
| 93 | - * | |
| 94 | - * @param bool $omit | |
| 95 | - * @return ConvertHelper_URLFinder | |
| 96 | - */ | |
| 91 | + /** | |
| 92 | + * Whether to omit the mailto: that is automatically added to all email addresses. | |
| 93 | + * | |
| 94 | + * @param bool $omit | |
| 95 | + * @return ConvertHelper_URLFinder | |
| 96 | + */ | |
| 97 | 97 | public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder | 
| 98 | 98 |      { | 
| 99 | 99 |          $this->setOption('omit-mailto', $omit); | 
| 100 | 100 | return $this; | 
| 101 | 101 | } | 
| 102 | 102 | |
| 103 | - /** | |
| 104 | - * Prepares the subject string by adding a newline before all URL schemes, | |
| 105 | - * to make it possible to parse even lists of links separated by commas or | |
| 106 | - * the like (http://domain.com,http://domain2.com). | |
| 107 | - */ | |
| 103 | + /** | |
| 104 | + * Prepares the subject string by adding a newline before all URL schemes, | |
| 105 | + * to make it possible to parse even lists of links separated by commas or | |
| 106 | + * the like (http://domain.com,http://domain2.com). | |
| 107 | + */ | |
| 108 | 108 | private function prepareSubject() : void | 
| 109 | 109 |      { | 
| 110 | 110 | $replaces = array(); | 
| @@ -117,11 +117,11 @@ discard block | ||
| 117 | 117 | $this->subject = str_replace(array_keys($replaces), array_values($replaces), $this->subject); | 
| 118 | 118 | } | 
| 119 | 119 | |
| 120 | - /** | |
| 121 | - * Fetches all URLs that can be found in the subject string. | |
| 122 | - * | |
| 123 | - * @return string[] | |
| 124 | - */ | |
| 120 | + /** | |
| 121 | + * Fetches all URLs that can be found in the subject string. | |
| 122 | + * | |
| 123 | + * @return string[] | |
| 124 | + */ | |
| 125 | 125 | public function getURLs() : array | 
| 126 | 126 |      { | 
| 127 | 127 | $this->prepareSubject(); | 
| @@ -154,13 +154,13 @@ discard block | ||
| 154 | 154 | return $result; | 
| 155 | 155 | } | 
| 156 | 156 | |
| 157 | - /** | |
| 158 | - * Retrieves all email addresses from the subject string. | |
| 159 | - * | |
| 160 | - * @return string[] | |
| 161 | - * | |
| 162 | - * @see omitMailto() | |
| 163 | - */ | |
| 157 | + /** | |
| 158 | + * Retrieves all email addresses from the subject string. | |
| 159 | + * | |
| 160 | + * @return string[] | |
| 161 | + * | |
| 162 | + * @see omitMailto() | |
| 163 | + */ | |
| 164 | 164 | public function getEmails() : array | 
| 165 | 165 |      { | 
| 166 | 166 | $matches = array(); | 
| @@ -194,11 +194,11 @@ discard block | ||
| 194 | 194 | return 'mailto:'; | 
| 195 | 195 | } | 
| 196 | 196 | |
| 197 | - /** | |
| 198 | - * Retrieves all URLs as URLInfo instances. | |
| 199 | - * | |
| 200 | - * @return URLInfo[] | |
| 201 | - */ | |
| 197 | + /** | |
| 198 | + * Retrieves all URLs as URLInfo instances. | |
| 199 | + * | |
| 200 | + * @return URLInfo[] | |
| 201 | + */ | |
| 202 | 202 | public function getInfos() | 
| 203 | 203 |      { | 
| 204 | 204 | $urls = $this->getURLs(); | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 68 | * @param bool $enabled | 
| 69 | 69 | * @return ConvertHelper_URLFinder | 
| 70 | 70 | */ | 
| 71 | - public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder | |
| 71 | + public function enableSorting(bool $enabled = true) : ConvertHelper_URLFinder | |
| 72 | 72 |      { | 
| 73 | 73 |          $this->setOption('sorting', $enabled); | 
| 74 | 74 | return $this; | 
| @@ -82,7 +82,7 @@ discard block | ||
| 82 | 82 | * @param bool $include | 
| 83 | 83 | * @return ConvertHelper_URLFinder | 
| 84 | 84 | */ | 
| 85 | - public function includeEmails(bool $include=true) : ConvertHelper_URLFinder | |
| 85 | + public function includeEmails(bool $include = true) : ConvertHelper_URLFinder | |
| 86 | 86 |      { | 
| 87 | 87 |          $this->setOption('include-emails', $include); | 
| 88 | 88 | return $this; | 
| @@ -94,7 +94,7 @@ discard block | ||
| 94 | 94 | * @param bool $omit | 
| 95 | 95 | * @return ConvertHelper_URLFinder | 
| 96 | 96 | */ | 
| 97 | - public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder | |
| 97 | + public function omitMailto(bool $omit = true) : ConvertHelper_URLFinder | |
| 98 | 98 |      { | 
| 99 | 99 |          $this->setOption('omit-mailto', $omit); | 
| 100 | 100 | return $this; | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 |      { | 
| 110 | 110 | $replaces = array(); | 
| 111 | 111 | |
| 112 | - foreach($this->schemes as $scheme) | |
| 112 | + foreach ($this->schemes as $scheme) | |
| 113 | 113 |          { | 
| 114 | 114 | $replaces[$scheme.':'] = PHP_EOL.$scheme.':'; | 
| 115 | 115 | } | 
| @@ -131,20 +131,20 @@ discard block | ||
| 131 | 131 | |
| 132 | 132 | $result = array(); | 
| 133 | 133 | |
| 134 | - foreach($matches[0] as $match) | |
| 134 | + foreach ($matches[0] as $match) | |
| 135 | 135 |          { | 
| 136 | - if(strstr($match, '://') && !in_array($match, $result)) | |
| 136 | + if (strstr($match, '://') && !in_array($match, $result)) | |
| 137 | 137 |              { | 
| 138 | 138 | $result[] = $match; | 
| 139 | 139 | } | 
| 140 | 140 | } | 
| 141 | 141 | |
| 142 | -        if($this->getBoolOption('include-emails')) | |
| 142 | +        if ($this->getBoolOption('include-emails')) | |
| 143 | 143 |          { | 
| 144 | 144 | $result = array_merge($result, $this->getEmails()); | 
| 145 | 145 | } | 
| 146 | 146 | |
| 147 | -        if($this->getBoolOption('sorting')) | |
| 147 | +        if ($this->getBoolOption('sorting')) | |
| 148 | 148 |          { | 
| 149 | 149 |              usort($result, function(string $a, string $b) { | 
| 150 | 150 | return strnatcasecmp($a, $b); | 
| @@ -169,12 +169,12 @@ discard block | ||
| 169 | 169 | $result = array(); | 
| 170 | 170 | $prefix = $this->getEmailPrefix(); | 
| 171 | 171 | |
| 172 | - foreach($matches[0] as $email) | |
| 172 | + foreach ($matches[0] as $email) | |
| 173 | 173 |          { | 
| 174 | 174 | $result[] = $prefix.$email; | 
| 175 | 175 | } | 
| 176 | 176 | |
| 177 | -        if($this->getBoolOption('sorting')) | |
| 177 | +        if ($this->getBoolOption('sorting')) | |
| 178 | 178 |          { | 
| 179 | 179 |              usort($result, function(string $a, string $b) { | 
| 180 | 180 | return strnatcasecmp($a, $b); | 
| @@ -186,7 +186,7 @@ discard block | ||
| 186 | 186 | |
| 187 | 187 | private function getEmailPrefix() : string | 
| 188 | 188 |      { | 
| 189 | -        if($this->getBoolOption('omit-mailto')) | |
| 189 | +        if ($this->getBoolOption('omit-mailto')) | |
| 190 | 190 |          { | 
| 191 | 191 | return ''; | 
| 192 | 192 | } | 
| @@ -205,7 +205,7 @@ discard block | ||
| 205 | 205 | |
| 206 | 206 | $result = array(); | 
| 207 | 207 | |
| 208 | - foreach($urls as $url) | |
| 208 | + foreach ($urls as $url) | |
| 209 | 209 |          { | 
| 210 | 210 | $result[] = parseURL($url); | 
| 211 | 211 | } |