-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServicesDefaultsCaseConverter.php
More file actions
46 lines (36 loc) · 1.35 KB
/
ServicesDefaultsCaseConverter.php
File metadata and controls
46 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Symplify\PhpConfigPrinter\CaseConverter;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use Symplify\PhpConfigPrinter\Contract\CaseConverterInterface;
use Symplify\PhpConfigPrinter\NodeFactory\Service\AutoBindNodeFactory;
use Symplify\PhpConfigPrinter\ValueObject\MethodName;
use Symplify\PhpConfigPrinter\ValueObject\VariableName;
use Symplify\PhpConfigPrinter\ValueObject\YamlKey;
final readonly class ServicesDefaultsCaseConverter implements CaseConverterInterface
{
public function __construct(
private AutoBindNodeFactory $autoBindNodeFactory
) {
}
public function convertToMethodCallStmt(mixed $key, mixed $values): Stmt
{
$methodCall = new MethodCall($this->createServicesVariable(), MethodName::DEFAULTS);
$decoratedMethodCall = $this->autoBindNodeFactory->createAutoBindCalls($values, $methodCall);
return new Expression($decoratedMethodCall);
}
public function match(string $rootKey, mixed $key, mixed $values): bool
{
if ($rootKey !== YamlKey::SERVICES) {
return false;
}
return $key === YamlKey::_DEFAULTS;
}
private function createServicesVariable(): Variable
{
return new Variable(VariableName::SERVICES);
}
}