Skip to content

Commit

Permalink
Convert to short arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Apr 21, 2016
1 parent fc92760 commit 5e19528
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
44 changes: 22 additions & 22 deletions src/Kdyby/Validator/DI/ValidatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
];



Expand All @@ -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'))
Expand All @@ -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')
Expand All @@ -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
));
]);
}


Expand All @@ -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,
));
]);
}


Expand All @@ -151,9 +151,9 @@ public function getTranslationResources()
{
$validatorClass = new \ReflectionClass('Symfony\Component\Validator\Constraint');

return array(
return [
dirname($validatorClass->getFileName()) . '/Resources/translations',
);
];
}


Expand All @@ -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]);
}


Expand Down
14 changes: 7 additions & 7 deletions tests/KdybyTests/Validator/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
Expand All @@ -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],
];
}


Expand Down
6 changes: 3 additions & 3 deletions tests/KdybyTests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5e19528

Please sign in to comment.