Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
49 / 49 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ClassCodeGenerator | |
100.00% |
49 / 49 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
generateComposerJsonFile | |
100.00% |
33 / 33 |
|
100.00% |
1 / 1 |
1 | |||
generateLayoutClass | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
generateLayoutTestClass | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\TwigTemplateLayoutRenderer\Skeleton; |
3 | |
4 | use Apie\Common\ValueObjects\EntityNamespace; |
5 | use Apie\Core\ApieLib; |
6 | use Apie\Core\Identifiers\Identifier; |
7 | |
8 | final class ClassCodeGenerator |
9 | { |
10 | public function generateComposerJsonFile( |
11 | Identifier $name, |
12 | EntityNamespace $entityNamespace, |
13 | string $apieVersion = ApieLib::VERSION |
14 | ): string { |
15 | $contents = [ |
16 | "name" => "apie/cms-layout-" . $name, |
17 | "description" => "Composer package of the apie library: cms layout " . $name, |
18 | "type" => "library", |
19 | "license" => "MIT", |
20 | "authors" => [ |
21 | ], |
22 | "autoload" => [ |
23 | "psr-4" => [ |
24 | $entityNamespace->toNative() => "src/", |
25 | ] |
26 | ], |
27 | "autoload-dev" => [ |
28 | "psr-4" => [ |
29 | $entityNamespace->toTestNamespace()->toNative() => 'tests/', |
30 | ] |
31 | ], |
32 | "require" => [ |
33 | "php" => ">=8.3", |
34 | "apie/core" => $apieVersion, |
35 | "apie/html-builders" => $apieVersion, |
36 | "apie/twig-template-layout-renderer" => $apieVersion, |
37 | "twig/twig" => "^3.10.2" |
38 | ], |
39 | "require-dev" => [ |
40 | "apie/fixtures" => $apieVersion, |
41 | "illuminate/support" => "*", |
42 | "phpunit/phpunit" => "^11.5.2" |
43 | ], |
44 | "minimum-stability" => "dev", |
45 | "prefer-stable" => true |
46 | ]; |
47 | return json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
48 | } |
49 | |
50 | public function generateLayoutClass( |
51 | Identifier $name, |
52 | EntityNamespace $entityNamespace |
53 | ): string { |
54 | $contents = '<?php' . PHP_EOL; |
55 | $contents .= 'namespace ' . rtrim($entityNamespace->toNative(), '\\') . ';' . PHP_EOL; |
56 | $contents .= ' |
57 | use Apie\HtmlBuilders\Assets\AssetManager; |
58 | use Apie\TwigTemplateLayoutRenderer\TwigRenderer; |
59 | |
60 | '; |
61 | $contents .= 'class ' . $name->toPascalCaseSlug()-> toNative() . 'DesignSystemLayout |
62 | { |
63 | /** |
64 | * @codeCoverageIgnore |
65 | */ |
66 | private function __construct() |
67 | { |
68 | } |
69 | |
70 | public static function createRenderer(?AssetManager $assetManager = null): TwigRenderer |
71 | { |
72 | $assetManager ??= new AssetManager(); |
73 | return new TwigRenderer( |
74 | __DIR__ . \'/../resources/templates\', |
75 | $assetManager->withAddedPath(__DIR__ . \'/../resources/assets\'), |
76 | "Apie\HtmlBuilders\Components\\\\" |
77 | ); |
78 | } |
79 | } |
80 | '; |
81 | return $contents; |
82 | } |
83 | |
84 | public function generateLayoutTestClass( |
85 | Identifier $name, |
86 | EntityNamespace $entityNamespace |
87 | ): string { |
88 | $contents = '<?php' . PHP_EOL; |
89 | $contents .= 'namespace ' . rtrim($entityNamespace->toTestNamespace()->toNative(), '\\') . ';' . PHP_EOL; |
90 | $contents .= ' |
91 | use ' . $entityNamespace . $name->toPascalCaseSlug()->toNative() . 'DesignSystemLayout; |
92 | use Apie\HtmlBuilders\Interfaces\ComponentRendererInterface; |
93 | use Apie\HtmlBuilders\TestHelpers\AbstractRenderTestCase; |
94 | |
95 | '; |
96 | $contents .= 'class ' . $name->toPascalCaseSlug()-> toNative() . 'DesignSystemLayoutTest extends AbstractRenderTestCase |
97 | { |
98 | public function getRenderer(): ComponentRendererInterface |
99 | { |
100 | return ' . $name->toPascalCaseSlug()-> toNative() . 'DesignSystemLayout::createRenderer(); |
101 | } |
102 | |
103 | public function getFixturesPath(): string |
104 | { |
105 | return __DIR__ . \'/../fixtures\'; |
106 | } |
107 | } |
108 | '; |
109 | return $contents; |
110 | } |
111 | } |