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.
Completed
Pull Request — master (#79)
by Ian
01:41
created

Snapshot::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Spatie\Snapshots;
4
5
use Spatie\Snapshots\Driver;
6
use Spatie\Snapshots\Filesystem;
7
8
class Snapshot
9
{
10
    private string $id;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
11
12
    private Filesystem $filesystem;
13
14
    private Driver $driver;
15
16
    public function __construct(
17
        string $id,
18
        Filesystem $filesystem,
19
        Driver $driver
20
    ) {
21
        $this->id = $id;
22
        $this->filesystem = $filesystem;
23
        $this->driver = $driver;
24
    }
25
26
    public static function forTestCase(
27
        string $id,
28
        string $directory,
29
        Driver $driver
30
    ): self {
31
        $filesystem = Filesystem::inDirectory($directory);
32
33
        return new self($id, $filesystem, $driver);
34
    }
35
36
    public function id(): string
37
    {
38
        return $this->id;
39
    }
40
41
    public function filename(): string
42
    {
43
        $file = $this->id.'.'.$this->driver->extension();
44
        // Remove anything which isn't a word, whitespace, number
45
        // or any of the following caracters -_~,;[]().
46
        $file = preg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $file);
47
        // Remove any runs of periods
48
        $file = preg_replace("([\.]{2,})", '', $file);
49
50
        return $file;
51
    }
52
53
    public function exists(): bool
54
    {
55
        return $this->filesystem->has($this->filename());
56
    }
57
58
    public function assertMatches($actual)
59
    {
60
        $this->driver->match($this->filesystem->read($this->filename()), $actual);
61
    }
62
63
    public function create($actual)
64
    {
65
        $this->filesystem->put($this->filename(), $this->driver->serialize($actual));
66
    }
67
}
68