Completed
Push — master ( 5fc4df...311e23 )
by Freek
02:49
created

Object::transform()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 4
nop 1
1
<?php
2
3
namespace Spatie\BladeJavaScript\Transformers;
4
5
use Exception;
6
use Spatie\BladeJavaScript\Transformer;
7
8
class Object implements Transformer
9
{
10
    public function canTransform($value): string
11
    {
12
        return is_object($value);
13
    }
14
15
    public function transform($value)
16
    {
17
        if ($value instanceof JsonSerializable || $value instanceof StdClass) {
0 ignored issues
show
Bug introduced by
The class Spatie\BladeJavaScript\T...ormers\JsonSerializable 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...
Bug introduced by
The class Spatie\BladeJavaScript\Transformers\StdClass 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...
18
            return json_encode($value);
19
        }
20
21
        if (method_exists($value, 'toJson')) {
22
            return $value;
23
        }
24
25
        if (!method_exists($value, '__toString')) {
26
            throw new Exception('Cannot transform this object to JavaScript.');
27
        }
28
29
        return "'{$value}'";
30
    }
31
}
32