Completed
Push — master ( 4cb8f2...aa668f )
by Arthur
12s
created
src/WebThumbnailer/Utils/ImageUtils.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public static function generateThumbnail($imageStr, $target, $maxWidth, $maxHeight, $crop = false)
34 34
     {
35
-        if (! touch($target)) {
35
+        if (!touch($target)) {
36 36
             throw new ImageConvertException('Target file is not writable.');
37 37
         }
38 38
 
39
-        if ($crop && ($maxWidth == 0  || $maxHeight == 0)) {
39
+        if ($crop && ($maxWidth == 0 || $maxHeight == 0)) {
40 40
             throw new ImageConvertException('Both width and height must be provided for cropping');
41 41
         }
42 42
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             throw new ImageConvertException('Could not generate the thumbnail from source image.');
68 68
         }
69 69
 
70
-        if (! imagecopyresized(
70
+        if (!imagecopyresized(
71 71
             $targetImg,
72 72
             $sourceImg,
73 73
             0,
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         $diffHeight = !empty($maxHeight) ? $originalHeight - $maxHeight : false;
109 109
 
110 110
         if (($diffHeight === false && $diffWidth !== false)
111
-            || ($diffWidth > $diffHeight && ! $crop)
111
+            || ($diffWidth > $diffHeight && !$crop)
112 112
             || ($diffWidth < $diffHeight && $crop)
113 113
         ) {
114 114
             $finalWidth = $maxWidth;
Please login to merge, or discard this patch.
src/WebThumbnailer/Finder/FinderCommon.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     protected function replaceOption($thumbnailUrl, $option)
59 59
     {
60 60
         $chosenOption = $this->getOptionValue($option);
61
-        return str_replace('${'. $option .'}', $chosenOption, $thumbnailUrl);
61
+        return str_replace('${'.$option.'}', $chosenOption, $thumbnailUrl);
62 62
     }
63 63
 
64 64
     /**
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
     protected function getOptionValue($option)
73 73
     {
74 74
         // If the provided option is not defined in the Finder rules.
75
-        if (empty($this->finderOptions) || ! in_array($option, array_keys($this->finderOptions))) {
76
-            throw new BadRulesException('Unknown option "'. $option .'" for the finder "'. $this->getName() .'"');
75
+        if (empty($this->finderOptions) || !in_array($option, array_keys($this->finderOptions))) {
76
+            throw new BadRulesException('Unknown option "'.$option.'" for the finder "'.$this->getName().'"');
77 77
         }
78 78
 
79 79
         // User option is defined.
80 80
         // Any defined option must provide a replacement value in rules under the `param` key.
81
-        if (! empty($this->userOptions[$option])
81
+        if (!empty($this->userOptions[$option])
82 82
             && is_string($this->userOptions[$option])
83 83
             && isset($this->finderOptions[$option][$this->userOptions[$option]]['param'])
84 84
         ) {
@@ -86,15 +86,15 @@  discard block
 block discarded – undo
86 86
         }
87 87
 
88 88
         // If no user option has been found, and no default value is provided: error.
89
-        if (! isset($this->finderOptions[$option]['default'])) {
90
-            $error = 'No default set for option "'. $option .'" for the finder "'. $this->getName() .'"';
89
+        if (!isset($this->finderOptions[$option]['default'])) {
90
+            $error = 'No default set for option "'.$option.'" for the finder "'.$this->getName().'"';
91 91
             throw new BadRulesException($error);
92 92
         }
93 93
 
94 94
         // Use default option replacement.
95 95
         $default = $this->finderOptions[$option]['default'];
96 96
         if (!isset($this->finderOptions[$option][$default]['param'])) {
97
-            $error = 'No default parameter set for option "'. $option .'" for the finder "'. $this->getName() .'"';
97
+            $error = 'No default parameter set for option "'.$option.'" for the finder "'.$this->getName().'"';
98 98
             throw new BadRulesException($error);
99 99
         }
100 100
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function isHotlinkAllowed()
108 108
     {
109
-        if (! isset($this->finderOptions['hotlink_allowed'])
109
+        if (!isset($this->finderOptions['hotlink_allowed'])
110 110
             ||  $this->finderOptions['hotlink_allowed'] === true
111 111
         ) {
112 112
             return true;
Please login to merge, or discard this patch.
src/WebThumbnailer/Application/WebAccess/WebAccessCUrl.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
             $maxBytes = ConfigManager::get('settings.default.max_img_dl', 16777216);
60 60
         }
61 61
 
62
-        $cookie = ConfigManager::get('settings.path.cache') . '/cookie.txt';
62
+        $cookie = ConfigManager::get('settings.path.cache').'/cookie.txt';
63 63
         $userAgent =
64 64
             'Mozilla/5.0 (X11; Linux x86_64; rv:45.0; WebThumbnailer)'
65 65
             . ' Gecko/20100101 Firefox/45.0';
66 66
         $acceptLanguage =
67
-            substr(setlocale(LC_COLLATE, 0), 0, 2) . ',en-US;q=0.7,en;q=0.3';
67
+            substr(setlocale(LC_COLLATE, 0), 0, 2).',en-US;q=0.7,en;q=0.3';
68 68
         $maxRedirs = 6;
69 69
 
70 70
         $ch = curl_init($url);
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         curl_setopt(
80 80
             $ch,
81 81
             CURLOPT_HTTPHEADER,
82
-            ['Accept-Language: ' . $acceptLanguage]
82
+            ['Accept-Language: '.$acceptLanguage]
83 83
         );
84 84
         curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs);
85 85
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
         curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
92 92
 
93 93
         // Max download size management
94
-        curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16);
94
+        curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024 * 16);
95 95
         curl_setopt($ch, CURLOPT_NOPROGRESS, false);
96 96
         curl_setopt(
97 97
             $ch,
98 98
             CURLOPT_PROGRESSFUNCTION,
99
-            function ($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) {
99
+            function($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) {
100 100
                 $downloaded = $arg2;
101 101
                 // Non-zero return stops downloading
102 102
                 return ($downloaded > $maxBytes) ? 1 : 0;
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         curl_close($ch);
118 118
 
119 119
         if ($response === false) {
120
-            return [[0 => 'curl_exec() error #'. $errorNo .': ' . $errorStr], false];
120
+            return [[0 => 'curl_exec() error #'.$errorNo.': '.$errorStr], false];
121 121
         }
122 122
 
123 123
         // Formatting output like the fallback method
Please login to merge, or discard this patch.
src/WebThumbnailer/Application/Thumbnailer.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         }
111 111
 
112 112
         if (empty($thumburl)) {
113
-            $error = 'No thumbnail could be found using '. $this->finder->getName() .' finder: '. $this->url;
113
+            $error = 'No thumbnail could be found using '.$this->finder->getName().' finder: '.$this->url;
114 114
             throw new ThumbnailNotFoundException($error);
115 115
         }
116 116
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function thumbnailStrictHotlink($thumburl)
141 141
     {
142
-        if (! $this->finder->isHotlinkAllowed()) {
142
+        if (!$this->finder->isHotlinkAllowed()) {
143 143
             throw new ThumbnailNotFoundException('Hotlink is not supported for this URL.');
144 144
         }
145 145
         return $thumburl;
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     protected function thumbnailHotlink($thumburl)
160 160
     {
161
-        if (! $this->finder->isHotlinkAllowed()) {
161
+        if (!$this->finder->isHotlinkAllowed()) {
162 162
             return $this->thumbnailDownload($thumburl);
163 163
         }
164 164
         return $thumburl;
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 
210 210
         if (strpos($headers[0], '200') === false) {
211 211
             throw new DownloadException(
212
-                'Unreachable thumbnail URL. HTTP '. $headers[0] .'.'. PHP_EOL .
213
-                ' - thumbnail URL: '. $thumburl
212
+                'Unreachable thumbnail URL. HTTP '.$headers[0].'.'.PHP_EOL.
213
+                ' - thumbnail URL: '.$thumburl
214 214
             );
215 215
         }
216 216
 
217 217
         if (empty($data)) {
218
-            throw new DownloadException('Couldn\'t download the thumbnail at '. $thumburl);
218
+            throw new DownloadException('Couldn\'t download the thumbnail at '.$thumburl);
219 219
         }
220 220
 
221 221
         // Resize and save it locally.
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             $this->options[WebThumbnailer::CROP]
228 228
         );
229 229
 
230
-        if (! is_file($thumbPath)) {
230
+        if (!is_file($thumbPath)) {
231 231
             throw new ImageConvertException('Thumbnail was not generated.');
232 232
         }
233 233
 
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
     {
308 308
         // Width
309 309
         $width = 0;
310
-        if (! empty($options[WebThumbnailer::MAX_WIDTH])) {
310
+        if (!empty($options[WebThumbnailer::MAX_WIDTH])) {
311 311
             if (SizeUtils::isMetaSize($options[WebThumbnailer::MAX_WIDTH])) {
312 312
                 $width = SizeUtils::getMetaSize($options[WebThumbnailer::MAX_WIDTH]);
313 313
             } elseif (is_int($options[WebThumbnailer::MAX_WIDTH])
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
             if (count(array_intersect($incompatibleFlags, $options)) > 1) {
358 358
                 $error = 'Only one of these flags can be set between: ';
359 359
                 foreach ($incompatibleFlags as $flag) {
360
-                    $error .= $flag .' ';
360
+                    $error .= $flag.' ';
361 361
                 }
362 362
                 throw new BadRulesException($error);
363 363
             }
Please login to merge, or discard this patch.
src/WebThumbnailer/Finder/DefaultFinder.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,16 +62,16 @@  discard block
 block discarded – undo
62 62
             return $this->url;
63 63
         }
64 64
 
65
-        if (empty($thumbnail) && ! empty($headers) && strpos($headers[0], '200') === false) {
65
+        if (empty($thumbnail) && !empty($headers) && strpos($headers[0], '200') === false) {
66 66
             return false;
67 67
         }
68 68
 
69 69
         // With curl, the thumb is extracted during the download
70
-        if ($this->webAccess instanceof WebAccessCUrl && ! empty($thumbnail)) {
70
+        if ($this->webAccess instanceof WebAccessCUrl && !empty($thumbnail)) {
71 71
             return $thumbnail;
72 72
         }
73 73
 
74
-        return ! empty($content) ? self::extractMetaTag($content) : false;
74
+        return !empty($content) ? self::extractMetaTag($content) : false;
75 75
     }
76 76
 
77 77
     /**
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
          *
102 102
          * @return int|bool length of $data or false if we need to stop the download
103 103
          */
104
-        return function (&$ch, $data) use ($url, &$content, &$thumbnail, &$isRedirected) {
104
+        return function(&$ch, $data) use ($url, &$content, &$thumbnail, &$isRedirected) {
105 105
             $content .= $data;
106 106
             $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
107 107
             if (!empty($responseCode) && in_array($responseCode, [301, 302])) {
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             }
114 114
             // After a redirection, the content type will keep the previous request value
115 115
             // until it finds the next content-type header.
116
-            if (! $isRedirected || strpos(strtolower($data), 'content-type') !== false) {
116
+            if (!$isRedirected || strpos(strtolower($data), 'content-type') !== false) {
117 117
                 $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
118 118
             }
119 119
             // we look for image, and ignore application/octet-stream,
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
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 (preg_match($ogRegex, $content, $matches) > 0
164 164
             || preg_match($ogRegexReverse, $content, $matches) > 0
Please login to merge, or discard this patch.
src/WebThumbnailer/Utils/UrlUtils.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
      */
21 21
     public static function getDomain($url)
22 22
     {
23
-        if (! parse_url($url, PHP_URL_SCHEME)) {
24
-            $url = 'http://' . $url;
23
+        if (!parse_url($url, PHP_URL_SCHEME)) {
24
+            $url = 'http://'.$url;
25 25
         }
26 26
         return strtolower(parse_url($url, PHP_URL_HOST));
27 27
     }
Please login to merge, or discard this patch.
src/WebThumbnailer/Application/ConfigManager.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * @var array List of JSON configuration file path.
24 24
      */
25 25
     public static $configFiles = [
26
-        FileUtils::RESOURCES_PATH . 'settings.json',
26
+        FileUtils::RESOURCES_PATH.'settings.json',
27 27
     ];
28 28
 
29 29
     /**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     public static function clear()
68 68
     {
69 69
         self::$configFiles = [
70
-            FileUtils::RESOURCES_PATH . 'settings.json',
70
+            FileUtils::RESOURCES_PATH.'settings.json',
71 71
         ];
72 72
         self::reload();
73 73
     }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     protected static function getConfig($settings, $config)
111 111
     {
112
-        if (! is_array($settings) || count($settings) == 0) {
112
+        if (!is_array($settings) || count($settings) == 0) {
113 113
             return self::$NOT_FOUND;
114 114
         }
115 115
 
Please login to merge, or discard this patch.
src/WebThumbnailer/Application/CacheManager.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     /**
27 27
      * Thumbnails image cache.
28 28
      */
29
-    const TYPE_THUMB  = 'thumb';
29
+    const TYPE_THUMB = 'thumb';
30 30
     /**
31 31
      * Finder cache.
32 32
      */
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             self::rebuildCacheFolders();
57 57
             return self::getCachePath($type, true);
58 58
         } elseif (!$path) {
59
-            throw new IOException('Cache folders are not writable: '. $cache);
59
+            throw new IOException('Cache folders are not writable: '.$cache);
60 60
         }
61 61
         return $path;
62 62
     }
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
         self::createDomainThumbCacheFolder($domainHash, $type);
87 87
         $domainFolder = FileUtils::getPath(self::getCachePath($type), $domainHash);
88 88
         if ($type === self::TYPE_THUMB) {
89
-            $suffix = $width . $height . ($crop ? '1' : '0') .'.jpg';
89
+            $suffix = $width.$height.($crop ? '1' : '0').'.jpg';
90 90
         } else {
91
-            $suffix = $width . $height;
91
+            $suffix = $width.$height;
92 92
         }
93
-        return $domainFolder . self::getThumbFilename($url) . $suffix;
93
+        return $domainFolder.self::getThumbFilename($url).$suffix;
94 94
     }
95 95
 
96 96
     /**
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     public static function isCacheValid($cacheFile, $domain, $type)
109 109
     {
110 110
         $out = false;
111
-        $cacheDuration = ConfigManager::get('settings.cache_duration', 3600*24*31);
111
+        $cacheDuration = ConfigManager::get('settings.cache_duration', 3600 * 24 * 31);
112 112
 
113 113
         if (is_readable($cacheFile)
114 114
             && ($cacheDuration < 0 || (time() - filemtime($cacheFile)) < $cacheDuration)
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
     protected static function createDomainThumbCacheFolder($domain, $type)
131 131
     {
132 132
         $cachePath = self::getCachePath($type);
133
-        $domainFolder = $cachePath . $domain;
133
+        $domainFolder = $cachePath.$domain;
134 134
         if (!file_exists($domainFolder)) {
135 135
             mkdir($domainFolder, 0775, false);
136
-            touch($domainFolder . '/' . self::$CLEAN_FILE);
136
+            touch($domainFolder.'/'.self::$CLEAN_FILE);
137 137
         }
138 138
         self::createHtaccessFile($cachePath, $type === self::TYPE_THUMB);
139 139
     }
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
     protected static function createHtaccessFile($path, $allowed = false)
149 149
     {
150 150
         $apacheVersion = ConfigManager::get('settings.apache_version', '');
151
-        $htaccessFile = $path . '.htaccess';
151
+        $htaccessFile = $path.'.htaccess';
152 152
         if (file_exists($htaccessFile)) {
153 153
             return;
154 154
         }
155
-        $templateFile = file_exists(FileUtils::RESOURCES_PATH .'htaccess'. $apacheVersion .'_template')
156
-            ? FileUtils::RESOURCES_PATH .'htaccess'. $apacheVersion .'_template'
157
-            : FileUtils::RESOURCES_PATH .'htaccess_template';
155
+        $templateFile = file_exists(FileUtils::RESOURCES_PATH.'htaccess'.$apacheVersion.'_template')
156
+            ? FileUtils::RESOURCES_PATH.'htaccess'.$apacheVersion.'_template'
157
+            : FileUtils::RESOURCES_PATH.'htaccess_template';
158 158
         $template = new \Text_Template($templateFile);
159 159
         $template->setVar([
160 160
             'new_all' => $allowed ? 'granted' : 'denied',
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     protected static function checkCacheType($type)
188 188
     {
189 189
         if ($type != self::TYPE_THUMB && $type != self::TYPE_FINDER) {
190
-            throw new CacheException('Unknown cache type '. $type);
190
+            throw new CacheException('Unknown cache type '.$type);
191 191
         }
192 192
     }
193 193
 
@@ -197,19 +197,19 @@  discard block
 block discarded – undo
197 197
     protected static function rebuildCacheFolders()
198 198
     {
199 199
         $mainFolder = ConfigManager::get('settings.path.cache', 'cache/');
200
-        if (! is_dir($mainFolder)) {
200
+        if (!is_dir($mainFolder)) {
201 201
             mkdir($mainFolder, 0755);
202 202
         }
203
-        if (! is_dir($mainFolder.self::TYPE_THUMB)) {
203
+        if (!is_dir($mainFolder.self::TYPE_THUMB)) {
204 204
             mkdir($mainFolder.self::TYPE_THUMB, 0755);
205 205
         }
206
-        if (! is_readable($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) {
207
-            touch($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep');
206
+        if (!is_readable($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) {
207
+            touch($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep');
208 208
         }
209
-        if (! is_dir($mainFolder.self::TYPE_FINDER)) {
210
-            mkdir($mainFolder . self::TYPE_FINDER, 0755);
209
+        if (!is_dir($mainFolder.self::TYPE_FINDER)) {
210
+            mkdir($mainFolder.self::TYPE_FINDER, 0755);
211 211
         }
212
-        if (! is_readable($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) {
212
+        if (!is_readable($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) {
213 213
             touch($mainFolder.self::TYPE_FINDER.DIRECTORY_SEPARATOR.'.gitkeep');
214 214
         }
215 215
     }
Please login to merge, or discard this patch.
src/WebThumbnailer/Finder/FinderFactory.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         try {
37 37
             list($domain, $finder, $rules, $options) = self::getThumbnailMeta($domain, $url);
38 38
 
39
-            $className = '\\WebThumbnailer\\Finder\\' . $finder . 'Finder';
39
+            $className = '\\WebThumbnailer\\Finder\\'.$finder.'Finder';
40 40
             if (!class_exists($className)) {
41 41
                 throw new UnsupportedDomainException();
42 42
             }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $jsonFiles = ConfigManager::get('settings.rules_filename', ['rules.json']);
68 68
         $allRules = [];
69 69
         foreach ($jsonFiles as $file) {
70
-            $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH . $file));
70
+            $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH.$file));
71 71
         }
72 72
 
73 73
         $domain = null;
Please login to merge, or discard this patch.