Completed
Push — master ( 474dd3...85d4eb )
by Bogdan
02:56
created

JsonExtractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 20
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A extract() 0 14 3
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\Extractors\PlainExtractors;
17
18
19
use Pinepain\JsSandbox\Extractors\Definition\PlainExtractorDefinitionInterface;
20
use Pinepain\JsSandbox\Extractors\ExtractorException;
21
use Pinepain\JsSandbox\Extractors\ExtractorInterface;
22
use V8\Context;
23
use V8\Exceptions\TryCatchException;
24
use V8\JSON;
25
use V8\Value;
26
27
28
class JsonExtractor implements PlainExtractorInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function extract(Context $context, Value $value, PlainExtractorDefinitionInterface $definition, ExtractorInterface $extractor)
34
    {
35
        try {
36
            $json = JSON::stringify($context, $value);
37
38
            if ($definition->getNext()) {
39
                $extractor->extract($context, $value, $definition->getNext());
40
            }
41
42
            return $json;
43
        } catch (TryCatchException $e) {
0 ignored issues
show
Bug introduced by
The class V8\Exceptions\TryCatchException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
44
            throw new ExtractorException("Failed to stringify value: " . $e->getMessage());
45
        }
46
    }
47
}
48