Skip to content

Commit

Permalink
update type hints for new ServiceExtensions feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrico committed May 10, 2024
1 parent ae8ef3d commit 2c50cb6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Container/ReadOnlyContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function configureServiceExtensions($extensions): ServiceExtensions
foreach ($extensions as $id => $callback) {
/**
* @var string $id
* @var callable(mixed,ContainerInterface):mixed $callback
* @var ExtendingService $callback
*/
$servicesExtensions->add($id, $callback);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Container/ServiceExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

use Psr\Container\ContainerInterface as Container;

/**
* @psalm-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
*/
class ServiceExtensions
{
private const SERVICE_TYPE_NOT_CHANGED = 1;
private const SERVICE_TYPE_CHANGED = 2;
private const SERVICE_TYPE_NOT_OBJECT = 0;

/**
* @var array<string, list<callable>>
* @var array<string, list<ExtendingService>>
*/
protected $extensions = [];

Expand All @@ -28,7 +31,7 @@ final public static function typeId(string $type): string

/**
* @param string $extensionId
* @param callable $extender
* @param ExtendingService $extender
* @return static
*/
public function add(string $extensionId, callable $extender): ServiceExtensions
Expand Down Expand Up @@ -94,7 +97,7 @@ protected function resolveByType(

$extendedClasses[] = $className;

/** @var array<class-string, list<callable>> $allCallbacks */
/** @var array<class-string, list<ExtendingService>> $allCallbacks */
$allCallbacks = [];

// 1st group of extensions: targeting exact class
Expand Down Expand Up @@ -147,7 +150,7 @@ protected function resolveByType(
* @param class-string $type
* @param object $service
* @param Container $container
* @param array $extenders
* @param list<ExtendingService> $extenders
* @return array{mixed, int}
*/
private function extendByType(
Expand Down
6 changes: 5 additions & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
use Inpsyde\Modularity\Properties\Properties;
use Psr\Container\ContainerInterface;

/**
* @psalm-import-type Service from \Inpsyde\Modularity\Module\ServiceModule
* @psalm-import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
*/
class Package
{
/**
Expand Down Expand Up @@ -507,7 +511,7 @@ private function addModuleServices(Module $module, string $status): bool
array_walk(
$services,
static function (callable $service, string $id) use ($addCallback, &$ids) {
/** @var callable(string, callable) $addCallback */
/** @var callable(string, Service|ExtendingService) $addCallback */
$addCallback($id, $service);
/** @var list<string> $ids */
$ids[] = $id;
Expand Down

0 comments on commit 2c50cb6

Please sign in to comment.