Passed
Push — wip-public-release ( a47743...14cdbd )
by Bogdan
02:52
created

NativeFunctionWrapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 48
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A call() 0 9 2
A __invoke() 0 4 1
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\ObjectValue;
23
24
25
class NativeFunctionWrapper implements NativeFunctionWrapperInterface
26
{
27
    /**
28
     * @var Context
29
     */
30
    private $context;
31
    /**
32
     * @var ObjectValue
33
     */
34
    private $recv;
35
    /**
36
     * @var FunctionObject
37
     */
38
    private $function_object;
39
    /**
40
     * @var WrapperInterface
41
     */
42
    private $wrapper;
43
44
    public function __construct(Context $context, ObjectValue $recv, FunctionObject $function_object, WrapperInterface $wrapper)
45
    {
46
        $this->context         = $context;
47
        $this->recv            = $recv;
48
        $this->function_object = $function_object;
49
        $this->wrapper         = $wrapper;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function call(...$args)
56
    {
57
        $args_for_call = [];
58
        foreach ($args as $arg) {
59
            $args_for_call[] = $this->wrapper->wrap($this->context->getIsolate(), $this->context, $arg);
60
        }
61
62
        return $this->function_object->call($this->context, $this->recv, $args_for_call);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function __invoke(...$args)
69
    {
70
        return $this->call(... $args);
71
    }
72
}
73