Issues (10)

src/command/Restore.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace aspirantzhang\octopusRevision\command;
6
7
use think\console\Command;
8
use think\console\Input;
9
use think\console\input\Argument;
10
use think\console\Output;
11
use think\Exception;
12
use aspirantzhang\octopusRevision\RevisionAPI;
13
14
class Restore extends Command
15
{
16
    protected function configure()
17
    {
18
        $this->setName('revision:restore')
19
            ->addArgument('tableName', Argument::REQUIRED, "Table name")
20
            ->addArgument('originalId', Argument::REQUIRED, "Original Id")
21
            ->addArgument('revisionId', Argument::REQUIRED, "Revision id")
22
            ->setDescription('Restore a record from a specific revision of a table');
23
    }
24
25
    protected function execute(Input $input, Output $output)
26
    {
27
        $output->writeln('<info>Processing...</info>');
28
29
        $tableName = trim($input->getArgument('tableName'));
0 ignored issues
show
It seems like $input->getArgument('tableName') can also be of type think\console\input\Argument; however, parameter $string of trim() 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

29
        $tableName = trim(/** @scrutinizer ignore-type */ $input->getArgument('tableName'));
Loading history...
30
        $originalId = trim($input->getArgument('originalId'));
31
        $revisionId = trim($input->getArgument('revisionId'));
32
33
        try {
34
            (new RevisionAPI())->restoreAPI($tableName, (int)$originalId, (int)$revisionId);
35
            $output->writeln('<info>...Complete successfully.</info>');
36
        } catch (Exception $e) {
37
            $output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
38
        }
39
    }
40
}
41