AbstractDatabaseCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLockConfig() 0 3 1
A runPhpCommand() 0 4 1
A __construct() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\CLI\Command\Db;
6
7
use Shlinkio\Shlink\CLI\Command\Util\AbstractLockedCommand;
8
use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig;
9
use Symfony\Component\Console\Helper\ProcessHelper;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Lock\LockFactory;
12
use Symfony\Component\Process\PhpExecutableFinder;
13
14
abstract class AbstractDatabaseCommand extends AbstractLockedCommand
15
{
16
    private ProcessHelper $processHelper;
17
    private string $phpBinary;
18
19 5
    public function __construct(LockFactory $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder)
20
    {
21 5
        parent::__construct($locker);
22 5
        $this->processHelper = $processHelper;
23 5
        $this->phpBinary = $phpFinder->find(false) ?: 'php';
24 5
    }
25
26 2
    protected function runPhpCommand(OutputInterface $output, array $command): void
27
    {
28 2
        $command = [$this->phpBinary, ...$command, '--no-interaction'];
29 2
        $this->processHelper->mustRun($output, $command);
0 ignored issues
show
Bug introduced by
$command of type array<integer,array|string> is incompatible with the type Symfony\Component\Process\Process|string expected by parameter $cmd of Symfony\Component\Consol...rocessHelper::mustRun(). ( Ignorable by Annotation )

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

29
        $this->processHelper->mustRun($output, /** @scrutinizer ignore-type */ $command);
Loading history...
30 2
    }
31
32 5
    protected function getLockConfig(): LockedCommandConfig
33
    {
34 5
        return new LockedCommandConfig($this->getName(), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getName() can also be of type null; however, parameter $lockName of Shlinkio\Shlink\CLI\Comm...ndConfig::__construct() 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

34
        return new LockedCommandConfig(/** @scrutinizer ignore-type */ $this->getName(), true);
Loading history...
35
    }
36
}
37