@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | try { |
| 35 | 35 | list($domain, $finder, $rules, $options) = static::getThumbnailMeta($domain, $url); |
| 36 | 36 | |
| 37 | - $className = '\\WebThumbnailer\\Finder\\' . $finder . 'Finder'; |
|
| 37 | + $className = '\\WebThumbnailer\\Finder\\'.$finder.'Finder'; |
|
| 38 | 38 | if (!class_exists($className)) { |
| 39 | 39 | throw new UnsupportedDomainException(); |
| 40 | 40 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $jsonFiles = ConfigManager::get('settings.rules_filename', ['rules.json']); |
| 66 | 66 | $allRules = []; |
| 67 | 67 | foreach ($jsonFiles as $file) { |
| 68 | - $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH . $file)); |
|
| 68 | + $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH.$file)); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $domain = null; |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | if (preg_match($this->urlRegex, $this->url, $matches) !== 0) { |
| 55 | 55 | $total = count($matches); |
| 56 | 56 | for ($i = 1; $i < $total; $i++) { |
| 57 | - $this->thumbnailUrl = str_replace('${' . $i . '}', $matches[$i], $this->thumbnailUrl); |
|
| 57 | + $this->thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $this->thumbnailUrl); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Match only options (not ${number}) |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // With curl, the thumb is extracted during the download |
| 86 | - if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) { |
|
| 86 | + if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) { |
|
| 87 | 87 | return $thumbnail; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return int|false length of $data or false if we need to stop the download |
| 118 | 118 | */ |
| 119 | - return function ($ch, $data) use (&$content, &$thumbnail, &$isRedirected) { |
|
| 119 | + return function($ch, $data) use (&$content, &$thumbnail, &$isRedirected) { |
|
| 120 | 120 | $content .= $data; |
| 121 | 121 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
| 122 | 122 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | // After a redirection, the content type will keep the previous request value |
| 131 | 131 | // until it finds the next content-type header. |
| 132 | - if (! $isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
| 132 | + if (!$isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
| 133 | 133 | $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); |
| 134 | 134 | } |
| 135 | 135 | if (!empty($contentType) && strpos($contentType, 'text/html') === false) { |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | if (preg_match($this->urlRegex, $content, $matches) !== 0) { |
| 161 | 161 | $total = count($matches); |
| 162 | 162 | for ($i = 1; $i < $total; $i++) { |
| 163 | - $thumbnailUrl = str_replace('${' . $i . '}', $matches[$i], $thumbnailUrl); |
|
| 163 | + $thumbnailUrl = str_replace('${'.$i.'}', $matches[$i], $thumbnailUrl); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Match only options (not ${number}) |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $chosenOption = $this->getOptionValue($option); |
| 48 | 48 | |
| 49 | - return str_replace('${' . $option . '}', $chosenOption, $thumbnailUrl); |
|
| 49 | + return str_replace('${'.$option.'}', $chosenOption, $thumbnailUrl); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | protected function getOptionValue(string $option) |
| 60 | 60 | { |
| 61 | 61 | // If the provided option is not defined in the Finder rules. |
| 62 | - if (empty($this->finderOptions) || ! in_array($option, array_keys($this->finderOptions))) { |
|
| 63 | - throw new BadRulesException('Unknown option "' . $option . '" for the finder "' . $this->getName() . '"'); |
|
| 62 | + if (empty($this->finderOptions) || !in_array($option, array_keys($this->finderOptions))) { |
|
| 63 | + throw new BadRulesException('Unknown option "'.$option.'" for the finder "'.$this->getName().'"'); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // User option is defined. |
| 67 | 67 | // Any defined option must provide a replacement value in rules under the `param` key. |
| 68 | 68 | if ( |
| 69 | - ! empty($this->userOptions[$option]) |
|
| 69 | + !empty($this->userOptions[$option]) |
|
| 70 | 70 | && is_string($this->userOptions[$option]) |
| 71 | 71 | && isset($this->finderOptions[$option][$this->userOptions[$option]]['param']) |
| 72 | 72 | ) { |
@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // If no user option has been found, and no default value is provided: error. |
| 77 | - if (! isset($this->finderOptions[$option]['default'])) { |
|
| 78 | - $error = 'No default set for option "' . $option . '" for the finder "' . $this->getName() . '"'; |
|
| 77 | + if (!isset($this->finderOptions[$option]['default'])) { |
|
| 78 | + $error = 'No default set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
| 79 | 79 | throw new BadRulesException($error); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // Use default option replacement. |
| 83 | 83 | $default = $this->finderOptions[$option]['default']; |
| 84 | 84 | if (!isset($this->finderOptions[$option][$default]['param'])) { |
| 85 | - $error = 'No default parameter set for option "' . $option . '" for the finder "' . $this->getName() . '"'; |
|
| 85 | + $error = 'No default parameter set for option "'.$option.'" for the finder "'.$this->getName().'"'; |
|
| 86 | 86 | throw new BadRulesException($error); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | /** @inheritdoc */ |
| 93 | 93 | public function isHotlinkAllowed(): bool |
| 94 | 94 | { |
| 95 | - if (! isset($this->finderOptions['hotlink_allowed']) || $this->finderOptions['hotlink_allowed'] === true) { |
|
| 95 | + if (!isset($this->finderOptions['hotlink_allowed']) || $this->finderOptions['hotlink_allowed'] === true) { |
|
| 96 | 96 | return true; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -28,8 +28,8 @@ |
||
| 28 | 28 | |
| 29 | 29 | $size = $this->getOptionValue('size'); |
| 30 | 30 | // One size is actually no suffix... |
| 31 | - $size = ! empty($size) ? '_' . $size : ''; |
|
| 32 | - $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1' . $size . '$2', $thumb); |
|
| 31 | + $size = !empty($size) ? '_'.$size : ''; |
|
| 32 | + $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1'.$size.'$2', $thumb); |
|
| 33 | 33 | |
| 34 | 34 | return $thumb ?? false; |
| 35 | 35 | } |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | return $this->url; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (empty($thumbnail) && ! empty($headers) && strpos($headers[0], '200') === false) { |
|
| 63 | + if (empty($thumbnail) && !empty($headers) && strpos($headers[0], '200') === false) { |
|
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // With curl, the thumb is extracted during the download |
| 68 | - if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) { |
|
| 68 | + if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) { |
|
| 69 | 69 | return $thumbnail; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - return ! empty($content) ? static::extractMetaTag($content) : false; |
|
| 72 | + return !empty($content) ? static::extractMetaTag($content) : false; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return int|false length of $data or false if we need to stop the download |
| 101 | 101 | */ |
| 102 | - return function ($ch, $data) use ($url, &$content, &$thumbnail, &$isRedirected) { |
|
| 102 | + return function($ch, $data) use ($url, &$content, &$thumbnail, &$isRedirected) { |
|
| 103 | 103 | $content .= $data; |
| 104 | 104 | $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); |
| 105 | 105 | if (!empty($responseCode) && in_array($responseCode, [301, 302])) { |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | // After a redirection, the content type will keep the previous request value |
| 113 | 113 | // until it finds the next content-type header. |
| 114 | - if (! $isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
| 114 | + if (!$isRedirected || strpos(strtolower($data), 'content-type') !== false) { |
|
| 115 | 115 | $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); |
| 116 | 116 | } |
| 117 | 117 | // we look for image, and ignore application/octet-stream, |
@@ -155,10 +155,10 @@ discard block |
||
| 155 | 155 | $propertiesKey = ['property', 'name', 'itemprop']; |
| 156 | 156 | $properties = implode('|', $propertiesKey); |
| 157 | 157 | // Try to retrieve OpenGraph image. |
| 158 | - $ogRegex = '#<meta[^>]+(?:' . $properties . ')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
| 158 | + $ogRegex = '#<meta[^>]+(?:'.$properties.')=["\']?og:image["\'\s][^>]*content=["\']?(.*?)["\'\s>]#'; |
|
| 159 | 159 | // If the attributes are not in the order property => content (e.g. Github) |
| 160 | 160 | // New regex to keep this readable... more or less. |
| 161 | - $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:' . $properties . ')=["\']?og:image["\'\s/>]#'; |
|
| 161 | + $ogRegexReverse = '#<meta[^>]+content=["\']?([^"\'\s]+)[^>]+(?:'.$properties.')=["\']?og:image["\'\s/>]#'; |
|
| 162 | 162 | |
| 163 | 163 | if ( |
| 164 | 164 | preg_match($ogRegex, $content, $matches) > 0 |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | public static function checkExtensionRequirements(array $required): bool |
| 19 | 19 | { |
| 20 | 20 | foreach ($required as $extension) { |
| 21 | - if (! extension_loaded($extension)) { |
|
| 21 | + if (!extension_loaded($extension)) { |
|
| 22 | 22 | throw new MissingRequirementException(sprintf( |
| 23 | 23 | 'PHP extension php-%s is required and must be loaded', |
| 24 | 24 | $extension |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $error = json_last_error(); |
| 34 | 34 | $msg = json_last_error_msg(); |
| 35 | 35 | throw new BadRulesException( |
| 36 | - 'An error occured while parsing JSON file: error code #' . $error . ': ' . $msg |
|
| 36 | + 'An error occured while parsing JSON file: error code #'.$error.': '.$msg |
|
| 37 | 37 | ); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | */ |
| 54 | 54 | public static function isMetaSize(string $size): bool |
| 55 | 55 | { |
| 56 | - $metaSize = array ( |
|
| 56 | + $metaSize = array( |
|
| 57 | 57 | WebThumbnailer::SIZE_SMALL, |
| 58 | 58 | WebThumbnailer::SIZE_MEDIUM, |
| 59 | 59 | WebThumbnailer::SIZE_LARGE |