FunctionExceptionHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 4
crap 12
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Wrappers\FunctionComponents;
17
18
19
use Pinepain\JsSandbox\Specs\ThrowSpec\ThrowSpecListInterface;
20
use Throwable;
21
use V8\Context;
22
use V8\Isolate;
23
24
25
class FunctionExceptionHandler implements FunctionExceptionHandlerInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function handle(Isolate $isolate, Context $context, Throwable $throwable, ThrowSpecListInterface $throw_specs): bool
31
    {
32
        foreach ($throw_specs->getThrowSpecs() as $throw_spec) {
33
            // TODO: what about if ($throw_spec->canHandle($throwable)) { ... }, anyway, there are already one function call - $throw_spec->getClass()
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
35
            $filter_class = $throw_spec->getClass();
36
37
            if (is_subclass_of($throwable, $filter_class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $filter_class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
38
                //if ($throwable instanceof $filter_class) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
                $throw_spec->getHandler()->handle($isolate, $context, $throwable);
40
41
                // TODO: as handling mean to re-throw exception with maybe different desc, return statement here MAY be redundant
42
                return true;
43
            }
44
        }
45
46
        return false;
47
    }
48
}
49