Skip to content

Commit

Permalink
- Just small code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Mar 17, 2018
1 parent ca24d5f commit 9c5b2fb
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.composer.php
Expand Up @@ -10,7 +10,7 @@

$file = __DIR__ . '/composer.json';
$content = file_get_contents($file);
$composer = json_decode($content, TRUE);
$composer = json_decode($content, TRUE);

$composer['require']['nette/application'] = $version;
$composer['require']['nette/di'] = $version;
Expand Down
1 change: 0 additions & 1 deletion src/IPub/Gravatar/Application/GravatarResponse.php
Expand Up @@ -20,7 +20,6 @@
use Nette\Utils;
use Nette\Http;

use IPub;
use IPub\Gravatar;
use IPub\Gravatar\Exceptions;

Expand Down
1 change: 0 additions & 1 deletion src/IPub/Gravatar/Caching/Cache.php
Expand Up @@ -16,7 +16,6 @@

namespace IPub\Gravatar\Caching;

use Nette;
use Nette\Caching;

/**
Expand Down
9 changes: 4 additions & 5 deletions src/IPub/Gravatar/DI/GravatarExtension.php
Expand Up @@ -21,7 +21,6 @@
use Nette\DI;
use Nette\PhpGenerator as Code;

use IPub;
use IPub\Gravatar;
use IPub\Gravatar\Caching;
use IPub\Gravatar\Templating;
Expand Down Expand Up @@ -57,19 +56,19 @@ public function loadConfiguration() : void

// Install Gravatar service
$builder->addDefinition($this->prefix('gravatar'))
->setClass(Gravatar\Gravatar::class)
->setType(Gravatar\Gravatar::class)
->addSetup('setSize', [$configuration['size']])
->addSetup('setExpiration', [$configuration['expiration']])
->addSetup('setDefaultImage', [$configuration['defaultImage']]);

// Create cache services
$builder->addDefinition($this->prefix('cache'))
->setClass(Caching\Cache::class, ['@cacheStorage', 'IPub.Gravatar'])
->setType(Caching\Cache::class, ['@cacheStorage', 'IPub.Gravatar'])
->setInject(FALSE);

// Register template helpers
$builder->addDefinition($this->prefix('helpers'))
->setClass(Templating\Helpers::class)
->setType(Templating\Helpers::class)
->setFactory($this->prefix('@gravatar') . '::createTemplateHelpers')
->setInject(FALSE);
}
Expand Down Expand Up @@ -99,7 +98,7 @@ public function beforeCompile() : void
*
* @return void
*/
public static function register(Nette\Configurator $config, string $extensionName = 'gravatar')
public static function register(Nette\Configurator $config, string $extensionName = 'gravatar') : void
{
$config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) : void {
$compiler->addExtension($extensionName, new GravatarExtension());
Expand Down
4 changes: 1 addition & 3 deletions src/IPub/Gravatar/Exceptions/InvalidStateException.php
Expand Up @@ -16,8 +16,6 @@

namespace IPub\Gravatar\Exceptions;

use Nette;

class InvalidStateException extends Nette\InvalidStateException implements IException
class InvalidStateException extends \RuntimeException implements IException
{
}
17 changes: 8 additions & 9 deletions src/IPub/Gravatar/Gravatar.php
Expand Up @@ -20,7 +20,6 @@
use Nette\Http;
use Nette\Utils;

use IPub;
use IPub\Gravatar\Caching;
use IPub\Gravatar\Exceptions;
use IPub\Gravatar\Templating;
Expand All @@ -43,8 +42,8 @@ final class Gravatar
/**
* @var string - URL constants for the avatar images
*/
const HTTP_URL = 'http://www.gravatar.com/avatar/';
const HTTPS_URL = 'https://secure.gravatar.com/avatar/';
public const HTTP_URL = 'http://www.gravatar.com/avatar/';
public const HTTPS_URL = 'https://secure.gravatar.com/avatar/';

/**
* @var int
Expand Down Expand Up @@ -121,7 +120,7 @@ public function __construct(
*
* @return string - The hashed form of the email, post cleaning
*/
public function getEmailHash(string $email = NULL) : string
public function getEmailHash(?string $email = NULL) : string
{
// Tack the email hash onto the end.
if ($this->hashEmail === TRUE && $email !== NULL) {
Expand Down Expand Up @@ -229,7 +228,7 @@ public function setDefaultImage($image) : void
*
* @return mixed - False if no default image set, string if one is set
*/
public function getDefaultImage(string $defaultImage = NULL) : ?string
public function getDefaultImage(?string $defaultImage = NULL) : ?string
{
if ($defaultImage !== NULL && in_array($defaultImage, ['404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'])) {
return $defaultImage;
Expand Down Expand Up @@ -269,7 +268,7 @@ public function setMaxRating(string $rating) : void
*
* @return string - The string representing the current maximum allowed rating ('g', 'pg', 'r', 'x').
*/
public function getMaxRating(string $maxRating = NULL) : string
public function getMaxRating(?string $maxRating = NULL) : string
{
if ($maxRating !== NULL && in_array($maxRating, ['g', 'pg', 'r', 'x'])) {
return $maxRating;
Expand Down Expand Up @@ -338,7 +337,7 @@ public function disableSecureImages() : void
*
* @throws Exceptions\InvalidArgumentException
*/
public function get(string $email = NULL, int $size = NULL) : Utils\Image
public function get(?string $email = NULL, ?int $size = NULL) : Utils\Image
{
// Set user email address
if ($email !== NULL && !Utils\Validators::isEmail($email)) {
Expand Down Expand Up @@ -378,7 +377,7 @@ public function get(string $email = NULL, int $size = NULL) : Utils\Image
*
* @throws Exceptions\InvalidArgumentException
*/
public function buildUrl(string $email = NULL, int $size = NULL, string $maxRating = NULL, string $defaultImage = NULL) : string
public function buildUrl(?string $email = NULL, ?int $size = NULL, ?string $maxRating = NULL, ?string $defaultImage = NULL) : string
{
// Set user email address
if ($email !== NULL && !Utils\Validators::isEmail($email)) {
Expand Down Expand Up @@ -431,7 +430,7 @@ public function createTemplateHelpers() : Templating\Helpers
*
* @return Http\Url
*/
private function createUrl(string $email, int $size = NULL, string $maxRating = NULL, string $defaultImage = NULL) : Http\Url
private function createUrl(string $email, ?int $size = NULL, ?string $maxRating = NULL, ?string $defaultImage = NULL) : Http\Url
{
// Tack the email hash onto the end.
$emailHash = $this->getEmailHash($email);
Expand Down
2 changes: 1 addition & 1 deletion src/IPub/Gravatar/Templating/Helpers.php
Expand Up @@ -56,7 +56,7 @@ public function __construct(Gravatar\Gravatar $gravatar)
*
* @return string
*/
public function gravatar(string $email, int $size = NULL) : string
public function gravatar(string $email, ?int $size = NULL) : string
{
return $this->gravatar
->buildUrl($email, $size);
Expand Down
3 changes: 1 addition & 2 deletions tests/IPubTests/Gravatar/ExtensionTest.phpt
Expand Up @@ -22,14 +22,13 @@ use Nette;
use Tester;
use Tester\Assert;

use IPub;
use IPub\Gravatar;

require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php';

class ExtensionTest extends Tester\TestCase
{
public function testFunctional()
public function testFunctional() : void
{
$dic = $this->createContainer();

Expand Down
11 changes: 5 additions & 6 deletions tests/IPubTests/Gravatar/GravatarTest.phpt
Expand Up @@ -22,7 +22,6 @@ use Nette;
use Tester;
use Tester\Assert;

use IPub;
use IPub\Gravatar;

require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php';
Expand All @@ -37,7 +36,7 @@ class GravatarTest extends Tester\TestCase
/**
* {@inheritdoc}
*/
public function setUp()
public function setUp() : void
{
parent::setUp();

Expand All @@ -47,19 +46,19 @@ class GravatarTest extends Tester\TestCase
$this->gravatar = $dic->getService('gravatar.gravatar');
}

public function testGravatarUrlWithDefaultOptions()
public function testGravatarUrlWithDefaultOptions() : void
{
Assert::equal('http://www.gravatar.com/avatar/aabfda88704a1ab55db46d4116442222?s=80&r=g&d=mm', $this->gravatar->buildUrl('john.doe@ipublikuj.eu'));
}

public function testGravatarSecureUrlWithDefaultOptions()
public function testGravatarSecureUrlWithDefaultOptions() : void
{
$this->gravatar->enableSecureImages();

Assert::equal('https://secure.gravatar.com/avatar/aabfda88704a1ab55db46d4116442222?s=80&r=g&d=mm', $this->gravatar->buildUrl('john.doe@ipublikuj.eu', NULL));
}

public function testGravatarInitializedWithOptions()
public function testGravatarInitializedWithOptions() : void
{
$this->gravatar->setSize(20);
$this->gravatar->setMaxRating('g');
Expand All @@ -68,7 +67,7 @@ class GravatarTest extends Tester\TestCase
Assert::equal('http://www.gravatar.com/avatar/aabfda88704a1ab55db46d4116442222?s=20&r=g&d=mm', $this->gravatar->buildUrl('john.doe@ipublikuj.eu'));
}

public function testGravatarExists()
public function testGravatarExists() : void
{
Assert::false($this->gravatar->exists('fake.email@ipublikuj.eu'));
Assert::true($this->gravatar->exists('adam.kadlec@gmail.com'));
Expand Down
7 changes: 3 additions & 4 deletions tests/IPubTests/Gravatar/TemplateTest.phpt
Expand Up @@ -26,7 +26,6 @@ use Nette\Utils;
use Tester;
use Tester\Assert;

use IPub;
use IPub\Gravatar;

require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php';
Expand All @@ -52,7 +51,7 @@ class TemplateTest extends Tester\TestCase
/**
* {@inheritdoc}
*/
public function setUp()
public function setUp() : void
{
parent::setUp();

Expand All @@ -65,7 +64,7 @@ class TemplateTest extends Tester\TestCase
$this->gravatar = $this->container->getByType(Gravatar\Gravatar::class);
}

public function testMobileVersion()
public function testMacroVersion() : void
{
// Create test presenter
$presenter = $this->createPresenter();
Expand Down Expand Up @@ -128,7 +127,7 @@ class TestPresenter extends UI\Presenter
{
use Gravatar\TGravatar;

public function renderDefault()
public function renderDefault() : void
{
// Set template for component testing
$this->template->setFile(__DIR__ . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'default.latte');
Expand Down
7 changes: 4 additions & 3 deletions tests/IPubTests/bootstrap.php
Expand Up @@ -19,10 +19,11 @@
Tester\Helpers::purge(TEMP_DIR);
\Tracy\Debugger::$logDirectory = TEMP_DIR;

$_SERVER = array_intersect_key($_SERVER, array_flip(array(
'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv')));
$_SERVER = array_intersect_key($_SERVER, array_flip([
'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv'
]));
$_SERVER['REQUEST_TIME'] = 1234567890;
$_ENV = $_GET = $_POST = array();
$_ENV = $_GET = $_POST = [];

function id($val)
{
Expand Down

0 comments on commit 9c5b2fb

Please sign in to comment.