Skip to content

Commit

Permalink
Separate chain calls (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankaest committed May 22, 2022
1 parent e858d96 commit 50b2e66
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/ParameterDefinition.php
Expand Up @@ -78,7 +78,9 @@ public function resolve(ContainerInterface $container)
// If type name is "self", it means that called class and
// $parameter->getDeclaringClass() returned instance of `ReflectionClass`.
/** @psalm-suppress PossiblyNullReference */
$typeName = $this->parameter->getDeclaringClass()->getName();
$typeName = $this->parameter
->getDeclaringClass()
->getName();
}

try {
Expand Down Expand Up @@ -185,7 +187,9 @@ private function resolveUnionType(ContainerInterface $container)
// If type name is "self", it means that called class and
// $parameter->getDeclaringClass() returned instance of `ReflectionClass`.
/** @psalm-suppress PossiblyNullReference */
$typeName = $this->parameter->getDeclaringClass()->getName();
$typeName = $this->parameter
->getDeclaringClass()
->getName();
}

try {
Expand Down Expand Up @@ -265,7 +269,10 @@ private function getCallable(): string
if ($class !== null) {
$callable[] = $class->getName();
}
$callable[] = $this->parameter->getDeclaringFunction()->getName() . '()';
$callable[] = $this->parameter
->getDeclaringFunction()
->getName() .
'()';

return implode('::', $callable);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Php8/Helpers/DefinitionExtractorTest.php
Expand Up @@ -57,7 +57,10 @@ public function testFromClassWithUnionSelfDependency(): void
{
$definition = DefinitionExtractor::fromClassName(UnionSelfDependency::class)['a'];

$actualType = implode('|', $definition->getReflection()->getType()->getTypes());
$actualType = implode('|', $definition
->getReflection()
->getType()
->getTypes());
$this->assertInstanceOf(ParameterDefinition::class, $definition);
$this->assertSame('self|' . ColorInterface::class, $actualType);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Php8/ParameterDefinitionTest.php
Expand Up @@ -44,7 +44,9 @@ public function testResolveUnionType(): void
public function testNotInstantiable(): void
{
$definition = new ParameterDefinition(
(new ReflectionClass(UnionCar::class))->getConstructor()->getParameters()[0]
(new ReflectionClass(UnionCar::class))
->getConstructor()
->getParameters()[0]
);
$container = new SimpleContainer();

Expand Down
8 changes: 7 additions & 1 deletion tests/Unit/Helpers/DefinitionExtractorTest.php
Expand Up @@ -145,6 +145,12 @@ public function testFromClassWithSelfDependency(): void
$definition = DefinitionExtractor::fromClassName(SelfDependency::class)['a'];

$this->assertInstanceOf(ParameterDefinition::class, $definition);
$this->assertSame('self', $definition->getReflection()->getType()->getName());
$this->assertSame(
'self',
$definition
->getReflection()
->getType()
->getName(),
);
}
}
8 changes: 6 additions & 2 deletions tests/Unit/ParameterDefinitionTest.php
Expand Up @@ -120,7 +120,9 @@ public function testResolveWithIncorrectTypeInContainer(): void
public function testNullableParameterNotInstantiable(): void
{
$definition = new ParameterDefinition(
(new ReflectionClass(NullableConcreteDependency::class))->getConstructor()->getParameters()[0]
(new ReflectionClass(NullableConcreteDependency::class))
->getConstructor()
->getParameters()[0]
);
$container = new SimpleContainer();

Expand Down Expand Up @@ -203,7 +205,9 @@ public function testResolveSelf(): void
public function testNotInstantiable(): void
{
$definition = new ParameterDefinition(
(new ReflectionClass(Car::class))->getConstructor()->getParameters()[0]
(new ReflectionClass(Car::class))
->getConstructor()
->getParameters()[0]
);
$container = new SimpleContainer();

Expand Down

0 comments on commit 50b2e66

Please sign in to comment.