Passed
Push — master ( d2ebdc...958928 )
by Bogdan
05:05
created

PrimitiveWrapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 26
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B wrap() 0 20 6
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;
17
18
19
use V8\BooleanValue;
20
use V8\Context;
21
use V8\Isolate;
22
use V8\NullValue;
23
use V8\NumberValue;
24
use V8\StringValue;
25
use function is_bool;
26
use function is_float;
27
use function is_int;
28
use function is_null;
29
use function is_string;
30
31
32
class PrimitiveWrapper implements WrapperInterface
33
{
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function wrap(Isolate $isolate, Context $context, $value)
38
    {
39
        if (is_null($value)) {
40
            return new NullValue($isolate);
41
        }
42
43
        if (is_bool($value)) {
44
            return new BooleanValue($isolate, $value);
45
        }
46
47
        if (is_string($value)) {
48
            return new StringValue($isolate, $value);
49
        }
50
51
        if (is_int($value) || is_float($value)) {
52
            return new NumberValue($isolate, $value);
53
        }
54
55
        throw new WrapperException('Vale type ' . gettype($value) . ' is not supported');
56
    }
57
}
58