Skip to content

Commit eeabec4

Browse files
optimize syntax (#4931)
Co-authored-by: 李铭昕 <[email protected]>
1 parent 395aadf commit eeabec4

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

src/Definition/DefinitionSource.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(array $source)
3333
*/
3434
public function getDefinition(string $name): ?DefinitionInterface
3535
{
36-
return $this->source[$name] ?? $this->source[$name] = $this->autowire($name);
36+
return $this->source[$name] ??= $this->autowire($name);
3737
}
3838

3939
/**

src/Definition/ObjectDefinition.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ public function setClassName(string $className = null): void
5353

5454
public function getClassName(): string
5555
{
56-
if ($this->className !== null) {
57-
return $this->className;
58-
}
59-
60-
return $this->name;
56+
return $this->className ?? $this->name;
6157
}
6258

6359
public function isClassExists(): bool

tests/Definition/DefinitionSourceTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected function tearDown(): void
2929
public function testGetDefinition()
3030
{
3131
$source = new DefinitionSource([]);
32-
$source->getDefinition(Bar::class);
32+
$bar = $source->getDefinition(Bar::class);
3333
$this->assertSame(1, count($source->getDefinitions()));
34+
$this->assertSame($bar, $source->getDefinition(Bar::class));
3435
}
3536
}

0 commit comments

Comments
 (0)