From 5e195281944641b872bff321199b66b0d48c21e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Thu, 21 Apr 2016 23:04:31 +0200 Subject: [PATCH] Convert to short arrays --- src/Kdyby/Validator/DI/ValidatorExtension.php | 44 +++++++++---------- tests/KdybyTests/Validator/Extension.phpt | 14 +++--- tests/KdybyTests/bootstrap.php | 6 +-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Kdyby/Validator/DI/ValidatorExtension.php b/src/Kdyby/Validator/DI/ValidatorExtension.php index 7adc041..db13f21 100644 --- a/src/Kdyby/Validator/DI/ValidatorExtension.php +++ b/src/Kdyby/Validator/DI/ValidatorExtension.php @@ -33,12 +33,12 @@ class ValidatorExtension extends Nette\DI\CompilerExtension implements ITranslat /** * @var array */ - public $defaults = array( + public $defaults = [ 'cache' => 'default', 'translationDomain' => NULL, 'debug' => '%debugMode%', 'strictEmail' => FALSE, - ); + ]; @@ -62,9 +62,9 @@ public function loadConfiguration() if (class_exists($cacheFactory[0]->entity) && in_array('Symfony\Component\Validator\Mapping\Cache\CacheInterface', class_implements($cacheFactory[0]->entity), TRUE)) { $cacheService->setFactory($cacheFactory[0]->entity, $cacheFactory[0]->arguments); } else { - $cacheService->setFactory('Symfony\Component\Validator\Mapping\Cache\DoctrineCache', array( + $cacheService->setFactory('Symfony\Component\Validator\Mapping\Cache\DoctrineCache', [ Helpers::processCache($this, $config['cache'], 'validator', $config['debug']), - )); + ]); } $builder->addDefinition($this->prefix('metadataFactory')) @@ -78,7 +78,7 @@ public function loadConfiguration() $builder->addDefinition($this->prefix('contextFactory')) ->setClass('Symfony\Component\Validator\Context\ExecutionContextFactoryInterface') - ->setFactory('Symfony\Component\Validator\Context\ExecutionContextFactory', array('translationDomain' => $config['translationDomain'])); + ->setFactory('Symfony\Component\Validator\Context\ExecutionContextFactory', ['translationDomain' => $config['translationDomain']]); $builder->addDefinition($this->prefix('validator')) ->setClass('Symfony\Component\Validator\Validator\ValidatorInterface') @@ -88,19 +88,19 @@ public function loadConfiguration() $builder->addDefinition($this->prefix('constraint.email')) ->setClass('Symfony\Component\Validator\Constraints\EmailValidator') - ->setArguments(array( + ->setArguments([ 'strict' => $config['strictEmail'], - )) - ->addTag(self::TAG_CONSTRAINT_VALIDATOR, array( + ]) + ->addTag(self::TAG_CONSTRAINT_VALIDATOR, [ 'Symfony\Component\Validator\Constraints\EmailValidator', - )); + ]); $builder->addDefinition($this->prefix('constraint.expression')) ->setClass('Symfony\Component\Validator\Constraints\ExpressionValidator') - ->addTag(self::TAG_CONSTRAINT_VALIDATOR, array( + ->addTag(self::TAG_CONSTRAINT_VALIDATOR, [ 'Symfony\Component\Validator\Constraints\ExpressionValidator', 'validator.expression', // @link https://github.com/symfony/symfony/pull/16166 - )); + ]); } @@ -109,35 +109,35 @@ public function beforeCompile() { $builder = $this->getContainerBuilder(); - $loaders = array(); + $loaders = []; foreach (array_keys($builder->findByTag(self::TAG_LOADER)) as $service) { $builder->getDefinition($service) ->setAutowired(FALSE); $loaders[] = '@' . $service; } $builder->getDefinition($this->prefix('loader')) - ->setArguments(array($loaders)); + ->setArguments([$loaders]); - $initializers = array(); + $initializers = []; foreach (array_keys($builder->findByTag(self::TAG_INITIALIZER)) as $service) { $initializers[] = '@' . $service; } $builder->getDefinition($this->prefix('validator')) - ->setArguments(array( + ->setArguments([ 'metadataFactory' => $this->prefix('@metadataFactory'), 'objectInitializers' => $initializers, - )); + ]); - $validators = array(); + $validators = []; foreach ($builder->findByTag(self::TAG_CONSTRAINT_VALIDATOR) as $service => $attributes) { foreach ((array) $attributes as $name) { $validators[$name] = (string) $service; } } $builder->getDefinition($this->prefix('constraintValidatorFactory')) - ->setArguments(array( + ->setArguments([ 'validators' => $validators, - )); + ]); } @@ -151,9 +151,9 @@ public function getTranslationResources() { $validatorClass = new \ReflectionClass('Symfony\Component\Validator\Constraint'); - return array( + return [ dirname($validatorClass->getFileName()) . '/Resources/translations', - ); + ]; } @@ -164,7 +164,7 @@ public function getTranslationResources() */ private static function filterArgs($statement) { - return Compiler::filterArguments(array(is_string($statement) ? new Nette\DI\Statement($statement) : $statement)); + return Compiler::filterArguments([is_string($statement) ? new Nette\DI\Statement($statement) : $statement]); } diff --git a/tests/KdybyTests/Validator/Extension.phpt b/tests/KdybyTests/Validator/Extension.phpt index c56865d..23a94b7 100644 --- a/tests/KdybyTests/Validator/Extension.phpt +++ b/tests/KdybyTests/Validator/Extension.phpt @@ -34,7 +34,7 @@ class ExtensionTest extends Tester\TestCase { $config = new Nette\Configurator(); $config->setTempDirectory(TEMP_DIR); - $config->addParameters(array('container' => array('class' => 'SystemContainer_' . md5($configFile)))); + $config->addParameters(['container' => ['class' => 'SystemContainer_' . md5($configFile)]]); $config->addConfig(__DIR__ . '/../nette-reset.neon', !isset($config->defaultExtensions['nette']) ? 'v23' : 'v22'); if ($configFile) { $config->addConfig(__DIR__ . '/config/' . $configFile . '.neon', FALSE); @@ -79,7 +79,7 @@ class ExtensionTest extends Tester\TestCase Tester\Assert::type('Symfony\Component\Validator\Constraints\BlankValidator', $factory->getInstance(new \Symfony\Component\Validator\Constraints\Blank())); // ExpressionValidator (requires a special fix). - Tester\Assert::type('Symfony\Component\Validator\Constraints\ExpressionValidator', $factory->getInstance(new \Symfony\Component\Validator\Constraints\Expression(array('expression' => '')))); + Tester\Assert::type('Symfony\Component\Validator\Constraints\ExpressionValidator', $factory->getInstance(new \Symfony\Component\Validator\Constraints\Expression(['expression' => '']))); // Custom validator with dependency (haa to be created by DIC). Tester\Assert::type('KdybyTests\ValidatorMock\FooConstraintValidator', $factory->getInstance(new \KdybyTests\ValidatorMock\FooConstraint())); @@ -89,11 +89,11 @@ class ExtensionTest extends Tester\TestCase public function strictEmailDataProvider() { - return array( - array(NULL, FALSE), - array('strict-email', TRUE), - array('non-strict-email', FALSE), - ); + return [ + [NULL, FALSE], + ['strict-email', TRUE], + ['non-strict-email', FALSE], + ]; } diff --git a/tests/KdybyTests/bootstrap.php b/tests/KdybyTests/bootstrap.php index da44429..6b8a641 100755 --- a/tests/KdybyTests/bootstrap.php +++ b/tests/KdybyTests/bootstrap.php @@ -23,10 +23,10 @@ class_alias('Tester\Assert', 'Assert'); Tester\Helpers::purge(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) { return $val;