1 | <?php |
||
28 | class ApplicationPackage implements RegistrationInterface |
||
29 | { |
||
30 | /** @var array $config */ |
||
31 | private $config; |
||
32 | |||
33 | /** @var Router $router */ |
||
34 | private $router; |
||
35 | |||
36 | /** |
||
37 | * ApplicationPackage constructor. |
||
38 | * @param array $config |
||
39 | * @param Router $router |
||
40 | */ |
||
41 | 10 | public function __construct(array $config, Router $router) |
|
46 | |||
47 | /** |
||
48 | * @param Container $c |
||
49 | * @throws \Bone\Exception |
||
50 | * @throws \Exception |
||
51 | */ |
||
52 | 10 | public function addToContainer(Container $c) |
|
66 | |||
67 | /** |
||
68 | * @param Container $c |
||
69 | */ |
||
70 | 10 | private function setConfigArray(Container $c) |
|
76 | |||
77 | /** |
||
78 | * @param Container $c |
||
79 | */ |
||
80 | 10 | private function setupViewEngine(Container $c) |
|
85 | |||
86 | /** |
||
87 | * @param Container $c |
||
88 | */ |
||
89 | 10 | private function setupPackages(Container $c) |
|
90 | { |
||
91 | // set up the modules and vendor package modules |
||
92 | 10 | $packages = $c->get('packages'); |
|
93 | 10 | $i18n = $c->get('i18n'); |
|
94 | /** @var Translator $translator */ |
||
95 | 10 | $translator = $c->get(Translator::class); |
|
96 | |||
97 | 10 | foreach ($packages as $packageName) { |
|
98 | 10 | if (class_exists($packageName)) { |
|
99 | /** @var RegistrationInterface $package */ |
||
100 | 10 | $package = new $packageName(); |
|
101 | |||
102 | 10 | if ($package->hasEntityPath()) { |
|
103 | 10 | $paths = $c['entity_paths']; |
|
104 | 10 | $paths[] = $package->getEntityPath(); |
|
105 | 10 | $c['entity_paths'] = $paths; |
|
106 | } |
||
107 | } |
||
108 | } |
||
109 | |||
110 | 10 | reset($packages); |
|
111 | 10 | $consoleCommands = []; |
|
112 | |||
113 | 10 | foreach ($packages as $packageName) { |
|
114 | 10 | if (class_exists($packageName)) { |
|
115 | /** @var RegistrationInterface $package */ |
||
116 | 10 | $package = new $packageName(); |
|
117 | 10 | $package->addToContainer($c); |
|
118 | |||
119 | 10 | if ($package instanceof RouterConfigInterface) { |
|
120 | 10 | $package->addRoutes($c, $this->router); |
|
121 | } |
||
122 | |||
123 | 10 | if ($package instanceof I18nRegistrationInterface) { |
|
124 | 10 | foreach ($i18n['supported_locales'] as $locale) { |
|
125 | 10 | $factory = new TranslatorFactory(); |
|
126 | 10 | $factory->addPackageTranslations($translator, $package, $locale); |
|
127 | } |
||
128 | } |
||
129 | |||
130 | 10 | if ($package instanceof MiddlewareAwareInterface) { |
|
131 | 10 | $stack = $c->get(Stack::class); |
|
132 | 10 | $package->addMiddleware($stack, $c); |
|
133 | } |
||
134 | |||
135 | 10 | if ($package instanceof CommandRegistrationInterface) { |
|
136 | 10 | $stack = $c->get(Stack::class); |
|
|
|||
137 | 10 | $commands = $package->registerConsoleCommands($c); |
|
138 | |||
139 | 10 | foreach ($commands as $command) { |
|
140 | 10 | $consoleCommands[] = $command; |
|
141 | } |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | |||
146 | 10 | $c['consoleCommands'] = $consoleCommands; |
|
147 | |||
148 | $c[ConsoleApplication::class] = $c->factory(function(Container $c) { |
||
149 | 1 | $app = new ConsoleApplication(); |
|
150 | 1 | $consoleCommands = $c->get('consoleCommands'); |
|
151 | 1 | foreach($consoleCommands as $command) { |
|
152 | 1 | $app->addCommands($consoleCommands); |
|
153 | } |
||
154 | |||
155 | 1 | return $app; |
|
156 | 10 | }); |
|
157 | 10 | } |
|
158 | |||
159 | /** |
||
160 | * @param Container $c |
||
161 | * @throws \Bone\Exception |
||
162 | */ |
||
163 | 10 | private function setupTranslator(Container $c) |
|
169 | |||
170 | |||
171 | /** |
||
172 | * @param Container $c |
||
173 | * @throws \Bone\Exception |
||
174 | */ |
||
175 | 10 | private function setupPdoConnection(Container $c) |
|
180 | |||
181 | /** |
||
182 | * @param Container $c |
||
183 | */ |
||
184 | 10 | private function setupDownloadController(Container $c): void |
|
192 | |||
193 | /** |
||
194 | * @param Container $c |
||
195 | */ |
||
196 | 10 | private function setupRouteFirewall(Container $c): void |
|
201 | |||
202 | /** |
||
203 | * @param Container $c |
||
204 | * @throws \Exception |
||
205 | */ |
||
206 | 10 | private function setupLogs(Container $c) |
|
211 | |||
212 | /** |
||
213 | * @param Container $c |
||
214 | */ |
||
215 | 10 | private function setupVendorViewOverrides(Container $c): void |
|
226 | |||
227 | /** |
||
228 | * @param string $view |
||
229 | * @param string $folder |
||
230 | * @param Folders $registeredViews |
||
231 | */ |
||
232 | 10 | private function overrideViewFolder(string $view, string $folder, Folders $registeredViews): void |
|
240 | |||
241 | /** |
||
242 | * @return string |
||
243 | */ |
||
244 | 1 | public function getEntityPath(): string |
|
248 | |||
249 | /** |
||
250 | * @return bool |
||
251 | */ |
||
252 | 1 | public function hasEntityPath(): bool |
|
256 | |||
257 | /** |
||
258 | * @param Container $c |
||
259 | */ |
||
260 | 10 | private function initMiddlewareStack(Container $c): void |
|
265 | |||
266 | /** |
||
267 | * @param Container $c |
||
268 | */ |
||
269 | 10 | private function setupMiddlewareStack(Container $c): void |
|
284 | } |
||
285 |
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.