Passed
Push — master ( 3c47cb...69fef7 )
by Yaroslav
02:16
created

HasDuskReporter::reportUserSee()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.6111
cc 5
nc 5
nop 3
crap 30
1
<?php
2
3
namespace LaravelDuskReporter;
4
5
use Illuminate\Support\Str;
6
use Laravel\Dusk\Browser;
7
use LaravelDuskReporter\Generation\ReportFileContract;
8
9
trait HasDuskReporter
10
{
11
    public static ?ReportFileContract $duskReporter = null;
12
13
    /**
14
     * Set dusk reporter.
15
     *
16
     * @param ReportFileContract $reporter
17
     *
18
     * @return void
19
     */
20
    public static function withDuskReporter(?ReportFileContract $reporter): void
21
    {
22
        static::$duskReporter = $reporter;
23
    }
24
25
    /**
26
     * Callback to add text to report file.
27
     *
28
     * @param Browser $browser
29
     * @param \Closure $callback
30
     *
31
     * @return Browser
32
     */
33
    public function reportAppend(Browser $browser, \Closure $callback): Browser
34
    {
35
        if (!is_null(static::$duskReporter)) {
36
            call_user_func($callback, static::$duskReporter, $browser);
37
        }
38
39
        return $browser;
40
    }
41
42
    /**
43
     * Add to report information about current screen.
44
     *
45
     * @param Browser $browser
46
     * @param string|null $caption
47
     * @param array $options
48
     *
49
     * @return Browser
50
     */
51
    public function reportUserSee(Browser $browser, ?string $caption = null, array $options = []): Browser
52
    {
53
        if (!is_null(static::$duskReporter)) {
54
            if (isset($options['screenshot']) && is_array($options['screenshot'])) {
55
                call_user_func_array([ static::$duskReporter, 'screenshot' ], $options['screenshot']);
56
            } else {
57
                static::$duskReporter->screenshotWithCombineScreen($browser);
58
            }
59
            if ($caption) {
60
                static::$duskReporter->p($caption);
61
            }
62
        }
63
64
        return $browser;
65
    }
66
67
    /**
68
     * Add to report information about current page.
69
     *
70
     * @param Browser $browser
71
     * @param string|null $pageName
72
     * @param array $options
73
     *
74
     * @return Browser
75
     */
76
    public function reportUserSeePage(Browser $browser, ?string $pageName = null, array $options = []): Browser
77
    {
78
        return $this->reportUserSee(
79
            $browser,
80
            trans('dusk-reporter::report.user_see_page', [
0 ignored issues
show
Bug introduced by
It seems like trans('dusk-reporter::re...his)), 'Page'), ' ')))) can also be of type array and array; however, parameter $caption of LaravelDuskReporter\HasD...porter::reportUserSee() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

80
            /** @scrutinizer ignore-type */ trans('dusk-reporter::report.user_see_page', [
Loading history...
81
                'page' => $pageName ?? Str::title(Str::kebab(Str::beforeLast(class_basename(get_class($this)), 'Page'), ' ')),
0 ignored issues
show
Unused Code introduced by
The call to Illuminate\Support\Str::kebab() has too many arguments starting with ' '. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
                'page' => $pageName ?? Str::title(Str::/** @scrutinizer ignore-call */ kebab(Str::beforeLast(class_basename(get_class($this)), 'Page'), ' ')),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
82
            ]),
83
            $options
84
        );
85
    }
86
}
87