diff --git a/src/Kdyby/Autowired/AutowireComponentFactories.php b/src/Kdyby/Autowired/AutowireComponentFactories.php index e13815e..c49db4a 100644 --- a/src/Kdyby/Autowired/AutowireComponentFactories.php +++ b/src/Kdyby/Autowired/AutowireComponentFactories.php @@ -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')) { @@ -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, - )); + ]); } @@ -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."); } diff --git a/src/Kdyby/Autowired/AutowireProperties.php b/src/Kdyby/Autowired/AutowireProperties.php index edc30fa..1553cd0 100644 --- a/src/Kdyby/Autowired/AutowireProperties.php +++ b/src/Kdyby/Autowired/AutowireProperties.php @@ -28,7 +28,7 @@ trait AutowireProperties /** * @var array */ - private $autowireProperties = array(); + private $autowireProperties = []; /** * @var Nette\DI\Container @@ -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) { @@ -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)) { @@ -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, - )); + ]); } @@ -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; } @@ -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'); diff --git a/src/Kdyby/Autowired/DI/AutowiredExtension.php b/src/Kdyby/Autowired/DI/AutowiredExtension.php index d55b7fa..4aa7092 100644 --- a/src/Kdyby/Autowired/DI/AutowiredExtension.php +++ b/src/Kdyby/Autowired/DI/AutowiredExtension.php @@ -22,9 +22,9 @@ class AutowiredExtension extends Nette\DI\CompilerExtension { - public $defaults = array( + public $defaults = [ 'cacheStorage' => '@Nette\Caching\IStorage', - ); + ]; public function loadConfiguration() diff --git a/src/Kdyby/Autowired/Diagnostics/Panel.php b/src/Kdyby/Autowired/Diagnostics/Panel.php index 8ae7671..3495113 100644 --- a/src/Kdyby/Autowired/Diagnostics/Panel.php +++ b/src/Kdyby/Autowired/Diagnostics/Panel.php @@ -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']); } @@ -42,10 +42,10 @@ public static function renderException($e = NULL) return NULL; } - return array( + return [ 'tab' => 'Autowired', 'panel' => self::highlightException($e), - ); + ]; } diff --git a/tests/KdybyTests/Autowired/AutowireComponentFactories.phpt b/tests/KdybyTests/Autowired/AutowireComponentFactories.phpt index 68a5143..6787bbd 100644 --- a/tests/KdybyTests/Autowired/AutowireComponentFactories.phpt +++ b/tests/KdybyTests/Autowired/AutowireComponentFactories.phpt @@ -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); @@ -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.'); } @@ -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.'); } diff --git a/tests/KdybyTests/Autowired/AutowireProperties.phpt b/tests/KdybyTests/Autowired/AutowireProperties.phpt index 684a574..2484801 100644 --- a/tests/KdybyTests/Autowired/AutowireProperties.phpt +++ b/tests/KdybyTests/Autowired/AutowireProperties.phpt @@ -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'); @@ -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); } @@ -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.'); } @@ -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.'); } @@ -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.'); } @@ -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.'); } @@ -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.'); } @@ -147,7 +147,7 @@ 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.'); } @@ -155,7 +155,7 @@ class AutowirePropertiesTest extends ContainerTestCase { $presenter = new PropertyWithUsePresenter(); - $this->container->callMethod(array($presenter, 'injectProperties')); + $this->container->callMethod([$presenter, 'injectProperties']); Assert::true($presenter->service instanceof AliasedService); } @@ -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); } diff --git a/tests/KdybyTests/Autowired/Integration.phpt b/tests/KdybyTests/Autowired/Integration.phpt index 7d12783..1c2c83f 100644 --- a/tests/KdybyTests/Autowired/Integration.phpt +++ b/tests/KdybyTests/Autowired/Integration.phpt @@ -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']); } } diff --git a/tests/KdybyTests/bootstrap.php b/tests/KdybyTests/bootstrap.php index 936cb60..cc56f30 100755 --- a/tests/KdybyTests/bootstrap.php +++ b/tests/KdybyTests/bootstrap.php @@ -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;