-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInstanceOfNestedCaseConverter.php
More file actions
58 lines (46 loc) · 1.69 KB
/
InstanceOfNestedCaseConverter.php
File metadata and controls
58 lines (46 loc) · 1.69 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
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Symplify\PhpConfigPrinter\CaseConverter\NestedCaseConverter;
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\NodeFactory\CommonNodeFactory;
use Symplify\PhpConfigPrinter\NodeFactory\Service\ServiceOptionNodeFactory;
use Symplify\PhpConfigPrinter\ValueObject\MethodName;
use Symplify\PhpConfigPrinter\ValueObject\VariableName;
use Symplify\PhpConfigPrinter\ValueObject\YamlKey;
final readonly class InstanceOfNestedCaseConverter
{
public function __construct(
private CommonNodeFactory $commonNodeFactory,
private ServiceOptionNodeFactory $serviceOptionNodeFactory
) {
}
/**
* @param mixed[] $values
*/
public function convertToMethodCall(string $key, array $values): Stmt
{
$classConstFetch = $this->commonNodeFactory->createClassReference($key);
$servicesVariable = new Variable(VariableName::SERVICES);
$args = [new Arg($classConstFetch)];
$instanceofMethodCall = new MethodCall($servicesVariable, MethodName::INSTANCEOF, $args);
$decoreatedInstanceofMethodCall = $this->serviceOptionNodeFactory->convertServiceOptionsToNodes(
$values,
$instanceofMethodCall
);
return new Expression($decoreatedInstanceofMethodCall);
}
public function isMatch(string $rootKey, int|string $subKey): bool
{
if ($rootKey !== YamlKey::SERVICES) {
return false;
}
if (! is_string($subKey)) {
return false;
}
return $subKey === YamlKey::_INSTANCEOF;
}
}