Passed
Push — master ( 534a00...719b7c )
by Yaroslav
02:31
created

HasDuskReporter::reportAppend()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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 page.
44
     *
45
     * @param Browser $browser
46
     * @param string|null $pageName
47
     * @param array $options
48
     *
49
     * @return Browser
50
     */
51
    public function reportUserSeePage(Browser $browser, ?string $pageName = 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
            static::$duskReporter->p(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 $content of LaravelDuskReporter\Gene...ReportFileContract::p() does only seem to accept 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

59
            static::$duskReporter->p(/** @scrutinizer ignore-type */ trans('dusk-reporter::report.user_see_page', [
Loading history...
60
                '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

60
                '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...
61
            ]));
62
        }
63
64
        return $browser;
65
    }
66
}
67