Skip to content

Commit

Permalink
PHP 5.4
Browse files Browse the repository at this point in the history
we now use at least PHP 5.4 because PHP 5.3 reached its end of life
  • Loading branch information
forxer committed Aug 22, 2014
1 parent e8c1214 commit 7b0c758
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 45 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/.settings
/.buildpath
/.project
/vendor/
/vendor/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require" : {
"php" : ">=5.3.0"
"php" : ">=5.4.0"
},
"autoload" : {
"psr-4" : {
Expand Down
29 changes: 11 additions & 18 deletions src/Gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);
}

/**
Expand All @@ -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);
Expand All @@ -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)));
}
Expand Down
53 changes: 36 additions & 17 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -64,19 +64,18 @@ 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)
{
if (null === $this->sParamsCache) {
$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;
}

/**
Expand Down Expand Up @@ -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)
)
);
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -268,7 +287,7 @@ public function disableSecure()
*/
protected function getParams()
{
$aParams = array();
$aParams = [];

if (null !== $this->getSize()) {
$aParams['s'] = $this->getSize();
Expand All @@ -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, '', '&') : '');
}
}
17 changes: 12 additions & 5 deletions src/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7b0c758

Please sign in to comment.