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 (#101)
by Tom
07:52
created

SnapshotsServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 20 4
1
<?php
2
3
namespace Spatie\Snapshots\Laravel;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Testing\TestResponse;
7
use RuntimeException;
8
use Spatie\Snapshots\MatchesSnapshots;
9
10
class SnapshotsServiceProvider extends ServiceProvider
11
{
12
    public function register()
13
    {
14
        TestResponse::macro('assertMatchesHtmlSnapshot', function () {
15
            $backtrace = collect(debug_backtrace());
16
            $index = $backtrace->search(function (array $call): bool {
17
                return ($call['class'] ?? null) === TestResponse::class
18
                    && ($call['function'] ?? null) === '__call'
19
                    && ($call['args'][0] ?? null) === 'assertMatchesHtmlSnapshot';
20
            });
21
            $test = $backtrace->get($index+1);
22
23
            if(!isset(class_uses($test['object'])[MatchesSnapshots::class])) {
24
                throw new RuntimeException(sprintf('%s does not use %s', $test['class'], MatchesSnapshots::class));
25
            }
26
27
            /** @var TestResponse $response */
28
            $response = $this;
29
            call_user_func([$test['object'], 'assertMatchesHtmlSnapshot'], $response->getContent());
30
        });
31
    }
32
}
33