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 (#76)
by Tom
01:06
created

HtmlDriver::serialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Snapshots\Drivers;
4
5
use DOMDocument;
6
use PHPUnit\Framework\Assert;
7
use Spatie\Snapshots\Driver;
8
use Spatie\Snapshots\Exceptions\CantBeSerialized;
9
10 View Code Duplication
class HtmlDriver implements Driver
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    public function serialize($data): string
13
    {
14
        if (! is_string($data)) {
15
            throw new CantBeSerialized('Only strings can be serialized to html');
16
        }
17
18
        $domDocument = new DOMDocument('1.0');
19
        $domDocument->preserveWhiteSpace = false;
20
        $domDocument->formatOutput = true;
21
22
        @$domDocument->loadHTML($data); // to ignore HTML5 errors
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
23
24
        return $domDocument->saveHTML();
25
    }
26
27
    public function extension(): string
28
    {
29
        return 'html';
30
    }
31
32
    public function match($expected, $actual)
33
    {
34
        Assert::assertEquals($expected, $this->serialize($actual));
35
    }
36
}
37