Passed
Push — main ( bfdb6b...82683d )
by Aspirant
01:39
created

Home   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 29
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 17 5
A configure() 0 8 1
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')) : null;
33
        $perPage = $input->getArgument('perPage') ? (int)trim($input->getArgument('perPage')) : null;
34
35
        $result = (new RevisionAPI())->listAPI($tableName, (int)$recordId, $page, $perPage);
0 ignored issues
show
Bug introduced by
It seems like $page can also be of type null; however, parameter $page of aspirantzhang\octopusRev...\RevisionAPI::listAPI() does only seem to accept integer, 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

35
        $result = (new RevisionAPI())->listAPI($tableName, (int)$recordId, /** @scrutinizer ignore-type */ $page, $perPage);
Loading history...
Bug introduced by
It seems like $perPage can also be of type null; however, parameter $perPage of aspirantzhang\octopusRev...\RevisionAPI::listAPI() does only seem to accept integer, 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

35
        $result = (new RevisionAPI())->listAPI($tableName, (int)$recordId, $page, /** @scrutinizer ignore-type */ $perPage);
Loading history...
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