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
Push — master ( 60247f...aca6d9 )
by Sebastian
01:47
created

ExportCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Export\Console;
4
5
use Spatie\Export\Exporter;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Process\Process;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class ExportCommand extends Command
11
{
12
    protected $name = 'export';
13
14
    protected $description = 'Export the entire app to a static site';
15
16
    public function __construct()
17
    {
18
        parent::__construct();
19
20
        collect()
21
            ->merge(config('export.before', []))
22
            ->merge(config('export.after', []))
23
            ->keys()
24
            ->unique()
25
            ->sort()
26
            ->each(function (string $name) {
27
                $this->addOption(
28
                    "skip-{$name}",
29
                    null,
30
                    InputOption::VALUE_NONE,
31
                    "Skip the {$name} hook"
32
                );
33
            });
34
    }
35
36
    public function handle(Exporter $exporter)
37
    {
38
        $exporter->onMessage(function (string $message) {
39
            $this->comment($message, 'v');
40
        });
41
42
        $this->runBeforeHooks();
43
44
        $this->info('Starting export...');
45
46
        $exporter->export();
47
48
        if (config('export.disk')) {
49
            $this->info('Files were saved to disk `'.config('export.disk').'`');
50
        } else {
51
            $this->info('Files were saved to `dist`');
52
        }
53
54
        $this->runAfterHooks();
55
    }
56
57 View Code Duplication
    protected function runBeforeHooks()
0 ignored issues
show
Duplication introduced by
This method 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...
58
    {
59
        $beforeHooks = collect(config('export.before', []))
60
            ->reject(function (string $hook, string $name) {
61
                return $this->input->getOption("skip-{$name}");
62
            });
63
64
        if (! count($beforeHooks)) {
65
            return;
66
        }
67
68
        $this->info('Running before hooks...');
69
70
        $this->runHooks($beforeHooks);
0 ignored issues
show
Documentation introduced by
$beforeHooks is of type object<Illuminate\Support\Collection>, but the function expects a array.

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...
71
    }
72
73 View Code Duplication
    protected function runAfterHooks()
0 ignored issues
show
Duplication introduced by
This method 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...
74
    {
75
        $afterHooks = collect(config('export.after', []))
76
            ->reject(function (string $hook, string $name) {
77
                return $this->input->getOption("skip-{$name}");
78
            });
79
80
        if (! count($afterHooks)) {
81
            return;
82
        }
83
84
        $this->info('Running after hooks...');
85
86
        $this->runHooks($afterHooks);
0 ignored issues
show
Documentation introduced by
$afterHooks is of type object<Illuminate\Support\Collection>, but the function expects a array.

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...
87
    }
88
89
    protected function runHooks(array $hooks)
90
    {
91
        foreach ($hooks as $name => $command) {
92
            $this->comment("[{$name}]", 'v');
93
94
            $process = new Process($command);
95
96
            $process->mustRun();
97
98
            foreach ($process as $data) {
99
                $this->output->write($data);
100
            }
101
        }
102
    }
103
}
104