GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

JsonDriver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 12 3
A extension() 0 4 1
A match() 0 8 2
1
<?php
2
3
namespace Spatie\Snapshots\Drivers;
4
5
use PHPUnit\Framework\Assert;
6
use Spatie\Snapshots\Driver;
7
use Spatie\Snapshots\Exceptions\CantBeSerialized;
8
9
class JsonDriver implements Driver
10
{
11
    public function serialize($data): string
12
    {
13
        if (is_string($data)) {
14
            $data = json_decode($data);
15
        }
16
17
        if (is_resource($data)) {
18
            throw new CantBeSerialized('Resources can not be serialized to json');
19
        }
20
21
        return json_encode($data, JSON_PRETTY_PRINT)."\n";
22
    }
23
24
    public function extension(): string
25
    {
26
        return 'json';
27
    }
28
29
    public function match($expected, $actual)
30
    {
31
        if (is_array($actual)) {
32
            $actual = json_encode($actual, JSON_PRETTY_PRINT)."\n";
33
        }
34
35
        Assert::assertJsonStringEqualsJsonString($expected, $actual);
36
    }
37
}
38