Completed
Pull Request — master (#9)
by Arthur
02:37 queued 57s
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/FinderFactory.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         try {
34 34
             list($domain, $finder, $rules, $options) = self::getThumbnailMeta($domain, $url);
35 35
 
36
-            $className = '\\WebThumbnailer\\Finder\\' . $finder . 'Finder';
36
+            $className = '\\WebThumbnailer\\Finder\\'.$finder.'Finder';
37 37
             if (!class_exists($className)) {
38 38
                 throw new Exception\UnsupportedDomainException();
39 39
             }
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         $jsonFiles = ConfigManager::get('settings.rules_filename', ['rules.json']);
64 64
         $allRules = [];
65 65
         foreach ($jsonFiles as $file) {
66
-            $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH . $file));
66
+            $allRules = array_merge($allRules, DataUtils::loadJson(FileUtils::RESOURCES_PATH.$file));
67 67
         }
68 68
 
69 69
         $domain = null;
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/ConfigManager.php 1 patch
Spacing   +2 added lines, -2 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
     /**
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     protected static function getConfig($settings, $config)
104 104
     {
105
-        if (! is_array($settings) || count($settings) == 0) {
105
+        if (!is_array($settings) || count($settings) == 0) {
106 106
             return self::$NOT_FOUND;
107 107
         }
108 108
 
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/Application/CacheManager.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     /**
26 26
      * Thumbnails image cache.
27 27
      */
28
-    const TYPE_THUMB  = 'thumb';
28
+    const TYPE_THUMB = 'thumb';
29 29
     /**
30 30
      * Finder cache.
31 31
      */
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             self::rebuildCacheFolders();
56 56
             return self::getCachePath($type, true);
57 57
         } elseif (!$path) {
58
-            throw new IOException('Cache folders are not writable: '. $cache);
58
+            throw new IOException('Cache folders are not writable: '.$cache);
59 59
         }
60 60
         return $path;
61 61
     }
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
         self::createDomainThumbCacheFolder($domainHash, $type);
79 79
         $domainFolder = FileUtils::getPath(self::getCachePath($type), $domainHash);
80 80
         if ($type === self::TYPE_THUMB) {
81
-            $suffix = $width . $height . ($crop ? '1' : '0') .'.jpg';
81
+            $suffix = $width.$height.($crop ? '1' : '0').'.jpg';
82 82
         } else {
83
-            $suffix = $width . $height;
83
+            $suffix = $width.$height;
84 84
         }
85
-        return $domainFolder . self::getThumbFilename($url) . $suffix;
85
+        return $domainFolder.self::getThumbFilename($url).$suffix;
86 86
     }
87 87
 
88 88
     /**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public static function isCacheValid($cacheFile, $domain, $type)
101 101
     {
102 102
         $out = false;
103
-        $cacheDuration = ConfigManager::get('settings.cache_duration', 3600*24*31);
103
+        $cacheDuration = ConfigManager::get('settings.cache_duration', 3600 * 24 * 31);
104 104
 
105 105
         if (is_readable($cacheFile)
106 106
             && ($cacheDuration < 0 || (time() - filemtime($cacheFile)) < $cacheDuration)
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
      */
122 122
     protected static function createDomainThumbCacheFolder($domain, $type)
123 123
     {
124
-        $domainFolder = self::getCachePath($type) . $domain;
124
+        $domainFolder = self::getCachePath($type).$domain;
125 125
         if (!file_exists($domainFolder)) {
126 126
             mkdir($domainFolder, 0775, false);
127
-            touch($domainFolder . '/' . self::$CLEAN_FILE);
127
+            touch($domainFolder.'/'.self::$CLEAN_FILE);
128 128
         }
129 129
     }
130 130
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     protected static function checkCacheType($type)
152 152
     {
153 153
         if ($type != self::TYPE_THUMB && $type != self::TYPE_FINDER) {
154
-            throw new CacheException('Unknown cache type '. $type);
154
+            throw new CacheException('Unknown cache type '.$type);
155 155
         }
156 156
     }
157 157
 
@@ -161,19 +161,19 @@  discard block
 block discarded – undo
161 161
     protected static function rebuildCacheFolders()
162 162
     {
163 163
         $mainFolder = ConfigManager::get('settings.path.cache', 'cache/');
164
-        if (! is_dir($mainFolder)) {
164
+        if (!is_dir($mainFolder)) {
165 165
             mkdir($mainFolder, 0755);
166 166
         }
167
-        if (! is_dir($mainFolder.self::TYPE_THUMB)) {
167
+        if (!is_dir($mainFolder.self::TYPE_THUMB)) {
168 168
             mkdir($mainFolder.self::TYPE_THUMB, 0755);
169 169
         }
170
-        if (! is_readable($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) {
171
-            touch($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep');
170
+        if (!is_readable($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) {
171
+            touch($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep');
172 172
         }
173
-        if (! is_dir($mainFolder.self::TYPE_FINDER)) {
174
-            mkdir($mainFolder . self::TYPE_FINDER, 0755);
173
+        if (!is_dir($mainFolder.self::TYPE_FINDER)) {
174
+            mkdir($mainFolder.self::TYPE_FINDER, 0755);
175 175
         }
176
-        if (! is_readable($mainFolder . self::TYPE_THUMB . DIRECTORY_SEPARATOR . '.gitkeep')) {
176
+        if (!is_readable($mainFolder.self::TYPE_THUMB.DIRECTORY_SEPARATOR.'.gitkeep')) {
177 177
             touch($mainFolder.self::TYPE_FINDER.DIRECTORY_SEPARATOR.'.gitkeep');
178 178
         }
179 179
     }
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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 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
     }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     public static function generateRelativeUrlFromPath($server, $path)
42 42
     {
43 43
         if (isset($server['DOCUMENT_ROOT'])) {
44
-            $root = ! empty($server['DOCUMENT_ROOT']) ? rtrim($server['DOCUMENT_ROOT'], '/') .'/' : '';
44
+            $root = !empty($server['DOCUMENT_ROOT']) ? rtrim($server['DOCUMENT_ROOT'], '/').'/' : '';
45 45
             $path = substr($path, strlen($root));
46 46
         }
47 47
 
Please login to merge, or discard this patch.