Skip to content

Commit 800002c

Browse files
committed
update: run inspect check
1 parent 4809e12 commit 800002c

17 files changed

+66
-33
lines changed

src/Application.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function commands(array $commands)
185185
* @return $this
186186
* @throws \InvalidArgumentException
187187
*/
188-
public function addCommand(string $name, $handler = null)
188+
public function addCommand(string $name, $handler = null): self
189189
{
190190
return $this->command($name, $handler);
191191
}
@@ -209,7 +209,7 @@ public function addGroup(string $name, string $controller = null)
209209
* @return $this
210210
* @throws \InvalidArgumentException
211211
*/
212-
public function registerCommands(string $namespace, string $basePath)
212+
public function registerCommands(string $namespace, string $basePath): self
213213
{
214214
$length = \strlen($basePath) + 1;
215215
$iterator = Helper::directoryIterator($basePath, $this->getFileFilter());
@@ -229,7 +229,7 @@ public function registerCommands(string $namespace, string $basePath)
229229
* @return $this
230230
* @throws \InvalidArgumentException
231231
*/
232-
public function registerGroups(string $namespace, string $basePath)
232+
public function registerGroups(string $namespace, string $basePath): self
233233
{
234234
$length = \strlen($basePath) + 1;
235235
$iterator = Helper::directoryIterator($basePath, $this->getFileFilter());
@@ -271,6 +271,7 @@ protected function getFileFilter(): callable
271271

272272
/**
273273
* @inheritdoc
274+
* @throws \ReflectionException
274275
* @throws \InvalidArgumentException
275276
*/
276277
protected function dispatch(string $name)

src/Base/AbstractApplication.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ protected function beforeRun()
141141
/**
142142
* run app
143143
* @param bool $exit
144+
* @throws \InvalidArgumentException
144145
*/
145146
public function run($exit = true)
146147
{
@@ -251,6 +252,7 @@ protected function runtimeCheck()
251252

252253
/**
253254
* register error handle
255+
* @throws \InvalidArgumentException
254256
*/
255257
protected function registerErrorHandle()
256258
{
@@ -270,6 +272,7 @@ protected function registerErrorHandle()
270272
* @param string $str
271273
* @param string $file
272274
* @param int $line
275+
* @throws \InvalidArgumentException
273276
*/
274277
public function handleError(int $num, string $str, string $file, int $line)
275278
{
@@ -280,6 +283,7 @@ public function handleError(int $num, string $str, string $file, int $line)
280283
/**
281284
* 运行异常处理
282285
* @param \Exception|\Throwable $e
286+
* @throws \InvalidArgumentException
283287
*/
284288
public function handleException($e)
285289
{
@@ -542,7 +546,7 @@ public function getCommandMessage($name, $default = null)
542546
* @param string $message
543547
* @return $this
544548
*/
545-
public function addCommandMessage($name, $message)
549+
public function addCommandMessage($name, $message): self
546550
{
547551
if ($name && $message) {
548552
$this->commandMessages[$name] = $message;
@@ -556,7 +560,7 @@ public function addCommandMessage($name, $message)
556560
* @param string|array $aliases
557561
* @return $this
558562
*/
559-
public function addCommandAliases(string $name, $aliases)
563+
public function addCommandAliases(string $name, $aliases): self
560564
{
561565
if (!$name || !$aliases) {
562566
return $this;

src/Components/ArtFont.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function font(string $name, string $group = null): string
172172
* @param string $path
173173
* @return $this
174174
*/
175-
public function addGroup(string $group, string $path)
175+
public function addGroup(string $group, string $path): self
176176
{
177177
$group = trim($group, '_');
178178

@@ -192,7 +192,7 @@ public function addGroup(string $group, string $path)
192192
* @param string $path
193193
* @return $this
194194
*/
195-
public function setGroup(string $group, string $path)
195+
public function setGroup(string $group, string $path): self
196196
{
197197
$group = trim($group, '_');
198198

@@ -211,7 +211,7 @@ public function setGroup(string $group, string $path)
211211
* @param string|null $group
212212
* @return $this
213213
*/
214-
public function addFont(string $name, string $file, string $group = null)
214+
public function addFont(string $name, string $file, string $group = null): self
215215
{
216216
$group = $group ?: self::DEFAULT_GROUP;
217217

@@ -230,7 +230,7 @@ public function addFont(string $name, string $file, string $group = null)
230230
* @param string $content
231231
* @return $this
232232
*/
233-
public function addFontContent(string $name, string $content)
233+
public function addFontContent(string $name, string $content): self
234234
{
235235
if ($name && ($content = trim($content))) {
236236
$this->fontContents[$name] = $content;

src/Components/Download.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(string $url, string $saveAs, $type = self::PROGRESS_
7171
* start download
7272
* @return $this
7373
*/
74-
public function start()
74+
public function start(): self
7575
{
7676
if (!$this->url || !$this->saveAs) {
7777
Show::liteError("Please the property 'url' and 'saveAs'.", 1);
@@ -155,7 +155,7 @@ public function progressShow($notifyCode, $severity, $message, $messageCode, $tr
155155
* @param $transferredBytes
156156
* @return string
157157
*/
158-
public function showProgressByType($transferredBytes)
158+
public function showProgressByType($transferredBytes): string
159159
{
160160
if ($transferredBytes <= 0) {
161161
return '';

src/Components/PharCompiler.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PharCompiler
4444
/**
4545
* @var string|null The latest tag name
4646
*/
47-
private $branchAliasVersion = '';
47+
private $branchAliasVersion = 'UNKNOWN';
4848

4949
/**
5050
* @var \DateTime
@@ -157,6 +157,9 @@ class PharCompiler
157157
* @param string|array|null $files Only fetch the listed files
158158
* @param bool $overwrite
159159
* @return bool
160+
* @throws \UnexpectedValueException
161+
* @throws \BadMethodCallException
162+
* @throws \RuntimeException
160163
*/
161164
public static function unpack(string $pharFile, string $extractTo, $files = null, $overwrite = false): bool
162165
{
@@ -167,6 +170,10 @@ public static function unpack(string $pharFile, string $extractTo, $files = null
167170
return $phar->extractTo($extractTo, $files, $overwrite);
168171
}
169172

173+
/**
174+
*
175+
* @throws \RuntimeException
176+
*/
170177
private static function checkEnv()
171178
{
172179
if (!\class_exists(\Phar::class, false)) {
@@ -183,6 +190,7 @@ private static function checkEnv()
183190
/**
184191
* PharCompiler constructor.
185192
* @param string $basePath
193+
* @throws \RuntimeException
186194
*/
187195
public function __construct(string $basePath)
188196
{
@@ -299,6 +307,9 @@ public function setModifies($modifies): self
299307
* @param string $pharFile The full path to the file to create
300308
* @param bool $refresh
301309
* @return string
310+
* @throws \UnexpectedValueException
311+
* @throws \BadMethodCallException
312+
* @throws \RuntimeException
302313
*/
303314
public function pack(string $pharFile, $refresh = true): string
304315
{
@@ -512,6 +523,7 @@ public function getCounter(): int
512523

513524
/**
514525
* @return string
526+
* @throws \RuntimeException
515527
*/
516528
private function createStub(): string
517529
{
@@ -626,6 +638,7 @@ private function stripWhitespace(string $source): string
626638

627639
/**
628640
* auto collect project information by git log
641+
* @throws \RuntimeException
629642
*/
630643
private function collectInformation()
631644
{
@@ -660,8 +673,11 @@ private function collectInformation()
660673
if ($code === 0) {
661674
$this->version = trim($ret);
662675
} else {
663-
list($code, $ret,) = ProcessUtil::run('git branch', $basePath);
664-
$this->branchAliasVersion = $code === 0 ? trim($ret, "* \n"): 'UNKNOWN';
676+
list($code1, $ret,) = ProcessUtil::run('git branch', $basePath);
677+
678+
if ($code1 === 0) {
679+
$this->branchAliasVersion = \explode("\n", trim($ret, "* \n"), 2)[0];
680+
}
665681
}
666682
}
667683

src/Components/Style/Color.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public static function makeByString($string)
140140
* @param string $bg Background color. e.g 'black'
141141
* @param array $options Style options. e.g ['bold', 'underscore']
142142
* @param bool $extra
143+
* @throws \InvalidArgumentException
143144
*/
144145
public function __construct($fg = '', $bg = '', array $options = [], $extra = false)
145146
{
@@ -194,7 +195,7 @@ public function __toString()
194195
/**
195196
* Get the translated color code.
196197
*/
197-
public function toStyle()
198+
public function toStyle(): string
198199
{
199200
$values = [];
200201

src/Components/Style/Style.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public static function stripColor(string $string)
244244
* @param bool $extra
245245
* @return $this
246246
*/
247-
public function add(string $name, $fg = '', $bg = '', array $options = [], $extra = false)
247+
public function add(string $name, $fg = '', $bg = '', array $options = [], $extra = false): self
248248
{
249249
if (\is_array($fg)) {
250250
return $this->addByArray($name, $fg);
@@ -272,7 +272,7 @@ public function add(string $name, $fg = '', $bg = '', array $options = [], $extr
272272
* ]
273273
* @return $this
274274
*/
275-
public function addByArray(string $name, array $styleConfig)
275+
public function addByArray(string $name, array $styleConfig): self
276276
{
277277
$style = [
278278
'fg' => '',

src/Components/Terminal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static function build($format, $type = 'm'): string
155155
* @param null $arg2
156156
* @return $this
157157
*/
158-
public function cursor($typeName, $arg1 = 1, $arg2 = null)
158+
public function cursor($typeName, $arg1 = 1, $arg2 = null): self
159159
{
160160
if (!isset(self::$ctrlCursorCodes[$typeName])) {
161161
Show::error("The [$typeName] is not supported cursor control.", __LINE__);
@@ -191,7 +191,7 @@ public function cursor($typeName, $arg1 = 1, $arg2 = null)
191191
* @param null $arg
192192
* @return $this
193193
*/
194-
public function screen(string $typeName, $arg = null)
194+
public function screen(string $typeName, $arg = null): self
195195
{
196196
if (!isset(self::$ctrlScreenCodes[$typeName])) {
197197
Show::error("The [$typeName] is not supported cursor control.", __LINE__);

src/IO/InputDefinition.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static function make(array $arguments = [], array $options = []): InputDe
5757
*
5858
* @param array $arguments
5959
* @param array $options
60+
* @throws \LogicException
61+
* @throws \InvalidArgumentException
6062
*/
6163
public function __construct(array $arguments = [], array $options = [])
6264
{
@@ -67,6 +69,7 @@ public function __construct(array $arguments = [], array $options = [])
6769
/**
6870
* @param array $arguments
6971
* @return InputDefinition
72+
* @throws \LogicException
7073
*/
7174
public function setArguments(array $arguments): InputDefinition
7275
{
@@ -80,7 +83,7 @@ public function setArguments(array $arguments): InputDefinition
8083
* @return $this
8184
* @throws \LogicException
8285
*/
83-
public function addArguments(array $arguments)
86+
public function addArguments(array $arguments): self
8487
{
8588
foreach ($arguments as $name => $arg) {
8689
$arg = $this->mergeArgOptConfig($arg);
@@ -100,7 +103,7 @@ public function addArguments(array $arguments)
100103
* @return $this
101104
* @throws \LogicException
102105
*/
103-
public function addArgument($name, $mode = null, $description = '', $default = null)
106+
public function addArgument($name, $mode = null, $description = '', $default = null): self
104107
{
105108
if (null === $mode) {
106109
$mode = Input::ARG_OPTIONAL;
@@ -248,7 +251,7 @@ public function addOptions(array $options = [])
248251
* @throws \InvalidArgumentException
249252
* @throws \LogicException
250253
*/
251-
public function addOption(string $name, string $shortcut = null, $mode = null, $description = '', $default = null)
254+
public function addOption(string $name, string $shortcut = null, $mode = null, $description = '', $default = null): self
252255
{
253256
if (0 === strpos($name, '-')) {
254257
$name = trim($name, '-');
@@ -369,6 +372,7 @@ public function hasShortcut(string $name): bool
369372
* Gets an option info array
370373
* @param string $shortcut the Shortcut name
371374
* @return array
375+
* @throws \InvalidArgumentException
372376
*/
373377
public function getOptionByShortcut(string $shortcut): array
374378
{
@@ -504,7 +508,7 @@ public function getExample()
504508
* @param string|array $example
505509
* @return $this
506510
*/
507-
public function setExample($example)
511+
public function setExample($example): self
508512
{
509513
$this->example = $example;
510514

@@ -523,7 +527,7 @@ public function getDescription()
523527
* @param string $description
524528
* @return $this
525529
*/
526-
public function setDescription(string $description)
530+
public function setDescription(string $description): self
527531
{
528532
$this->description = $description;
529533

src/IO/Output.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function read($question = null, $nl = false): string
117117
* @param boolean $nl True (default) to append a new line at the end of the output string.
118118
* @return $this
119119
*/
120-
public function stderr($text = '', $nl = true)
120+
public function stderr($text = '', $nl = true): self
121121
{
122122
$text = $this->getStyle()->format($text);
123123

@@ -163,7 +163,7 @@ public function getOutputStream()
163163
* @param $outStream
164164
* @return $this
165165
*/
166-
public function setOutputStream($outStream)
166+
public function setOutputStream($outStream): self
167167
{
168168
$this->outputStream = $outStream;
169169

@@ -183,7 +183,7 @@ public function getErrorStream()
183183
* @param $errorStream
184184
* @return $this
185185
*/
186-
public function setErrorStream($errorStream)
186+
public function setErrorStream($errorStream): self
187187
{
188188
$this->errorStream = $errorStream;
189189

0 commit comments

Comments
 (0)