• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / plugin / 7778870016

04 Feb 2024 10:19AM UTC coverage: 37.918%. Remained the same
7778870016

push

github

twinh
style: php-cs-fixer

nullable_type_declaration_for_default_null_value php_unit_data_provider_static

907 of 2392 relevant lines covered (37.92%)

5.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Command/BaseCommand.php
1
<?php
2

3
namespace Miaoxing\Plugin\Command;
4

5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Exception\InvalidArgumentException;
7
use Symfony\Component\Console\Input\ArrayInput;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Wei\Ret;
11
use Wei\ServiceTrait;
12
use Wei\Wei;
13

14
abstract class BaseCommand extends Command
15
{
16
    use ServiceTrait;
17

18
    /**
19
     * @var InputInterface
20
     */
21
    protected $input;
22

23
    /**
24
     * @var OutputInterface
25
     */
26
    protected $output;
27

28
    /**
29
     * @var Wei
30
     */
31
    protected $wei;
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function __construct(?string $name = null)
37
    {
38
        $this->wei = wei();
×
39

40
        // Convert class name to command name if not provided
41
        if (null === $name && null === static::getDefaultName()) {
×
42
            $name = $this->wei->str->snake($this->wei->cls->baseName($this), ':');
×
43
        }
44

45
        parent::__construct($name);
×
46
    }
47

48
    /**
49
     * Executes the current command
50
     *
51
     * @return int|void
52
     */
53
    abstract protected function handle();
54

55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function execute(InputInterface $input, OutputInterface $output)
59
    {
60
        $this->input = $input;
×
61
        $this->output = $output;
×
62
        $code = $this->handle();
×
63
        return is_int($code) ? $code : 0;
×
64
    }
65

66
    /**
67
     * Returns all the given arguments merged with the default values.
68
     *
69
     * @return array
70
     */
71
    protected function getArguments()
72
    {
73
        return $this->input->getArguments();
×
74
    }
75

76
    /**
77
     * Returns the argument value for a given argument name.
78
     *
79
     * @param string $name The argument name
80
     *
81
     * @return string|string[]|null The argument value
82
     *
83
     * @throws InvalidArgumentException When argument given doesn't exist
84
     */
85
    protected function getArgument(string $name)
86
    {
87
        return $this->input->getArgument($name);
×
88
    }
89

90
    /**
91
     * Returns all the given options merged with the default values.
92
     *
93
     * @return array
94
     */
95
    protected function getOptions()
96
    {
97
        return $this->input->getOptions();
×
98
    }
99

100
    /**
101
     * Returns the option value for a given option name.
102
     *
103
     * @param string $name The option name
104
     *
105
     * @return bool|string|string[]|null The option value
106
     *
107
     * @throws InvalidArgumentException When option given doesn't exist
108
     */
109
    protected function getOption(string $name)
110
    {
111
        return $this->input->getOption($name);
×
112
    }
113

114
    /**
115
     * Writes a error message
116
     *
117
     * @param string $message
118
     * @param int $code
119
     * @return int
120
     */
121
    protected function err(string $message, int $code = -1)
122
    {
123
        $this->output->writeln('<error>' . $message . '</error>');
×
124
        return $code;
×
125
    }
126

127
    /**
128
     * Writes a success message
129
     *
130
     * @param string $message
131
     * @param int $code
132
     * @return int
133
     */
134
    protected function suc(string $message, int $code = 0)
135
    {
136
        $this->output->writeln('<info>' . $message . '</info>');
×
137
        return $code;
×
138
    }
139

140
    /**
141
     * Writes a message base on result data
142
     *
143
     * @param Ret $ret
144
     * @return int
145
     */
146
    protected function ret(Ret $ret): int
147
    {
148
        $type = $ret->isSuc() ? 'suc' : 'err';
×
149
        return $this->{$type}($ret->getMessage(), $ret->getCode());
×
150
    }
151

152
    /**
153
     * @param string $command
154
     * @param array $input
155
     * @return int
156
     * @throws \Exception
157
     */
158
    protected function runCommand(string $command, array $input)
159
    {
160
        $command = $this->getApplication()->find($command);
×
161
        return $command->run(new ArrayInput($input), $this->output);
×
162
    }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc