Do some code quality check and fix #126

This commit is contained in:
crazywhalecc
2023-08-20 19:51:45 +08:00
committed by Jerry Ma
parent 9c57ed6439
commit c8fa767576
104 changed files with 1040 additions and 785 deletions

View File

@@ -24,11 +24,14 @@ class CheckListHandler
* @throws FileSystemException
* @throws RuntimeException
*/
public function __construct(private InputInterface $input, private OutputInterface $output, bool $include_manual = false)
public function __construct(private readonly InputInterface $input, private readonly OutputInterface $output, bool $include_manual = false)
{
$this->loadCheckList($include_manual);
}
/**
* @throws RuntimeException
*/
public function runSingleCheck(string $item_name, int $fix_policy = FIX_POLICY_DIE): void
{
foreach ($this->check_list as $item) {
@@ -127,7 +130,10 @@ class CheckListHandler
usort($this->check_list, fn ($a, $b) => $a->level > $b->level ? -1 : ($a->level == $b->level ? 0 : 1));
}
private function emitFix(CheckResult $result)
/**
* @throws RuntimeException
*/
private function emitFix(CheckResult $result): void
{
pcntl_signal(SIGINT, function () {
$this->output->writeln('<error>You cancelled fix</error>');

View File

@@ -6,7 +6,7 @@ namespace SPC\doctor;
class CheckResult
{
public function __construct(private bool $ok, private ?string $message = null, private string $fix_item = '', private array $fix_params = [])
public function __construct(private readonly bool $ok, private readonly ?string $message = null, private string $fix_item = '', private array $fix_params = [])
{
}
@@ -40,7 +40,7 @@ class CheckResult
return $this->ok;
}
public function setFixItem(string $fix_item = '', array $fix_params = [])
public function setFixItem(string $fix_item = '', array $fix_params = []): void
{
$this->fix_item = $fix_item;
$this->fix_params = $fix_params;

View File

@@ -12,11 +12,11 @@ use SPC\exception\RuntimeException;
class LinuxMuslCheck
{
/** @noinspection PhpUnused */
#[AsCheckItem('if musl-libc is installed', limit_os: 'Linux')]
public function checkMusl(): ?CheckResult
{
$file = '/lib/ld-musl-x86_64.so.1';
$result = null;
if (file_exists($file)) {
return CheckResult::ok();
}
@@ -29,6 +29,10 @@ class LinuxMuslCheck
};
}
/**
* @throws RuntimeException
* @noinspection PhpUnused
*/
#[AsFixItem('fix-musl')]
public function fixMusl(array $distro): bool
{

View File

@@ -30,6 +30,7 @@ class LinuxToolCheckList
'bzip2', 'cmake', 'patch',
];
/** @noinspection PhpUnused */
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux')]
public function checkCliTools(): ?CheckResult
{
@@ -54,6 +55,7 @@ class LinuxToolCheckList
return CheckResult::ok();
}
/** @noinspection PhpUnused */
#[AsCheckItem('if necessary packages are installed', limit_os: 'Linux')]
public function checkSystemOSPackages(): ?CheckResult
{
@@ -67,6 +69,10 @@ class LinuxToolCheckList
return CheckResult::ok();
}
/**
* @throws RuntimeException
* @noinspection PhpUnused
*/
#[AsFixItem('install-linux-tools')]
public function fixBuildTools(array $distro, array $missing): bool
{