NativeFunctionWrapper::call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
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\NativeWrappers;
17
18
19
use Pinepain\JsSandbox\Wrappers\WrapperInterface;
20
use V8\Context;
21
use V8\FunctionObject;
22
use V8\Isolate;
23
use V8\ObjectValue;
24
use V8\Value;
25
26
27
class NativeFunctionWrapper extends NativeObjectWrapper implements NativeFunctionWrapperInterface
28
{
29
    /**
30
     * @var ObjectValue
31
     */
32
    protected $recv;
33
34 2
    public function __construct(Isolate $isolate, Context $context, FunctionObject $target, WrapperInterface $wrapper, ObjectValue $recv)
35
    {
36 2
        parent::__construct($isolate, $context, $target, $wrapper);
37 2
        $this->recv = $recv;
38 2
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function call(...$args): Value
44
    {
45 1
        $args_for_call = [];
46 1
        foreach ($args as $arg) {
47 1
            $args_for_call[] = $this->wrapper->wrap($this->context->getIsolate(), $this->context, $arg);
48
        }
49
50 1
        assert($this->target instanceof FunctionObject);
0 ignored issues
show
Bug introduced by
The class V8\FunctionObject does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
52 1
        return $this->target->call($this->context, $this->recv, $args_for_call);
53
    }
54
}
55