VisualDiffServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace BeyondCode\VisualDiff;
4
5
use Laravel\Dusk\Browser;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Foundation\Testing\TestResponse;
8
9
class VisualDiffServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     */
14
    public function boot()
15
    {
16
        if ($this->app->runningInConsole()) {
17
            $this->publishes([
18
                __DIR__ . '/../config/config.php' => config_path('visualdiff.php'),
19
            ], 'config');
20
        }
21
    }
22
23
    /**
24
     * Register the application services.
25
     */
26
    public function register()
27
    {
28
        $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'visualdiff');
29
30 View Code Duplication
        TestResponse::macro('visualDiff', function ($name = null, $resolutions = null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
31
32
            if (is_null($name)) {
33
                // Guess the test name from the backtrace
34
                $name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)[4]['function'];
35
            }
36
37
            $testResolutions = config('visualdiff.resolutions');
38
39
            if (! is_null($resolutions)) {
40
                $testResolutions = $resolutions;
41
            }
42
43
            $tester = new VisualDiffTester($this->content(), $name, $testResolutions);
0 ignored issues
show
Bug introduced by
The method content() does not seem to exist on object<BeyondCode\Visual...ualDiffServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
45
            $tester->setScreenshotOutputPath(config('visualdiff.screenshot_path'));
46
            $tester->setDiffOutputPath(config('visualdiff.diff_path'));
47
48
            $tester->createDiffs();
49
50
            return $this;
51
        });
52
53 View Code Duplication
        TestResponse::macro('visualDiffForResolutions', function (array $resolutions, $name = null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
54
            if (is_null($name)) {
55
                // Guess the test name from the backtrace
56
                $name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)[4]['function'];
57
            }
58
59
            return $this->visualDiff($name, $resolutions);
0 ignored issues
show
Bug introduced by
The method visualDiff() does not seem to exist on object<BeyondCode\Visual...ualDiffServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        });
61
62
        if (class_exists(Browser::class)) {
63 View Code Duplication
            Browser::macro('visualDiff', function ($name = null, $resolutions = null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
64
65
                if (is_null($name)) {
66
                    // Guess the test name from the backtrace
67
                    $name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7)[6]['function'];
68
                }
69
70
                $testResolutions = config('visualdiff.resolutions');
71
72
                if (! is_null($resolutions)) {
73
                    $testResolutions = $resolutions;
74
                }
75
76
                $tester = new DuskVisualDiffTester('', $name, $testResolutions);
77
                $tester->setBrowser($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<BeyondCode\VisualDi...ualDiffServiceProvider>, but the function expects a object<Laravel\Dusk\Browser>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
79
                $tester->setScreenshotOutputPath(config('visualdiff.screenshot_path'));
80
                $tester->setDiffOutputPath(config('visualdiff.diff_path'));
81
82
                $tester->createDiffs();
83
84
                return $this;
85
            });
86
87 View Code Duplication
            Browser::macro('visualDiffForResolutions', function (array $resolutions, $name = null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
88
                if (is_null($name)) {
89
                    // Guess the test name from the backtrace
90
                    $name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7)[6]['function'];
91
                }
92
93
                return $this->visualDiff($name, $resolutions);
0 ignored issues
show
Bug introduced by
The method visualDiff() does not seem to exist on object<BeyondCode\Visual...ualDiffServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
            });
95
        }
96
    }
97
}
98