1 | <?php declare(strict_types=1); |
||
24 | final class EnvironmentFactory |
||
25 | { |
||
26 | private $baseEnvironment; |
||
27 | /** |
||
28 | * @var Renderer |
||
29 | */ |
||
30 | private $renderer; |
||
31 | |||
32 | public function __construct(Environment $baseEnvironment, Renderer $renderer) |
||
37 | |||
38 | public function create( |
||
69 | |||
70 | /** |
||
71 | * Adds the phpDocumentor base extension to the Twig Environment. |
||
72 | */ |
||
73 | private function addPhpDocumentorExtension( |
||
85 | |||
86 | /** |
||
87 | * Tries to add any custom extensions that have been defined in the template or the transformation's configuration. |
||
88 | * |
||
89 | * This method will read the `twig-extension` parameter of the transformation (which inherits the template's |
||
90 | * parameter set) and try to add those extensions to the environment. |
||
91 | * |
||
92 | * @throws \InvalidArgumentException if a twig-extension should be loaded but it could not be found. |
||
93 | */ |
||
94 | private function addExtensionsFromTemplateConfiguration( |
||
95 | Transformation $transformation, |
||
96 | ProjectDescriptor $project, |
||
97 | Environment $twigEnvironment |
||
98 | ): void { |
||
99 | $isDebug = $transformation->getParameter('twig-debug') |
||
|
|||
100 | ? $transformation->getParameter('twig-debug')->getValue() |
||
101 | : false; |
||
102 | // if ($isDebug === 'true') { |
||
103 | $twigEnvironment->enableDebug(); |
||
104 | $twigEnvironment->enableAutoReload(); |
||
105 | $twigEnvironment->addExtension(new DebugExtension()); |
||
106 | // } |
||
107 | |||
108 | /** @var \phpDocumentor\Transformer\Template\Parameter $extension */ |
||
109 | foreach ($transformation->getParametersWithKey('twig-extension') as $extension) { |
||
110 | $extensionValue = $extension->getValue(); |
||
111 | if (!class_exists($extensionValue)) { |
||
112 | throw new \InvalidArgumentException('Unknown twig extension: ' . $extensionValue); |
||
113 | } |
||
114 | |||
115 | // to support 'normal' Twig extensions we check the interface to determine what instantiation to do. |
||
116 | $implementsInterface = in_array( |
||
117 | 'phpDocumentor\Transformer\Writer\Twig\ExtensionInterface', |
||
118 | class_implements($extensionValue), |
||
119 | true |
||
120 | ); |
||
121 | |||
122 | $twigEnvironment->addExtension( |
||
123 | $implementsInterface ? new $extensionValue($project, $transformation) : new $extensionValue() |
||
124 | ); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Returns the path belonging to the template. |
||
130 | */ |
||
131 | private function getTemplatePath(Transformation $transformation): string |
||
137 | } |
||
138 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.