Skip to content

Commit 1683291

Browse files
committed
Merge branch 'fix-downstream-analysis-issues'
2 parents 919503e + 16b86ac commit 1683291

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+424
-1146
lines changed

phpstan-baseline-7.4.neon

Lines changed: 7 additions & 502 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline-8.3.neon

Lines changed: 7 additions & 497 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Sli/Command/Generate/Concept/GenerateCommand.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,28 @@ abstract class GenerateCommand extends Command
9999
* The parent of the generated class, or interfaces extended by the
100100
* generated interface
101101
*
102-
* @var class-string[]
102+
* @var string[]
103103
*/
104104
protected array $Extends = [];
105105

106106
/**
107107
* Interfaces implemented by the generated class
108108
*
109-
* @var class-string[]
109+
* @var string[]
110110
*/
111111
protected array $Implements = [];
112112

113113
/**
114114
* Traits used by the generated class
115115
*
116-
* @var class-string[]
116+
* @var string[]
117117
*/
118118
protected array $Uses = [];
119119

120120
/**
121121
* Modifiers applied to the generated class
122122
*
123-
* @var class-string[]
123+
* @var string[]
124124
*/
125125
protected array $Modifiers = [];
126126

@@ -486,11 +486,14 @@ function ($match) use (
486486
* Convert a built-in or user-defined type to a code-safe identifier, using
487487
* the same alias as the declaring class if possible
488488
*
489+
* @template TReturnFqcn of bool
490+
*
489491
* @param string $type Either a built-in type (e.g. `bool`) or a FQCN.
490492
* @param string|null $filename File where `$type` is declared (if
491493
* applicable).
492-
* @param bool $returnFqcn If `false`, return `null` instead of `$type` if
493-
* the alias has already been claimed.
494+
* @param TReturnFqcn $returnFqcn If `false`, return `null` instead of
495+
* `$type` if the alias has already been claimed.
496+
* @return (TReturnFqcn is true ? string : string|null)
494497
*/
495498
protected function getTypeAlias(string $type, ?string $filename = null, bool $returnFqcn = true): ?string
496499
{
@@ -516,10 +519,13 @@ protected function getTypeAlias(string $type, ?string $filename = null, bool $re
516519
* Otherwise, `use $fqcn[ as $alias];` will be queued for output and
517520
* `$alias` will be returned.
518521
*
522+
* @template TReturnFqcn of bool
523+
*
519524
* @param string|null $alias If `null`, the basename of `$fqcn` will be
520525
* used.
521-
* @param bool $returnFqcn If `false`, return `null` instead of the FQCN if
522-
* `$alias` has already been claimed.
526+
* @param TReturnFqcn $returnFqcn If `false`, return `null` instead of the
527+
* FQCN if `$alias` has already been claimed.
528+
* @return (TReturnFqcn is true ? string : string|null)
523529
*/
524530
protected function getFqcnAlias(string $fqcn, ?string $alias = null, bool $returnFqcn = true): ?string
525531
{
@@ -669,7 +675,7 @@ protected function generateImports(): array
669675
/**
670676
* Get an array that maps imports to aliases
671677
*
672-
* @return array<class-string,string|null>
678+
* @return array<class-string,string>
673679
*/
674680
protected function getImportMap(bool $sort = true): array
675681
{

src/Sli/Command/Generate/GenerateBuilder.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ protected function run(string ...$args)
355355
$summary = $_phpDoc ? $_phpDoc->unwrap($_phpDoc->Params[$_param->getName()]->Description ?? null) : null;
356356
}
357357

358-
$type = ($type ?? '') !== '' ? "$type " : '';
358+
$type = $type !== '' ? "$type " : '';
359359
$methods[] = " * @method \$this $name($type\$value$default)"
360360
. $this->getSummary(
361361
$summary, // Taken from property PHPDoc if set, otherwise constructor PHPDoc if set, otherwise `null`
@@ -515,7 +515,7 @@ protected function run(string ...$args)
515515
}
516516
$docBlocks[$name] = implode(\PHP_EOL, $lines);
517517
} else {
518-
$type = ($type ?? '') !== '' ? "$type " : '';
518+
$type = $type !== '' ? "$type " : '';
519519
$methods[] = " * @method \$this $name($type\$value$default)"
520520
. $this->getSummary(
521521
$summary, // Taken from constructor PHPDoc if set, otherwise property PHPDoc if set, otherwise `null`
@@ -725,8 +725,11 @@ protected function run(string ...$args)
725725
$docBlock[] = ' *';
726726
foreach ($this->InputClassTemplates as $template => $tag) {
727727
$tag = clone $tag;
728-
if (!Test::isPhpReservedWord($tag->Type) &&
729-
!array_key_exists($tag->Type, $this->InputClassTemplates)) {
728+
if (
729+
$tag->Type !== null &&
730+
!Test::isPhpReservedWord($tag->Type) &&
731+
!array_key_exists($tag->Type, $this->InputClassTemplates)
732+
) {
730733
$tag->Type = $this->getPhpDocTypeAlias(
731734
$tag,
732735
[],

src/Sli/Command/Http/SendHttpRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class SendHttpRequest extends Command
4545
private function getMethod(): string
4646
{
4747
return $this->HttpMethod
48-
?? ($this->HttpMethod = Str::upper(Arr::last($this->nameParts())));
48+
??= Str::upper((string) Arr::last($this->nameParts()));
4949
}
5050

5151
public function description(): string

src/Toolkit/Cli/CliApplication.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ public function run()
311311
// Print usage info if the last remaining $arg is "--help"
312312
if ($arg === '--help' && !$args) {
313313
$usage = $this->getHelp($name, $node);
314-
Console::stdout($usage);
314+
if ($usage !== null) {
315+
Console::stdout($usage);
316+
}
315317
return $this;
316318
}
317319

@@ -332,7 +334,9 @@ public function run()
332334
!Pcre::match('/^[a-zA-Z][a-zA-Z0-9_-]*$/', $arg)
333335
) {
334336
$usage = $this->getUsage($name, $node);
335-
Console::out($usage);
337+
if ($usage !== null) {
338+
Console::out($usage);
339+
}
336340
$this->LastExitStatus =
337341
$arg === null
338342
? 0
@@ -410,6 +414,7 @@ public function run()
410414
}
411415
if (
412416
$node &&
417+
$name !== null &&
413418
($usage = $this->getUsage($name, $node)) !== null
414419
) {
415420
Console::out("\n" . $usage);
@@ -483,8 +488,10 @@ private function generateHelp(string $name, $node, int $target, string ...$args)
483488
}
484489

485490
$usage = $this->getHelp($name, $node, $style);
486-
$usage = $formatter->formatTags($usage);
487-
$usage = Str::eolToNative($usage);
488-
printf('%s%s', str_replace('\ ', "\u{00A0}", $usage), \PHP_EOL);
491+
if ($usage !== null) {
492+
$usage = $formatter->formatTags($usage);
493+
$usage = Str::eolToNative($usage);
494+
}
495+
printf('%s%s', str_replace('\ ', "\u{00A0}", (string) $usage), \PHP_EOL);
489496
}
490497
}

src/Toolkit/Cli/CliCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ final public function getHelp(?CliHelpStyle $style = null): array
491491
$synopsis = $this->getSynopsis($style);
492492

493493
$description = $this->getLongDescription();
494-
if ((string) $description !== '') {
494+
if ($description !== null && $description !== '') {
495495
$description = $this->prepareHelp($style, $description);
496496
}
497497

src/Toolkit/Console/ConsoleFormatter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ function (array $match) use (
395395
}
396396

397397
if ($match['block'] !== null) {
398+
/** @var array{fence:string,infostring:string,block:string} $match */
398399
// Reinstate unwrapped newlines before blocks
399400
if ($unwrap && $string !== '' && $string[-1] !== "\n") {
400401
$string[-1] = "\n";
@@ -423,6 +424,7 @@ function (array $match) use (
423424
}
424425

425426
if ($match['span'] !== null) {
427+
/** @var array{backtickstring:string,span:string} $match */
426428
$span = $match['span'];
427429
// As per CommonMark:
428430
// - Convert line endings to spaces

src/Toolkit/Console/ConsoleWriter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ public function logProgress(
830830
return $this;
831831
}
832832

833-
if ((string) $msg2 === '') {
833+
if ($msg2 === null || $msg2 === '') {
834834
$msg1 = rtrim($msg1, "\r") . "\r";
835835
} else {
836836
$msg2 = rtrim($msg2, "\r") . "\r";
@@ -931,6 +931,7 @@ public function groupEnd(bool $printMessage = false)
931931
{
932932
$msg = array_pop($this->State->GroupMessageStack);
933933
if ($printMessage &&
934+
$msg !== null &&
934935
$msg !== '' &&
935936
($msg = Formatter::removeTags($msg)) !== '') {
936937
$this->write(Level::NOTICE, '', $msg ? "{ $msg } complete" : null, MessageType::GROUP_END);
@@ -1128,7 +1129,7 @@ private function _write(
11281129
}
11291130

11301131
$_msg2 = null;
1131-
if ((string) $msg2 !== '') {
1132+
if ($msg2 !== null && $msg2 !== '') {
11321133
$_msg2 = $msg2HasTags ? $formatter->formatTags($msg2) : $msg2;
11331134
$_msg2 = strpos($msg2, "\n") !== false
11341135
? str_replace("\n", "\n" . str_repeat(' ', $margin + $indent + 2), "\n" . ltrim($_msg2))

src/Toolkit/Console/Support/ConsoleFormat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(string $before = '', string $after = '', array $repl
5050
*/
5151
public function apply(?string $text, $attributes = null): string
5252
{
53-
if ((string) $text === '') {
53+
if ($text === null || $text === '') {
5454
return '';
5555
}
5656

0 commit comments

Comments
 (0)