Skip to content

Commit

Permalink
convert short arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Jul 7, 2016
1 parent 3c0f4b0 commit 0688481
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
12 changes: 6 additions & 6 deletions src/Kdyby/Autowired/AutowireComponentFactories.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function injectComponentFactories(Nette\DI\Container $dic)
return;
}

$ignore = class_parents('Nette\Application\UI\Presenter') + array('ui' => 'Nette\Application\UI\Presenter');
$ignore = class_parents('Nette\Application\UI\Presenter') + ['ui' => 'Nette\Application\UI\Presenter'];
$rc = new ClassType($this);
foreach ($rc->getMethods() as $method) {
if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) {
Expand All @@ -90,13 +90,13 @@ public function injectComponentFactories(Nette\DI\Container $dic)

$files = array_map(function ($class) {
return ClassType::from($class)->getFileName();
}, array_diff(array_values(class_parents($presenterClass) + array('me' => $presenterClass)), $ignore));
}, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));

$files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName();

$cache->save($presenterClass, TRUE, array(
$cache->save($presenterClass, TRUE, [
$cache::FILES => $files,
));
]);
}


Expand Down Expand Up @@ -140,13 +140,13 @@ protected function createComponent($name)
}
$parameters = $methodReflection->getParameters();

$args = array();
$args = [];
if (($first = reset($parameters)) && !$first->className) {
$args[] = $name;
}

$args = Nette\DI\Helpers::autowireArguments($methodReflection, $args, $sl);
$component = call_user_func_array(array($this, $method), $args);
$component = call_user_func_array([$this, $method], $args);
if (!$component instanceof Nette\ComponentModel\IComponent && !isset($this->components[$name])) {
throw new Nette\UnexpectedValueException("Method $methodReflection did not return or create the desired component.");
}
Expand Down
20 changes: 10 additions & 10 deletions src/Kdyby/Autowired/AutowireProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait AutowireProperties
/**
* @var array
*/
private $autowireProperties = array();
private $autowireProperties = [];

/**
* @var Nette\DI\Container
Expand Down Expand Up @@ -58,7 +58,7 @@ public function injectProperties(Nette\DI\Container $dic)
$cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireProperties');

$containerFileName = ClassType::from($this->autowirePropertiesLocator)->getFileName();
$cacheKey = array($presenterClass = get_class($this), $containerFileName);
$cacheKey = [$presenterClass = get_class($this), $containerFileName];

if (is_array($this->autowireProperties = $cache->load($cacheKey))) {
foreach ($this->autowireProperties as $propName => $tmp) {
Expand All @@ -68,9 +68,9 @@ public function injectProperties(Nette\DI\Container $dic)
return;
}

$this->autowireProperties = array();
$this->autowireProperties = [];

$ignore = class_parents('Nette\Application\UI\Presenter') + array('ui' => 'Nette\Application\UI\Presenter');
$ignore = class_parents('Nette\Application\UI\Presenter') + ['ui' => 'Nette\Application\UI\Presenter'];
$rc = new ClassType($this);
foreach ($rc->getProperties() as $prop) {
if (!$this->validateProperty($prop, $ignore)) {
Expand All @@ -82,13 +82,13 @@ public function injectProperties(Nette\DI\Container $dic)

$files = array_map(function ($class) {
return ClassType::from($class)->getFileName();
}, array_diff(array_values(class_parents($presenterClass) + array('me' => $presenterClass)), $ignore));
}, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));

$files[] = $containerFileName;

$cache->save($cacheKey, $this->autowireProperties, array(
$cache->save($cacheKey, $this->autowireProperties, [
$cache::FILES => $files,
));
]);
}


Expand All @@ -100,7 +100,7 @@ private function validateProperty(Property $property, array $ignore)
}

foreach ($property->getAnnotations() as $name => $value) {
if (!in_array(Strings::lower($name), array('autowire', 'autowired'), TRUE)) {
if (!in_array(Strings::lower($name), ['autowire', 'autowired'], TRUE)) {
continue;
}

Expand Down Expand Up @@ -149,10 +149,10 @@ private function findByTypeForProperty($type)
private function resolveProperty(Property $prop)
{
$type = $this->resolveAnnotationClass($prop, $prop->getAnnotation('var'), 'var');
$metadata = array(
$metadata = [
'value' => NULL,
'type' => $type,
);
];

if (($args = (array) $prop->getAnnotation('autowire')) && !empty($args['factory'])) {
$factoryType = $this->resolveAnnotationClass($prop, $args['factory'], 'autowire');
Expand Down
4 changes: 2 additions & 2 deletions src/Kdyby/Autowired/DI/AutowiredExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
class AutowiredExtension extends Nette\DI\CompilerExtension
{

public $defaults = array(
public $defaults = [
'cacheStorage' => '@Nette\Caching\IStorage',
);
];


public function loadConfiguration()
Expand Down
6 changes: 3 additions & 3 deletions src/Kdyby/Autowired/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Panel extends Nette\Object

public static function registerBluescreen()
{
Debugger::getBlueScreen()->addPanel(array(get_called_class(), 'renderException'));
Debugger::getBlueScreen()->addPanel([get_called_class(), 'renderException']);
}


Expand All @@ -42,10 +42,10 @@ public static function renderException($e = NULL)
return NULL;
}

return array(
return [
'tab' => 'Autowired',
'panel' => self::highlightException($e),
);
];
}


Expand Down
6 changes: 3 additions & 3 deletions tests/KdybyTests/Autowired/AutowireComponentFactories.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AutowireComponentFactoriesTest extends ContainerTestCase
public function testFunctional()
{
$presenter = new SillyPresenter();
$this->container->callMethod(array($presenter, 'injectComponentFactories'));
$this->container->callMethod([$presenter, 'injectComponentFactories']);

Assert::true($presenter['silly'] instanceof SillyComponent);
Assert::true($presenter['dummy'] instanceof SillyComponent);
Expand All @@ -65,7 +65,7 @@ class AutowireComponentFactoriesTest extends ContainerTestCase

Assert::exception(function () use ($container) {
$presenter = new WithMissingServicePresenter_wcf();
$container->callMethod(array($presenter, 'injectComponentFactories'));
$container->callMethod([$presenter, 'injectComponentFactories']);
}, 'Kdyby\Autowired\MissingServiceException', 'No service of type SampleMissingService12345 found. Make sure the type hint in KdybyTests\Autowired\WithMissingServicePresenter_wcf::createComponentSilly() is written correctly and service of this type is registered.');
}

Expand All @@ -77,7 +77,7 @@ class AutowireComponentFactoriesTest extends ContainerTestCase

Assert::exception(function () use ($container) {
$component = new NonPresenterComponent_AcfProperties();
$container->callMethod(array($component, 'injectComponentFactories'));
$container->callMethod([$component, 'injectComponentFactories']);
}, 'Kdyby\Autowired\MemberAccessException', 'Trait Kdyby\Autowired\AutowireComponentFactories can be used only in descendants of PresenterComponent.');
}

Expand Down
30 changes: 15 additions & 15 deletions tests/KdybyTests/Autowired/AutowireProperties.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class AutowirePropertiesTest extends ContainerTestCase
{
$builder = new DI\ContainerBuilder;
$builder->addDefinition('sampleFactory')
->setFactory('KdybyTests\Autowired\SampleService', array(new PhpLiteral('$name'), new PhpLiteral('$secondName')))
->setParameters(array('name', 'secondName' => NULL))
->setFactory('KdybyTests\Autowired\SampleService', [new PhpLiteral('$name'), new PhpLiteral('$secondName')])
->setParameters(['name', 'secondName' => NULL])
->setImplement('KdybyTests\Autowired\ISampleServiceFactory')
->setAutowired(TRUE);

$builder->addDefinition('sample')
->setClass('KdybyTests\Autowired\SampleService', array('shared'));
->setClass('KdybyTests\Autowired\SampleService', ['shared']);

$builder->addDefinition('importedService')
->setClass('KdybyTests\Autowired\UseExpansion\ImportedService');
Expand All @@ -65,16 +65,16 @@ class AutowirePropertiesTest extends ContainerTestCase
Assert::null($presenter->factoryResult);
Assert::null($presenter->secondFactoryResult);

$this->container->callMethod(array($presenter, 'injectProperties'));
$this->container->callMethod([$presenter, 'injectProperties']);

Assert::true($presenter->service instanceof SampleService);
Assert::same(array('shared'), $presenter->service->args);
Assert::same(['shared'], $presenter->service->args);

Assert::true($presenter->factoryResult instanceof SampleService);
Assert::same(array('string argument', NULL), $presenter->factoryResult->args);
Assert::same(['string argument', NULL], $presenter->factoryResult->args);

Assert::true($presenter->secondFactoryResult instanceof SampleService);
Assert::same(array('string argument', 'and another'), $presenter->secondFactoryResult->args);
Assert::same(['string argument', 'and another'], $presenter->secondFactoryResult->args);
}


Expand All @@ -86,7 +86,7 @@ class AutowirePropertiesTest extends ContainerTestCase
Assert::exception(function () use ($container) {
$presenter = new WithMissingServicePresenter_ap();
Assert::null($presenter->service);
$container->callMethod(array($presenter, 'injectProperties'));
$container->callMethod([$presenter, 'injectProperties']);
}, 'Kdyby\Autowired\MissingClassException', 'Class "SampleMissingService12345" was not found, please check the typehint on KdybyTests\Autowired\WithMissingServicePresenter_ap::$service in annotation @var.');
}

Expand All @@ -99,7 +99,7 @@ class AutowirePropertiesTest extends ContainerTestCase
Assert::exception(function () use ($container) {
$presenter = new WithMissingServiceFactoryPresenter_ap();
Assert::null($presenter->secondFactoryResult);
$container->callMethod(array($presenter, 'injectProperties'));
$container->callMethod([$presenter, 'injectProperties']);
}, 'Kdyby\Autowired\MissingClassException', 'Class "SampleMissingService12345" was not found, please check the typehint on KdybyTests\Autowired\WithMissingServiceFactoryPresenter_ap::$secondFactoryResult in annotation @autowire.');
}

Expand All @@ -111,7 +111,7 @@ class AutowirePropertiesTest extends ContainerTestCase

Assert::exception(function () use ($container) {
$component = new NonPresenterComponent_ap();
$container->callMethod(array($component, 'injectProperties'));
$container->callMethod([$component, 'injectProperties']);
}, 'Kdyby\Autowired\MemberAccessException', 'Trait Kdyby\Autowired\AutowireProperties can be used only in descendants of PresenterComponent.');
}

Expand All @@ -123,7 +123,7 @@ class AutowirePropertiesTest extends ContainerTestCase

Assert::exception(function () use ($container) {
$component = new PrivateAutowiredPropertyPresenter();
$container->callMethod(array($component, 'injectProperties'));
$container->callMethod([$component, 'injectProperties']);
}, 'Kdyby\Autowired\MemberAccessException', 'Autowired properties must be protected or public. Please fix visibility of KdybyTests\Autowired\PrivateAutowiredPropertyPresenter::$service or remove the @autowire annotation.');
}

Expand All @@ -135,7 +135,7 @@ class AutowirePropertiesTest extends ContainerTestCase

Assert::exception(function () use ($container) {
$component = new WrongCasePropertyAnnotationPresenter();
$container->callMethod(array($component, 'injectProperties'));
$container->callMethod([$component, 'injectProperties']);
}, 'Kdyby\Autowired\UnexpectedValueException', 'Annotation @Autowire on KdybyTests\Autowired\WrongCasePropertyAnnotationPresenter::$service should be fixed to lowercase @autowire.');
}

Expand All @@ -147,15 +147,15 @@ class AutowirePropertiesTest extends ContainerTestCase

Assert::exception(function () use ($container) {
$component = new TypoPropertyAnnotationPresenter();
$container->callMethod(array($component, 'injectProperties'));
$container->callMethod([$component, 'injectProperties']);
}, 'Kdyby\Autowired\UnexpectedValueException', 'Annotation @autowired on KdybyTests\Autowired\TypoPropertyAnnotationPresenter::$service should be fixed to lowercase @autowire.');
}

public function testUseExpansion()
{
$presenter = new PropertyWithUsePresenter();

$this->container->callMethod(array($presenter, 'injectProperties'));
$this->container->callMethod([$presenter, 'injectProperties']);
Assert::true($presenter->service instanceof AliasedService);
}

Expand All @@ -167,7 +167,7 @@ class AutowirePropertiesTest extends ContainerTestCase

$presenter = new WithTraitPresenter();

$this->container->callMethod(array($presenter, 'injectProperties'));
$this->container->callMethod([$presenter, 'injectProperties']);
Assert::true($presenter->service instanceof SampleService);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/KdybyTests/Autowired/Integration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class IntegrationTest extends ContainerTestCase
$container = $this->compileContainer($builder);

$presenter = new IntegrationPresenter();
$container->callMethod(array($presenter, 'injectProperties'));
$container->callMethod(array($presenter, 'injectComponentFactories'));
$container->callMethod([$presenter, 'injectProperties']);
$container->callMethod([$presenter, 'injectComponentFactories']);
}

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

Please sign in to comment.