Skip to content

Commit

Permalink
Merge pull request #39 from samsonasik/apply-php80
Browse files Browse the repository at this point in the history
Apply PHP 8.0 Syntax and constructor promotion
  • Loading branch information
Ocramius authored Oct 28, 2022
2 parents b9f883e + 6f957eb commit fb0a2c3
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/Listener/LocatorRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function onLoadModules(ModuleEvent $e)
$events->attach(
Application::class,
ModuleManager::EVENT_BOOTSTRAP,
function (MvcEvent $e) use ($moduleManager) {
static function (MvcEvent $e) use ($moduleManager): void {
$moduleClassName = $moduleManager::class;
$moduleClassNameArray = explode('\\', $moduleClassName);
$moduleClassNameAlias = end($moduleClassNameArray);
Expand Down
18 changes: 7 additions & 11 deletions src/Listener/ServiceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ class ServiceListener implements ServiceListenerInterface
/** @var callable[] */
protected $listeners = [];

/**
* Default service manager used to fulfill other SMs that need to be lazy loaded
*
* @var ServiceManager
*/
protected $defaultServiceManager;

/**
* Default service configuration for the application service manager.
*
Expand All @@ -52,10 +45,13 @@ class ServiceListener implements ServiceListenerInterface
protected $serviceManagers = [];

/** @param null|array $configuration */
public function __construct(ServiceManager $serviceManager, $configuration = null)
{
$this->defaultServiceManager = $serviceManager;

public function __construct(
/**
* Default service manager used to fulfill other SMs that need to be lazy loaded
*/
protected ServiceManager $defaultServiceManager,
$configuration = null
) {
if ($configuration !== null) {
$this->setDefaultServiceConfig($configuration);
}
Expand Down
4 changes: 1 addition & 3 deletions src/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ public function loadModule($module)
protected function loadModuleByName(ModuleEvent $event)
{
$event->setName(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE);
$result = $this->getEventManager()->triggerEventUntil(function ($r) {
return is_object($r);
}, $event);
$result = $this->getEventManager()->triggerEventUntil(static fn($r): bool => is_object($r), $event);

$module = $result->last();
if (! is_object($module)) {
Expand Down
4 changes: 2 additions & 2 deletions test/Listener/LocatorRegistrationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testModuleClassIsRegisteredWithDiAndInjectedWithSharedInstances(
{
$module = null;
$locator = $this->serviceManager;
$locator->setFactory('Foo\Bar', function ($s) {
$locator->setFactory('Foo\Bar', static function ($s): Bar {
$module = $s->get(Module::class);
$manager = $s->get(ModuleManager::class);
return new Bar($module, $manager);
Expand All @@ -118,7 +118,7 @@ public function testModuleClassIsRegisteredWithDiAndInjectedWithSharedInstances(
$locatorRegistrationListener = new LocatorRegistrationListener();
$events = $this->moduleManager->getEventManager();
$locatorRegistrationListener->attach($events);
$events->attach(ModuleEvent::EVENT_LOAD_MODULE, function (ModuleEvent $e) use (&$module) {
$events->attach(ModuleEvent::EVENT_LOAD_MODULE, static function (ModuleEvent $e) use (&$module): void {
$module = $e->getModule();
}, -1000);
$this->moduleManager->loadModules();
Expand Down
14 changes: 5 additions & 9 deletions test/Listener/ServiceListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public function getServiceConfig(): array
// @codingStandardsIgnoreStart
return [
'invokables' => [
__CLASS__ => __CLASS__
self::class => self::class
],
'factories' => [
'foo' => static function () {},
'foo' => static function (): void {},
],
'abstract_factories' => [
new TestAsset\SampleAbstractFactory(),
Expand Down Expand Up @@ -362,9 +362,7 @@ public function testListenerCanOverrideServicesInServiceManagers(): void
{
$services = new ServiceManager();
$services->setService('config', []);
$services->setFactory('foo', static function ($services) {
return $services;
});
$services->setFactory('foo', static fn($services) => $services);
$listener = new ServiceListener($services);
$listener->addServiceManager(
$services,
Expand All @@ -378,9 +376,7 @@ public function testListenerCanOverrideServicesInServiceManagers(): void
'config' => ['foo' => 'bar'],
],
'factories' => [
'foo' => static function () {
return new stdClass();
},
'foo' => static fn(): stdClass => new stdClass(),
],
]);

Expand Down Expand Up @@ -422,7 +418,7 @@ public function testOnLoadModulesPostShouldNotRaiseExceptionIfNamedServiceManage
try {
$listener->onLoadModulesPost($event);
self::assertFalse($services->has('UndefinedPluginManager'));
} catch (\Exception $e) {
} catch (\Exception) {
self::fail('Exception should not be raised when encountering unknown plugin manager services');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

class CustomPluginDuckTypeProviderModule
{
/** @var mixed */
public $config;

/** @param mixed $config */
public function __construct($config)
public function __construct(public mixed $config)
{
$this->config = $config;
}

/** @return mixed */
Expand Down
3 changes: 1 addition & 2 deletions test/Listener/TestAsset/CustomPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public function validate($plugin): void
}
}

/** @param mixed $plugin */
public function validatePlugin($plugin): void
public function validatePlugin(mixed $plugin): void
{
$this->validate($plugin);
}
Expand Down
2 changes: 0 additions & 2 deletions test/Listener/TestAsset/CustomPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function createService(ServiceLocatorInterface $container)

/**
* Provide options to use during instantiation (v2).
*
* @param array $options
*/
public function setCreationOptions(array $options): void
{
Expand Down
7 changes: 1 addition & 6 deletions test/Listener/TestAsset/CustomPluginProviderModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

class CustomPluginProviderModule implements CustomPluginProviderInterface
{
/** @var mixed */
public $config;

/** @param mixed $config */
public function __construct($config)
public function __construct(public mixed $config)
{
$this->config = $config;
}

/** @return mixed */
Expand Down
7 changes: 1 addition & 6 deletions test/Listener/TestAsset/ServiceProviderModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

class ServiceProviderModule
{
/** @var mixed */
public $config;

/** @param mixed $config */
public function __construct($config)
public function __construct(public mixed $config)
{
$this->config = $config;
}

/** @return mixed */
Expand Down
4 changes: 1 addition & 3 deletions test/Listener/_files/good/merge3.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
declare(strict_types=1);

return [
'toUpper' => function (string $input) {
return strtoupper($input);
},
'toUpper' => static fn(string $input): string => strtoupper($input),
];
2 changes: 1 addition & 1 deletion test/ModuleManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testModuleIsMarkedAsLoadedWhenLoadModuleEventIsTriggered(): void
$moduleManager = new ModuleManager(['BarModule'], $this->events);
$events = $this->events;
$this->defaultListeners->attach($events);
$events->attach(ModuleEvent::EVENT_LOAD_MODULE, function (ModuleEvent $e) use ($test) {
$events->attach(ModuleEvent::EVENT_LOAD_MODULE, static function (ModuleEvent $e) use ($test): void {
$test->modules = $e->getTarget()->getLoadedModules(false);
});

Expand Down
10 changes: 1 addition & 9 deletions test/TestAsset/ListenerTestModule/src/Foo/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@

class Bar
{
/** @var Module */
public $module;

/** @var ModuleManager */
public $moduleManager;

public function __construct(Module $module, ModuleManager $moduleManager)
public function __construct(public Module $module, public ModuleManager $moduleManager)
{
$this->module = $module;
$this->moduleManager = $moduleManager;
}
}

0 comments on commit fb0a2c3

Please sign in to comment.