Passed
Push — master ( f1e8a4...0fff4f )
by De Cramer
07:22
created

JsonConfig::getValidationConstraints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace oliverde8\ComfyBundle\Model;
4
5
use Symfony\Component\Validator\Constraints\Json;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints\Json was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class JsonConfig extends TextConfig
8
{
9
    /**
10
     * @inheritDoc
11
     */
12
    protected function getValidationConstraints()
13
    {
14
        return new Json();
15
    }
16
17
    protected function serialize($value): ?string
18
    {
19
        dump($value);
20
        return !is_null($value) ? json_encode($value) : null;
21
    }
22
23
    public function deserialize(?string $value)
24
    {
25
        dump($value);
26
        dump(json_decode($value, true));
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        dump(json_decode(/** @scrutinizer ignore-type */ $value, true));
Loading history...
27
        return !is_null($value) ? json_decode($value, true) : null;
28
    }
29
}
30