Home::execute()   A
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
cc 5
eloc 12
c 2
b 1
f 2
nc 12
nop 2
dl 0
loc 17
rs 9.5555
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 Home extends Command
15
{
16
    protected function configure()
17
    {
18
        $this->setName('revision:list')
19
            ->addArgument('tableName', Argument::REQUIRED, "Table name")
20
            ->addArgument('recordId', Argument::REQUIRED, "Record Id")
21
            ->addArgument('page', Argument::OPTIONAL, "Current page number")
22
            ->addArgument('perPage', Argument::OPTIONAL, "Per page number")
23
            ->setDescription('Get the revision list of a specific record of a table');
24
    }
25
26
    protected function execute(Input $input, Output $output)
27
    {
28
        $output->writeln('<info>Processing...</info>');
29
30
        $tableName = trim($input->getArgument('tableName'));
0 ignored issues
show
Bug introduced by
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

30
        $tableName = trim(/** @scrutinizer ignore-type */ $input->getArgument('tableName'));
Loading history...
31
        $recordId = trim($input->getArgument('recordId'));
32
        $page = $input->getArgument('page') ? (int)trim($input->getArgument('page')) : 1;
33
        $perPage = $input->getArgument('perPage') ? (int)trim($input->getArgument('perPage')) : 5;
34
35
        $result = (new RevisionAPI())->listAPI($tableName, (int)$recordId, (int)$page, (int)$perPage);
36
        if ($result['success'] === true) {
37
            $list = $result['data']['dataSource'];
38
            foreach ($list as $item) {
39
                $output->writeln('<comment> - [' . $item['id'] . '] ' . $item['title'] . ' @ ' . $item['create_time'] . '</comment>');
40
            }
41
        } else {
42
            $output->writeln('<error>' . $result['message'] . '</error>');
43
        }
44
    }
45
}
46