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

CommandCore   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
c 0
b 0
f 0
dl 0
loc 22
ccs 5
cts 8
cp 0.625
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A __construct() 0 3 1
A callAction() 0 5 1
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