-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNameOnlyServiceCaseConverter.php
More file actions
40 lines (32 loc) · 1.19 KB
/
NameOnlyServiceCaseConverter.php
File metadata and controls
40 lines (32 loc) · 1.19 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
<?php
declare(strict_types=1);
namespace Symplify\PhpConfigPrinter\CaseConverter;
use PhpParser\Node\Arg;
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\CommonNodeFactory;
use Symplify\PhpConfigPrinter\ValueObject\VariableName;
use Symplify\PhpConfigPrinter\ValueObject\YamlKey;
final readonly class NameOnlyServiceCaseConverter implements CaseConverterInterface
{
public function __construct(
private CommonNodeFactory $commonNodeFactory
) {
}
public function convertToMethodCallStmt(mixed $key, mixed $values): Stmt
{
$classConstFetch = $this->commonNodeFactory->createClassReference($key);
$setMethodCall = new MethodCall(new Variable(VariableName::SERVICES), 'set', [new Arg($classConstFetch)]);
return new Expression($setMethodCall);
}
public function match(string $rootKey, mixed $key, mixed $values): bool
{
if ($rootKey !== YamlKey::SERVICES) {
return false;
}
return $values === null || $values === [];
}
}