Passed
Pull Request — 0.9.x (#324)
by Shinji
01:53
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Reli\Lib\Loop\LoopMiddleware;
15
16
use Reli\Lib\Log\Log;
17
use Reli\Lib\Loop\LoopMiddlewareInterface;
18
19
class ExitLoopOnSpecificExceptionMiddleware implements LoopMiddlewareInterface
20
{
21
    /** @param list<class-string<\Throwable>> $exception_names */
0 ignored issues
show
Bug introduced by
The type Reli\Lib\Loop\LoopMiddleware\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
    public function __construct(
23
        private array $exception_names,
24
        private LoopMiddlewareInterface $chain,
25
    ) {
26
    }
27
    public function invoke(): bool
28
    {
29
        try {
30
            return $this->chain->invoke();
31
        } catch (\Throwable $e) {
32
            foreach ($this->exception_names as $exception_name) {
33
                /** @psalm-suppress DocblockTypeContradiction */
34
                if (is_a($e, $exception_name)) {
35
                    Log::debug(
36
                        $e->getMessage(),
37
                        [
38
                            'trace' => $e->getTrace()
39
                        ]
40
                    );
41
                    return false;
42
                }
43
            }
44
            throw $e;
45
        }
46
    }
47
}
48