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

PrimitiveWrapper::wrap()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 10
cp 0
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 10
nc 5
nop 3
crap 42
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