Skip to content

Commit ec83452

Browse files
authored
optimization code (#3471)
1 parent efb3c93 commit ec83452

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

src/Container.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ public function get($name)
114114
if (isset($this->resolvedEntries[$name]) || array_key_exists($name, $this->resolvedEntries)) {
115115
return $this->resolvedEntries[$name];
116116
}
117-
$this->resolvedEntries[$name] = $value = $this->make($name);
118-
return $value;
117+
return $this->resolvedEntries[$name] = $this->make($name);
119118
}
120119

121120
/**

src/Definition/DefinitionSource.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use function is_callable;
1919
use function is_string;
2020
use function method_exists;
21-
use function print_r;
2221

2322
class DefinitionSource implements DefinitionSourceInterface
2423
{
@@ -37,10 +36,7 @@ public function __construct(array $source)
3736
*/
3837
public function getDefinition(string $name): ?DefinitionInterface
3938
{
40-
if (! isset($this->source[$name])) {
41-
$this->source[$name] = $this->autowire($name);
42-
}
43-
return $this->source[$name];
39+
return $this->source[$name] ?? $this->source[$name] = $this->autowire($name);
4440
}
4541

4642
/**
@@ -141,9 +137,4 @@ private function autowire(string $name, ObjectDefinition $definition = null): ?O
141137

142138
return $definition;
143139
}
144-
145-
private function printLn(string $message): void
146-
{
147-
print_r($message . PHP_EOL);
148-
}
149140
}

src/Resolver/DepthGuard.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,14 @@ public function decrement()
6868

6969
public function call(string $name, callable $callable)
7070
{
71-
$guard = DepthGuard::getInstance();
72-
7371
try {
7472
$this->increment();
75-
$result = $callable();
73+
return $callable();
7674
} catch (CircularDependencyException $exception) {
7775
$exception->addDefinitionName($name);
7876
throw $exception;
7977
} finally {
80-
$guard->decrement();
78+
$this->decrement();
8179
}
82-
83-
return $result;
8480
}
8581
}

0 commit comments

Comments
 (0)