Skip to content

Commit

Permalink
Add strict types declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMasterov committed Jan 7, 2017
1 parent 1af8145 commit 21e66c0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 54 deletions.
25 changes: 4 additions & 21 deletions src/Configuration/TwigConfiguration.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace AlexMasterov\EquipTwig\Configuration;

Expand All @@ -16,9 +17,6 @@ final class TwigConfiguration implements ConfigurationInterface

const PREFIX = 'TWIG_';

/**
* @param Injector $injector
*/
public function apply(Injector $injector)
{
$env = $this->env;
Expand All @@ -36,24 +34,14 @@ public function apply(Injector $injector)
]);
}

/**
* @param Env $env
*
* @return array
*/
private function fileExtensions(Env $env)
private function fileExtensions(Env $env): array
{
$fileExtensions = $env->getValue('TWIG_FILE_EXTENSIONS', 'html.twig,twig');

return explode(',', $fileExtensions);
}

/**
* @param Env $env
*
* @return array
*/
private function options(Env $env)
private function options(Env $env): array
{
static $options = [
'debug' => false,
Expand All @@ -76,12 +64,7 @@ private function options(Env $env)
return $options;
}

/**
* @param Env $env
*
* @return array
*/
private function envTwig(Env $env)
private function envTwig(Env $env): array
{
$twigFilter = static function ($value) {
return stristr($value, self::PREFIX);
Expand Down
10 changes: 1 addition & 9 deletions src/Configuration/TwigExtensionSet.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace AlexMasterov\EquipTwig\Configuration;

Expand All @@ -12,20 +13,11 @@

class TwigExtensionSet extends Set implements ConfigurationInterface
{
/**
* @param Injector $injector
*/
public function apply(Injector $injector)
{
$injector->prepare(Twig_Environment::class, [$this, 'prepareExtension']);
}

/**
* @param Twig_Environment $environment
* @param Injector $injector
*
* @return void
*/
public function prepareExtension(
Twig_Environment $environment,
Injector $injector
Expand Down
5 changes: 4 additions & 1 deletion src/Exception/ExceptionInterface.php
@@ -1,7 +1,10 @@
<?php
declare(strict_types=1);

namespace AlexMasterov\EquipTwig\Exception;

interface ExceptionInterface
use Throwable;

interface ExceptionInterface extends Throwable
{
}
5 changes: 2 additions & 3 deletions src/Exception/ExtensionException.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace AlexMasterov\EquipTwig\Exception;

Expand All @@ -10,10 +11,8 @@ class ExtensionException extends InvalidArgumentException implements ExceptionIn
{
/**
* @param string|object $spec
*
* @return static
*/
public static function invalidClass($spec)
public static function invalidClass($spec): self
{
if (is_object($spec)) {
$spec = get_class($spec);
Expand Down
9 changes: 2 additions & 7 deletions src/Exception/LoaderException.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace AlexMasterov\EquipTwig\Exception;

Expand All @@ -7,13 +8,7 @@

class LoaderException extends Twig_Error_Loader implements ExceptionInterface
{
/**
* @param string $name The template name
* @param string $where The template directory path
*
* @return static
*/
public static function notFound($name, $where)
public static function notFound(string $name, string $where): self
{
return new static(sprintf(
'Unable to find template `%s` (looked into: %s).',
Expand Down
18 changes: 8 additions & 10 deletions src/Loader/FilesystemLoader.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace AlexMasterov\EquipTwig\Loader;

Expand All @@ -16,23 +17,20 @@ final class FilesystemLoader implements Twig_LoaderInterface
/**
* @var array
*/
private $fileExtensions = [];
private $fileExtensions = ['html.twig', 'twig'];

/**
* @var array
*/
private $cache = [];

/**
* @param string $path The template directory path
* @param array $fileExtensions The template file extensions
*/
public function __construct(
$path,
array $fileExtensions = ['html.twig', 'twig']
) {
public function __construct(string $path, array $fileExtensions = null)
{
$this->path = $path;
$this->fileExtensions = $fileExtensions;

if ($fileExtensions) {
$this->fileExtensions = $fileExtensions;
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/TwigFormatter.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace AlexMasterov\EquipTwig;

Expand All @@ -17,9 +18,6 @@ final class TwigFormatter extends HtmlFormatter
*/
private $template;

/**
* @param Twig_Environment $environment
*/
public function __construct(Twig_Environment $environment)
{
$this->environment = $environment;
Expand Down

0 comments on commit 21e66c0

Please sign in to comment.