Skip to content

Commit

Permalink
Merge pull request #105 from samsonasik/php74-syntax
Browse files Browse the repository at this point in the history
[Php 7.4] Apply Php 7.4 Syntax
  • Loading branch information
Ocramius committed Sep 18, 2021
2 parents 9a86e14 + 4677bf7 commit aa488f5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 deletions.
5 changes: 2 additions & 3 deletions src/AbstractFactory/ReflectionBasedAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ private function resolveParameterWithoutConfigService(ContainerInterface $contai
* @return mixed
* @throws ServiceNotFoundException If type-hinted parameter cannot be
* resolved to a service in the container.
* @psalm-suppress MissingClosureReturnType
*/
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
return $this->resolveParameter($parameter, $container, $requestedName);
};
return fn(ReflectionParameter $parameter) => $this->resolveParameter($parameter, $container, $requestedName);
}

/**
Expand Down
10 changes: 3 additions & 7 deletions src/Exception/CyclicAliasException.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public static function fromCyclicAlias(string $alias, array $aliases): self
public static function fromAliasesMap(array $aliases)
{
$detectedCycles = array_filter(array_map(
function ($alias) use ($aliases) {
return self::getCycleFor($aliases, $alias);
},
static fn($alias) => self::getCycleFor($aliases, $alias),
array_keys($aliases)
));

Expand Down Expand Up @@ -125,9 +123,7 @@ private static function printCycle(array $detectedCycle)
return implode(
' => ',
array_map(
function ($cycle) {
return '"' . $cycle . '"';
},
static fn($cycle): string => '"' . $cycle . '"',
$fullCycle
)
);
Expand All @@ -148,7 +144,7 @@ private static function deDuplicateDetectedCycles(array $detectedCycles)

$hash = serialize(array_values($cycleAliases));

$detectedCyclesByHash[$hash] = $detectedCyclesByHash[$hash] ?? $detectedCycle;
$detectedCyclesByHash[$hash] ??= $detectedCycle;
}

return array_values($detectedCyclesByHash);
Expand Down
10 changes: 1 addition & 9 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,7 @@ private function createDelegatorFromName(string $name, ?array $options = null)

$creationCallback =
/** @return object */
static function () use (
$initialCreationContext,
$delegatorFactory,
$name,
$creationCallback,
$options
) {
return $delegatorFactory($initialCreationContext, $name, $creationCallback, $options);
};
static fn() => $delegatorFactory($initialCreationContext, $name, $creationCallback, $options);
}

return $creationCallback();
Expand Down
4 changes: 1 addition & 3 deletions src/Tool/ConfigDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public function createDependencyConfig(array $config, $className, $ignoreUnresol
$constructorArguments = $reflectionClass->getConstructor()->getParameters();
$constructorArguments = array_filter(
$constructorArguments,
function (ReflectionParameter $argument) {
return ! $argument->isOptional();
}
static fn(ReflectionParameter $argument): bool => ! $argument->isOptional()
);

// has no required parameters, treat it as an invokable
Expand Down
19 changes: 8 additions & 11 deletions src/Tool/FactoryCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class FactoryCreator
{
public const FACTORY_TEMPLATE = <<<'EOT'
<?php
declare(strict_types=1);
namespace %s;
%s
class %sFactory implements FactoryInterface
{
/**
Expand All @@ -47,7 +47,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
return new %s(%s);
}
}

EOT;

private const IMPORT_ALWAYS = [
Expand Down Expand Up @@ -135,9 +135,8 @@ function (ReflectionParameter $argument): bool {
*/
private function createArgumentString($className)
{
$arguments = array_map(function (string $dependency): string {
return sprintf('$container->get(\\%s::class)', $dependency);
}, $this->getConstructorParameters($className));
$arguments = array_map(fn(string $dependency): string
=> sprintf('$container->get(\\%s::class)', $dependency), $this->getConstructorParameters($className));

switch (count($arguments)) {
case 0:
Expand All @@ -160,8 +159,6 @@ private function createImportStatements(string $className): string
{
$imports = array_merge(self::IMPORT_ALWAYS, [$className]);
sort($imports);
return implode("\n", array_map(function (string $import): string {
return sprintf('use %s;', $import);
}, $imports));
return implode("\n", array_map(static fn(string $import): string => sprintf('use %s;', $import), $imports));
}
}
4 changes: 1 addition & 3 deletions test/LazyServiceIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ public function testRaisesServiceNotFoundExceptionIfRequestedLazyServiceIsNotInC
*/
protected function getRegisteredProxyAutoloadFunctions()
{
$filter = function ($autoload) {
return $autoload instanceof AutoloaderInterface;
};
$filter = static fn($autoload): bool => $autoload instanceof AutoloaderInterface;

return array_filter(spl_autoload_functions(), $filter);
}
Expand Down

0 comments on commit aa488f5

Please sign in to comment.