Passed
Pull Request — master (#1111)
by Aleksei
10:58
created

CommandCore::callAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Console;
6
7
use Spiral\Core\Attribute\Scope as ScopeAttribute;
8
use Spiral\Core\CoreInterface;
9
use Spiral\Core\InvokerInterface;
10
use Spiral\Interceptors\Context\CallContext;
11
use Spiral\Interceptors\HandlerInterface;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
#[ScopeAttribute('console.command')]
16
final class CommandCore implements CoreInterface, HandlerInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Spiral\Core\CoreInterface has been deprecated: Use {@see HandlerInterface} instead. ( Ignorable by Annotation )

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

16
final class CommandCore implements /** @scrutinizer ignore-deprecated */ CoreInterface, HandlerInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
17
{
18 98
    public function __construct(
19
        private readonly InvokerInterface $invoker,
20
    ) {
21 98
    }
22
23
    /**
24
     * @param array{input: InputInterface, output: OutputInterface, command: Command}|array $parameters
25
     */
26
    public function callAction(string $controller, string $action, array $parameters = []): int
27
    {
28
        $command = $parameters['command'];
29
30
        return (int)$this->invoker->invoke([$command, $action]);
31
    }
32
33 98
    public function handle(CallContext $context): int
34
    {
35 98
        $callable = $context->getTarget()->getCallable() ?? throw new \RuntimeException('Command action not found');
36 98
        return (int)$this->invoker->invoke($callable, $context->getArguments());
37
    }
38
}
39