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

miaoxing / plugin / 8096252018

28 Feb 2024 12:39AM UTC coverage: 40.426%. Remained the same
8096252018

push

github

twinh
fix(plugin, php8): Creation of dynamic property xxx is deprecated

1007 of 2491 relevant lines covered (40.43%)

6.05 hits per line

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

40.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
#[\AllowDynamicProperties]
15
abstract class BaseCommand extends Command
16
{
17
    use ServiceTrait;
18

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

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

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

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

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

46
        parent::__construct($name);
1✔
47
    }
48

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

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

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

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

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

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

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

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

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

153
    /**
154
     * @param string $command
155
     * @param array $input
156
     * @return int
157
     * @throws \Exception
158
     */
159
    protected function runCommand(string $command, array $input)
160
    {
161
        $command = $this->getApplication()->find($command);
×
162
        return $command->run(new ArrayInput($input), $this->output);
×
163
    }
164
}
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

© 2025 Coveralls, Inc