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.

ObjectDriver::extension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Snapshots\Drivers;
4
5
use PHPUnit\Framework\Assert;
6
use Spatie\Snapshots\Driver;
7
use Symfony\Component\Serializer\Encoder\YamlEncoder;
8
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
9
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
10
use Symfony\Component\Serializer\Serializer;
11
use Symfony\Component\Yaml\Yaml;
12
13
class ObjectDriver implements Driver
14
{
15
    public function serialize($data): string
16
    {
17
        $normalizers = [
18
            new DateTimeNormalizer(),
19
            new ObjectNormalizer(),
20
        ];
21
22
        $encoders = [
23
            new YamlEncoder(),
24
        ];
25
26
        $serializer = new Serializer($normalizers, $encoders);
27
28
        // The Symfony serialized doesn't support `stdClass` yet.
29
        // This may be removed when Symfony 5.1 is released.
30
        if ($data instanceof \stdClass) {
31
            $data = (array) $data;
32
        }
33
34
        return $this->dedent(
35
            $serializer->serialize($data, 'yaml', [
36
                'yaml_inline' => 2,
37
                'yaml_indent' => 4,
38
                'yaml_flags' => Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK,
39
            ])
40
        );
41
    }
42
43
    public function extension(): string
44
    {
45
        return 'yml';
46
    }
47
48
    public function match($expected, $actual)
49
    {
50
        Assert::assertEquals($expected, $this->serialize($actual));
51
    }
52
53
    protected function dedent(string $string): string
54
    {
55
        return preg_replace('/^ {4}/m', '', $string);
56
    }
57
}
58