From 7b0c75818166d4b9723c100486be5d6692f64faa Mon Sep 17 00:00:00 2001 From: Vincent Garnier Date: Fri, 22 Aug 2014 19:31:43 +0200 Subject: [PATCH] PHP 5.4 we now use at least PHP 5.4 because PHP 5.3 reached its end of life --- .gitignore | 5 +---- composer.json | 2 +- src/Gravatar.php | 29 ++++++++++---------------- src/Image.php | 53 ++++++++++++++++++++++++++++++++---------------- src/Profile.php | 17 +++++++++++----- 5 files changed, 61 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 10be2b4..57872d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -/.settings -/.buildpath -/.project -/vendor/ \ No newline at end of file +/vendor/ diff --git a/composer.json b/composer.json index 1cacdce..399887e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require" : { - "php" : ">=5.3.0" + "php" : ">=5.4.0" }, "autoload" : { "psr-4" : { diff --git a/src/Gravatar.php b/src/Gravatar.php index d3d2a17..3524273 100644 --- a/src/Gravatar.php +++ b/src/Gravatar.php @@ -28,9 +28,7 @@ class Gravatar */ public static function image($sEmail, $iSize = null, $sDefaultImage = null, $sRating = null, $sExtension = null, $bSecure = false) { - $gravatarImage = new GravatarImage(); - - $gravatarImage + $gravatarImage = (new GravatarImage()) ->setSize($iSize) ->setDefaultImage($sDefaultImage) ->setMaxRating($sRating) @@ -56,19 +54,17 @@ public static function image($sEmail, $iSize = null, $sDefaultImage = null, $sRa */ public static function images(array $aEmail, $iSize = null, $sDefaultImage = null, $sRating = null, $sExtension = null, $bSecure = false) { - $gravatarImage = new GravatarImage(); - - $gravatarImage + $gravatarImage = (new GravatarImage()) ->setSize($iSize) ->setDefaultImage($sDefaultImage) ->setMaxRating($sRating) ->setExtension($sExtension); if ($bSecure) { - $gravatarImages->enableSecure(); + $gravatarImage->enableSecure(); } - $aUrls = array(); + $aUrls = []; foreach ($aEmail as $sEmail) { $aUrls[$sEmail] = $gravatarImage->getUrl($sEmail); @@ -86,11 +82,9 @@ public static function images(array $aEmail, $iSize = null, $sDefaultImage = nul */ public static function profile($sEmail, $sFormat = null) { - $gravatarProfile = new GravatarProfile(); - - $gravatarProfile->setFormat($sFormat); - - return $gravatarProfile->getUrl($sEmail); + return (new GravatarProfile()) + ->setFormat($sFormat) + ->getUrl($sEmail); } /** @@ -102,11 +96,10 @@ public static function profile($sEmail, $sFormat = null) */ public static function profiles(array $aEmail, $sFormat = null) { - $gravatarProfil = new GravatarProfile(); - - $gravatarProfil->setFormat($sFormat); + $gravatarProfil = (new GravatarProfile()) + ->setFormat($sFormat); - $aUrls = array(); + $aUrls = []; foreach ($aEmail as $sEmail) { $aUrls[$sEmail] = $gravatarProfil->getUrl($sEmail); @@ -121,7 +114,7 @@ public static function profiles(array $aEmail, $sFormat = null) * @param string $sEmail The email to get the hash for * @return string The hashed form of the email */ - protected function getHash($sEmail) + protected static function getHash($sEmail) { return md5(strtolower(trim($sEmail))); } diff --git a/src/Image.php b/src/Image.php index 04d4d73..033cf3c 100644 --- a/src/Image.php +++ b/src/Image.php @@ -28,7 +28,7 @@ class Image extends Gravatar /** * @var array List of accepted gravatar recognized default image "type". */ - protected $aValidDefaultsImages = array('404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); + protected $aValidDefaultsImages = ['404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank']; /** * @var string The maximum rating to allow for the avatars. @@ -38,7 +38,7 @@ class Image extends Gravatar /** * @var array List of accepted ratings. */ - protected $aValidRatings = array('g', 'pg', 'r', 'x'); + protected $aValidRatings = ['g', 'pg', 'r', 'x']; /** * @var string The extension to append to the avatars URL. @@ -48,10 +48,10 @@ class Image extends Gravatar /** * @var array List of accepted extensions. */ - protected $aValidExtensions = array('jpg', 'jpeg', 'gif', 'png'); + protected $aValidExtensions = ['jpg', 'jpeg', 'gif', 'png']; /** - * @var boolean Should we use the secure (HTTPS) URL base? + * @var boolean Should we use the secure (HTTPS) URL base? */ protected $bUseSecureUrl = false; @@ -64,7 +64,7 @@ class Image extends Gravatar * Build the avatar URL based on the provided email address. * * @param string $sEmail The email to get the gravatar for. - * @return string The URL to the gravatar. + * @return string The URL to the gravatar. */ public function getUrl($sEmail) { @@ -72,11 +72,10 @@ public function getUrl($sEmail) $this->sParamsCache = $this->getParams(); } - return - ($this->usingSecure() ? self::SECURE_URL : self::URL) - .'avatar/' - .$this->getHash($sEmail) - .$this->sParamsCache; + return ($this->usingSecure() ? static::SECURE_URL : static::URL) + . 'avatar/' + . static::getHash($sEmail) + . $this->sParamsCache; } /** @@ -154,7 +153,13 @@ public function setDefaultImage($sDefaultImage = null) return $this; } - throw new InvalidArgumentException(sprintf('The default image "%s" is not a recognized gravatar "default" and is not a valid URL, default gravatar can be: %s', $sDefaultImage, implode(', ', $this->aValidDefaultsImages))); + throw new InvalidArgumentException( + sprintf( + 'The default image "%s" is not a recognized gravatar "default" and is not a valid URL, default gravatar can be: %s', + $sDefaultImage, + implode(', ', $this->aValidDefaultsImages) + ) + ); } /** @@ -184,8 +189,15 @@ public function setMaxRating($sRating = null) $sRating = strtolower($sRating); - if (!in_array($sRating, $this->aValidRatings)) { - throw new InvalidArgumentException(sprintf('Invalid rating "%s" specified, only allowed to be used are: %s', $sRating, implode(', ', $this->aValidRatings))); + if (!in_array($sRating, $this->aValidRatings)) + { + throw new InvalidArgumentException( + sprintf( + 'Invalid rating "%s" specified, only allowed to be used are: %s', + $sRating, + implode(', ', $this->aValidRatings) + ) + ); } $this->sMaxRating = $sRating; @@ -218,8 +230,15 @@ public function setExtension($sExtension = null) $this->sParamsCache = null; - if (!in_array($sExtension, $this->aValidExtensions)) { - throw new InvalidArgumentException(sprintf('The extension "%s" is not a valid one, extension image for Gravatar can be: %s', $sExtension, implode(', ', $this->aValidExtensions))); + if (!in_array($sExtension, $this->aValidExtensions)) + { + throw new InvalidArgumentException( + sprintf( + 'The extension "%s" is not a valid one, extension image for Gravatar can be: %s', + $sExtension, + implode(', ', $this->aValidExtensions) + ) + ); } $this->sExtension = $sExtension; @@ -268,7 +287,7 @@ public function disableSecure() */ protected function getParams() { - $aParams = array(); + $aParams = []; if (null !== $this->getSize()) { $aParams['s'] = $this->getSize(); @@ -283,6 +302,6 @@ protected function getParams() } return (null !== $this->sExtension ? '.'.$this->sExtension : '') - .(!empty($aParams) ? '?'.http_build_query($aParams, '', '&') : ''); + .(!empty($aParams) ? '?' . http_build_query($aParams, '', '&') : ''); } } diff --git a/src/Profile.php b/src/Profile.php index 0a2f3df..7e5535d 100644 --- a/src/Profile.php +++ b/src/Profile.php @@ -20,7 +20,7 @@ class Profile extends Gravatar /** * @var array List of accepted format. */ - protected $aValidFormats = array('json', 'xml', 'php', 'vcf', 'qr'); + protected $aValidFormats = ['json', 'xml', 'php', 'vcf', 'qr']; /** * Build the profile URL based on the provided email address. @@ -30,8 +30,8 @@ class Profile extends Gravatar */ public function getUrl($sEmail) { - return self::URL.$this->getHash($sEmail) - .(null !== $this->sFormat ? '.'.$this->sFormat : null); + return static::URL . static::getHash($sEmail) + . (null !== $this->sFormat ? '.' . $this->sFormat : null); } /** @@ -76,8 +76,15 @@ public function setFormat($sFormat = null) return $this; } - if (!in_array($sFormat, $this->aValidFormats)) { - throw new InvalidArgumentException(sprintf('The format "%s" is not a valid one, profile format for Gravatar can be: %s', $sFormat, implode(', ', $this->aValidFormats))); + if (!in_array($sFormat, $this->aValidFormats)) + { + throw new InvalidArgumentException( + sprintf( + 'The format "%s" is not a valid one, profile format for Gravatar can be: %s', + $sFormat, + implode(', ', $this->aValidFormats) + ) + ); } $this->sFormat = $sFormat;