Save   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
c 1
b 0
f 1
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 2
A configure() 0 7 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 Save extends Command
15
{
16
    protected function configure()
17
    {
18
        $this->setName('revision:save')
19
            ->addArgument('revisionTitle', Argument::REQUIRED, "Revision title")
20
            ->addArgument('tableName', Argument::REQUIRED, "Table name")
21
            ->addArgument('originalId', Argument::REQUIRED, "Original id")
22
            ->setDescription('Save a revision of a specific record of a table');
23
    }
24
25
    protected function execute(Input $input, Output $output)
26
    {
27
        $output->writeln('<info>Processing...</info>');
28
29
        $revisionTitle = trim($input->getArgument('revisionTitle'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('revisionTitle') 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
        $revisionTitle = trim(/** @scrutinizer ignore-type */ $input->getArgument('revisionTitle'));
Loading history...
30
        $tableName = trim($input->getArgument('tableName'));
31
        $originalId = trim($input->getArgument('originalId'));
32
33
        try {
34
            $revisionId = (new RevisionAPI())->saveAPI($revisionTitle, $tableName, (int)$originalId);
35
            $output->writeln('<comment>Revision ID: ' . $revisionId . '</comment>');
36
            $output->writeln('<info>...Complete successfully.</info>');
37
        } catch (Exception $e) {
38
            $output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
39
        }
40
    }
41
}
42