Skip to content

Commit 772d3ed

Browse files
committed
Fix phpstan
1 parent cff69dd commit 772d3ed

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ includes:
33

44
parameters:
55
excludePaths:
6-
- src/Controller/ErrorPreviewConsoleController.php
6+
- src/Command/Preview/ErrorPreviewConsoleCommand.php
77
- src/Controller/ErrorPreviewController.php
88
- src/Middleware/Routed/Preview/ErrorPreviewAction.php
99
checkMissingIterableValueType: false
@@ -13,3 +13,4 @@ parameters:
1313
ignoreErrors:
1414
- '#function set_error_handler expects (callable(int, string, string, int, array): bool)*#'
1515
- '#Invalid type object to throw#'
16+
- '#Cannot call method getBody\(\) on int#'

spec/Middleware/MezzioFactorySpec.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -240,97 +240,97 @@
240240
$config = $this->config;
241241
unset($config['db']['adapters']);
242242

243-
foreach ($this->mapCreateContainers as $container) {
243+
foreach ($this->mapCreateContainers as $mapCreateContainer) {
244244
$config['log']['ErrorHeroModuleLogger']['writers'][0]['options']['db'] = AdapterInterface::class;
245-
if ($container instanceof AuraContainer) {
245+
if ($mapCreateContainer instanceof AuraContainer) {
246246
$config = new ArrayObject($config);
247247
}
248248

249-
allow($container)->toReceive('get')->with('config')
249+
allow($mapCreateContainer)->toReceive('get')->with('config')
250250
->andReturn($config);
251-
if ($container instanceof AuraContainer) {
251+
if ($mapCreateContainer instanceof AuraContainer) {
252252
$config = $config->getArrayCopy();
253253
}
254254

255-
allow($container)->toReceive('has')->with(EntityManager::class)->andReturn(false);
255+
allow($mapCreateContainer)->toReceive('has')->with(EntityManager::class)->andReturn(false);
256256

257257
$logging = Double::instance(['extends' => Logging::class, 'methods' => '__construct']);
258-
allow($container)->toReceive('get')->with(Logging::class)
258+
allow($mapCreateContainer)->toReceive('get')->with(Logging::class)
259259
->andReturn($logging);
260260

261261
$renderer = Double::instance(['implements' => TemplateRendererInterface::class]);
262-
allow($container)->toReceive('get')->with(TemplateRendererInterface::class)
262+
allow($mapCreateContainer)->toReceive('get')->with(TemplateRendererInterface::class)
263263
->andReturn($renderer);
264264

265-
expect($container->has('ErrorHeroModuleLogger'))->toBeFalsy();
266-
$actual = $this->factory($container);
265+
expect($mapCreateContainer->has('ErrorHeroModuleLogger'))->toBeFalsy();
266+
$actual = $this->factory($mapCreateContainer);
267267
expect($actual)->toBeAnInstanceOf(Mezzio::class);
268-
expect($container->has('ErrorHeroModuleLogger'))->toBeTruthy();
268+
expect($mapCreateContainer->has('ErrorHeroModuleLogger'))->toBeTruthy();
269269
}
270270

271271
});
272272

273273
it('returns Mezzio Middleware instance with create service first for mapped containers and db name found in adapters', function (): void {
274274

275-
foreach ($this->mapCreateContainers as $container) {
275+
foreach ($this->mapCreateContainers as $mapCreateContainer) {
276276
$config = $this->config;
277277
$config['log']['ErrorHeroModuleLogger']['writers'][0]['options']['db'] = 'my-adapter';
278-
if ($container instanceof AuraContainer) {
278+
if ($mapCreateContainer instanceof AuraContainer) {
279279
$config = new ArrayObject($config);
280280
}
281281

282-
allow($container)->toReceive('get')->with('config')
282+
allow($mapCreateContainer)->toReceive('get')->with('config')
283283
->andReturn($config);
284-
if ($container instanceof AuraContainer) {
284+
if ($mapCreateContainer instanceof AuraContainer) {
285285
$config = $config->getArrayCopy();
286286
}
287287

288-
allow($container)->toReceive('has')->with(EntityManager::class)->andReturn(false);
288+
allow($mapCreateContainer)->toReceive('has')->with(EntityManager::class)->andReturn(false);
289289

290290
$logging = Double::instance(['extends' => Logging::class, 'methods' => '__construct']);
291-
allow($container)->toReceive('get')->with(Logging::class)
291+
allow($mapCreateContainer)->toReceive('get')->with(Logging::class)
292292
->andReturn($logging);
293293

294294
$renderer = Double::instance(['implements' => TemplateRendererInterface::class]);
295-
allow($container)->toReceive('get')->with(TemplateRendererInterface::class)
295+
allow($mapCreateContainer)->toReceive('get')->with(TemplateRendererInterface::class)
296296
->andReturn($renderer);
297297

298-
expect($container->has('ErrorHeroModuleLogger'))->toBeFalsy();
299-
$actual = $this->factory($container);
298+
expect($mapCreateContainer->has('ErrorHeroModuleLogger'))->toBeFalsy();
299+
$actual = $this->factory($mapCreateContainer);
300300
expect($actual)->toBeAnInstanceOf(Mezzio::class);
301-
expect($container->has('ErrorHeroModuleLogger'))->toBeTruthy();
301+
expect($mapCreateContainer->has('ErrorHeroModuleLogger'))->toBeTruthy();
302302
}
303303

304304
});
305305

306306
it('returns Mezzio Middleware instance with create services first for mapped containers and db name not found in adapters, which means use "Laminas\Db\Adapter\Adapter" name', function (): void {
307307

308308
$config = $this->config;
309-
foreach ($this->mapCreateContainers as $container) {
310-
if ($container instanceof AuraContainer) {
309+
foreach ($this->mapCreateContainers as $mapCreateContainer) {
310+
if ($mapCreateContainer instanceof AuraContainer) {
311311
$config = new ArrayObject($config);
312312
}
313313

314-
allow($container)->toReceive('get')->with('config')
314+
allow($mapCreateContainer)->toReceive('get')->with('config')
315315
->andReturn($config);
316-
if ($container instanceof AuraContainer) {
316+
if ($mapCreateContainer instanceof AuraContainer) {
317317
$config = $config->getArrayCopy();
318318
}
319319

320-
allow($container)->toReceive('has')->with(EntityManager::class)->andReturn(false);
320+
allow($mapCreateContainer)->toReceive('has')->with(EntityManager::class)->andReturn(false);
321321

322322
$logging = Double::instance(['extends' => Logging::class, 'methods' => '__construct']);
323-
allow($container)->toReceive('get')->with(Logging::class)
323+
allow($mapCreateContainer)->toReceive('get')->with(Logging::class)
324324
->andReturn($logging);
325325

326326
$renderer = Double::instance(['implements' => TemplateRendererInterface::class]);
327-
allow($container)->toReceive('get')->with(TemplateRendererInterface::class)
327+
allow($mapCreateContainer)->toReceive('get')->with(TemplateRendererInterface::class)
328328
->andReturn($renderer);
329329

330-
expect($container->has('ErrorHeroModuleLogger'))->toBeFalsy();
331-
$actual = $this->factory($container);
330+
expect($mapCreateContainer->has('ErrorHeroModuleLogger'))->toBeFalsy();
331+
$actual = $this->factory($mapCreateContainer);
332332
expect($actual)->toBeAnInstanceOf(Mezzio::class);
333-
expect($container->has('ErrorHeroModuleLogger'))->toBeTruthy();
333+
expect($mapCreateContainer->has('ErrorHeroModuleLogger'))->toBeTruthy();
334334
}
335335

336336
});

src/Command/BaseLoggingCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Throwable;
14+
use Webmozart\Assert\Assert;
1415

1516
use function ErrorHeroModule\isExcludedException;
1617

@@ -70,6 +71,7 @@ private function exceptionError(Throwable $throwable): int
7071
}
7172

7273
// show default view if display_errors setting = 0.
74+
Assert::isInstanceOf($this->output, OutputInterface::class);
7375
return $this->showDefaultConsoleView($this->output);
7476
}
7577

src/Command/Preview/ErrorPreviewConsoleCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class ErrorPreviewConsoleCommand extends BaseLoggingCommand
1616
{
17-
protected function configure()
17+
protected function configure(): void
1818
{
1919
$this
2020
->addArgument('type', InputArgument::OPTIONAL, 'Type of preview: exception, error, warning, fatal');

0 commit comments

Comments
 (0)