Application::ajax()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Terminal;
4
5
use Exception;
6
use Illuminate\Console\Application as ConsoleApplication;
7
use Illuminate\Http\Request;
8
use Recca0120\Terminal\Contracts\TerminalCommand;
9
use Symfony\Component\Console\Formatter\OutputFormatter;
10
use Symfony\Component\Console\Input\StringInput;
11
use Symfony\Component\Console\Output\BufferedOutput;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class Application extends ConsoleApplication
15
{
16
    /**
17
     * Run an Artisan console command by name.
18
     *
19
     * @param string $command
20
     * @param array $parameters
21
     * @param OutputInterface $outputBuffer
22 2
     * @return int
23
     * @throws Exception
24 2
     */
25 1
    public function call($command, array $parameters = [], $outputBuffer = null)
26 1
    {
27
        if ($this->ajax() === true) {
28 1
            $this->lastOutput = $outputBuffer ?: new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true, new OutputFormatter(true));
0 ignored issues
show
Documentation Bug introduced by
$outputBuffer ?: new \Sy...\OutputFormatter(true)) is of type object<Symfony\Component...Output\OutputInterface>, but the property $lastOutput was declared to be of type object<Symfony\Component...\Output\BufferedOutput>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
29 1
            $this->setCatchExceptions(true);
30
        } else {
31
            $this->lastOutput = $outputBuffer ?: new BufferedOutput();
0 ignored issues
show
Documentation Bug introduced by
$outputBuffer ?: new \Sy...Output\BufferedOutput() is of type object<Symfony\Component...Output\OutputInterface>, but the property $lastOutput was declared to be of type object<Symfony\Component...\Output\BufferedOutput>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
32 2
            $this->setCatchExceptions(false);
33 2
        }
34 2
35
        $command .= ' '.implode(' ', $parameters);
36 2
        $input = new StringInput($command);
37
        $input->setInteractive(false);
38 2
        $result = $this->run($input, $this->lastOutput);
39
        $this->setCatchExceptions(true);
40 2
41
        return $result;
42
    }
43
44
    /**
45
     * Resolve an array of commands through the application.
46
     *
47
     * @param array|mixed $commands
48
     * @return $this
49 2
     */
50
    public function resolveCommands($commands)
51 2
    {
52 1
        return parent::resolveCommands(array_filter($commands, static function ($command) {
53 2
            return is_subclass_of($command, TerminalCommand::class);
54
        }));
55
    }
56
57
    /**
58
     * ajax.
59
     *
60
     * @return bool
61 2
     */
62
    private function ajax()
63 2
    {
64
        $request = $this->laravel['request'] ?: Request::capture();
65 2
66
        return $request->ajax();
67
    }
68
}
69