AbstractDatabaseCommand::getLockConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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