diff --git a/CImage.php b/CImage.php index 2397229..c8bbc95 100644 --- a/CImage.php +++ b/CImage.php @@ -445,7 +445,7 @@ class CImage /** - * Set whitelist for valid hostnames from where remote source can be + * Set whitelist for valid hostnames from where remote source can be * downloaded. * * @param array $whitelist with regexp hostnames to allow download from. @@ -462,7 +462,7 @@ class CImage /** - * Check if the hostname for the remote image, is on a whitelist, + * Check if the hostname for the remote image, is on a whitelist, * if the whitelist is defined. * * @param string $src the remote source. @@ -779,7 +779,7 @@ class CImage $info = list($this->width, $this->height, $this->fileType, $this->attr) = getimagesize($file); if (empty($info)) { throw new Exception("The file doesn't seem to be a valid image."); - } + } if ($this->verbose) { $this->log("Loading image details for: {$file}"); @@ -976,7 +976,7 @@ class CImage $this->cropHeight = round($height / $ratio); $this->log("Crop width, height, ratio: $this->cropWidth x $this->cropHeight ($ratio)."); - } else if ($this->fillToFit) { + } elseif ($this->fillToFit) { // Use newWidth and newHeigh as defined width/height, // image should fit the area. @@ -1204,7 +1204,7 @@ class CImage $this->extension = isset($this->extension) ? $this->extension - : (isset($parts['extension']) + : (isset($parts['extension']) ? $parts['extension'] : null); @@ -1276,7 +1276,7 @@ class CImage /** - * Load image from disk. Try to load image without verbose error message, + * Load image from disk. Try to load image without verbose error message, * if fail, load again and display error messages. * * @param string $src of image. @@ -1509,7 +1509,7 @@ class CImage $this->width = $this->newWidth; $this->height = $this->newHeight; - } else if ($this->fillToFit) { + } elseif ($this->fillToFit) { // Resize by fill to fit $this->log("Resizing using strategy - Fill to fit"); @@ -1548,7 +1548,7 @@ class CImage $this->width = $this->newWidth; $this->height = $this->newHeight; - } else if (!($this->newWidth == $this->width && $this->newHeight == $this->height)) { + } elseif (!($this->newWidth == $this->width && $this->newHeight == $this->height)) { // Resize it $this->log("Resizing, new height and/or width"); @@ -1569,10 +1569,10 @@ class CImage if ($this->newWidth > $this->width && $this->newHeight > $this->height) { $posX = round(($this->newWidth - $this->width) / 2); $posY = round(($this->newHeight - $this->height) / 2); - } else if ($this->newWidth > $this->width) { + } elseif ($this->newWidth > $this->width) { $posX = round(($this->newWidth - $this->width) / 2); $cropY = round(($this->height - $this->newHeight) / 2); - } else if ($this->newHeight > $this->height) { + } elseif ($this->newHeight > $this->height) { $posY = round(($this->newHeight - $this->height) / 2); $cropX = round(($this->width - $this->newWidth) / 2); } diff --git a/CRemoteImage.php b/CRemoteImage.php index a442a82..7a3cb54 100644 --- a/CRemoteImage.php +++ b/CRemoteImage.php @@ -145,7 +145,8 @@ class CRemoteImage * * @return $this */ - function setHeaderFields() { + public function setHeaderFields() + { $this->http->setHeader("User-Agent", "CImage/0.7.0 (PHP/". phpversion() . " cURL)"); $this->http->setHeader("Accept", "image/jpeg,image/png,image/gif"); @@ -164,8 +165,8 @@ class CRemoteImage * * @return string as path to saved file or false if not saved. */ - function save() { - + public function save() + { $this->cache = array(); $date = $this->http->getDate(time()); $maxAge = $this->http->getMaxAge($this->defaultMaxAge); @@ -201,8 +202,8 @@ class CRemoteImage * * @return string as path to cached file. */ - function updateCacheDetails() { - + public function updateCacheDetails() + { $date = $this->http->getDate(time()); $maxAge = $this->http->getMaxAge($this->defaultMaxAge); $lastModified = $this->http->getLastModified(); @@ -227,8 +228,8 @@ class CRemoteImage * * @return string as path to downloaded file or false if failed. */ - function download($url) { - + public function download($url) + { $this->http = new CHttpGet(); $this->url = $url; @@ -252,7 +253,7 @@ class CRemoteImage if ($this->status === 200) { $this->isCacheWritable(); return $this->save(); - } else if ($this->status === 304) { + } elseif ($this->status === 304) { $this->isCacheWritable(); return $this->updateCacheDetails(); } diff --git a/CWhitelist.php b/CWhitelist.php index d0db039..539e392 100644 --- a/CWhitelist.php +++ b/CWhitelist.php @@ -13,10 +13,10 @@ class CWhitelist /** - * Set the whitelist from an array of strings, each item in the + * Set the whitelist from an array of strings, each item in the * whitelist should be a regexp without the surrounding / or #. * - * @param array $whitelist with all valid options, + * @param array $whitelist with all valid options, * default is to clear the whitelist. * * @return $this @@ -44,8 +44,8 @@ class CWhitelist public function check($item, $whitelist = null) { if ($whitelist !== null) { - $this->set($whitelist); - } + $this->set($whitelist); + } if (empty($item) or empty($this->whitelist)) { return false; diff --git a/REVISION.md b/REVISION.md index 4c1ad1c..4eb72f0 100644 --- a/REVISION.md +++ b/REVISION.md @@ -8,6 +8,7 @@ Revision history v0.7.0.x (latest) ------------------------------------- +* Improved codestyle and added `phpcs.xml` to start using phpcs to check code style, fix #95. * Adding `composer.json` for publishing on packagist. * Add permalink to setup for comparing images with `webroot/compare/compare.php`, fix #92. * Allow space in filename by using `urlencode()` and allow space as valid filenam character. fix #91. diff --git a/autoload.php b/autoload.php index 26dc77f..b65d4e1 100644 --- a/autoload.php +++ b/autoload.php @@ -17,7 +17,7 @@ spl_autoload_register(function ($class) { //$path = CIMAGE_SOURCE_PATH . "/{$class}.php"; $path = __DIR__ . "/{$class}.php"; - if(is_file($path)) { + if (is_file($path)) { require($path); } }); diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..c65fee7 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,32 @@ + + + Custom rule set. + + . + test + autoload.php + + docs/* + coverage/* + webroot/imgs.php + webroot/imgp.php + webroot/imgd.php + webroot/test/* + webroot/js/* + webroot/compare/* + + + + + + + + + + + + + + diff --git a/test/CImage_RemoteDownloadTest.php b/test/CImageRemoteDownloadTest.php similarity index 97% rename from test/CImage_RemoteDownloadTest.php rename to test/CImageRemoteDownloadTest.php index 86ffee5..6d2dc9d 100644 --- a/test/CImage_RemoteDownloadTest.php +++ b/test/CImageRemoteDownloadTest.php @@ -1,9 +1,9 @@