Skip to content

Commit 53d247c

Browse files
committed
chore: fix psalm issues
1 parent 73bdfa1 commit 53d247c

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

psalm-baseline.xml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,26 @@
3737
<MoreSpecificReturnType>
3838
<code><![CDATA[list<DownloadConfig>]]></code>
3939
</MoreSpecificReturnType>
40-
<PropertyNotSetInConstructor>
41-
<code><![CDATA[Get]]></code>
42-
<code><![CDATA[Get]]></code>
43-
</PropertyNotSetInConstructor>
4440
</file>
4541
<file src="src/Command/ListSoftware.php">
46-
<PropertyNotSetInConstructor>
47-
<code><![CDATA[ListSoftware]]></code>
48-
<code><![CDATA[ListSoftware]]></code>
49-
</PropertyNotSetInConstructor>
5042
<RiskyTruthyFalsyComparison>
5143
<code><![CDATA[$software->homepage]]></code>
5244
</RiskyTruthyFalsyComparison>
5345
</file>
46+
<file src="src/Command/Show.php">
47+
<InvalidArrayOffset>
48+
<code><![CDATA[$units[$i]]]></code>
49+
</InvalidArrayOffset>
50+
<InvalidOperand>
51+
<code><![CDATA[$bytes /= 1024]]></code>
52+
</InvalidOperand>
53+
<MixedArgument>
54+
<code><![CDATA[$units[$i]]]></code>
55+
</MixedArgument>
56+
<PossiblyFalseArgument>
57+
<code><![CDATA[$destinationPath]]></code>
58+
</PossiblyFalseArgument>
59+
</file>
5460
<file src="src/DLoad.php">
5561
<ArgumentTypeCoercion>
5662
<code><![CDATA[$files]]></code>
@@ -101,6 +107,22 @@
101107
<code><![CDATA[ZipPharArchive]]></code>
102108
</PropertyNotSetInConstructor>
103109
</file>
110+
<file src="src/Module/Binary/Internal/BinaryExecutor.php">
111+
<MixedArgumentTypeCoercion>
112+
<code><![CDATA[$output]]></code>
113+
<code><![CDATA[$output]]></code>
114+
</MixedArgumentTypeCoercion>
115+
</file>
116+
<file src="src/Module/Binary/Internal/VersionComparator.php">
117+
<PossiblyNullArgument>
118+
<code><![CDATA[$versionOnly]]></code>
119+
<code><![CDATA[\preg_replace('/[-+].*$/', '', $constraint)]]></code>
120+
</PossiblyNullArgument>
121+
<RedundantCondition>
122+
<code><![CDATA[!$hasPreB]]></code>
123+
<code><![CDATA[$bIsNum]]></code>
124+
</RedundantCondition>
125+
</file>
104126
<file src="src/Module/Common/Config/Action/Download.php">
105127
<MissingConstructor>
106128
<code><![CDATA[$software]]></code>

psalm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<RedundantConditionGivenDocblockType errorLevel="suppress"/>
1313
<RedundantCastGivenDocblockType errorLevel="suppress"/>
1414
<MissingOverrideAttribute errorLevel="suppress"/>
15+
<PropertyNotSetInConstructor>
16+
<errorLevel type="suppress">
17+
<directory name="src/Command"/>
18+
</errorLevel>
19+
</PropertyNotSetInConstructor>
1520
</issueHandlers>
1621
<projectFiles>
1722
<directory name="src"/>

src/Command/Show.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Internal\DLoad\Module\Binary\Binary;
88
use Internal\DLoad\Module\Binary\BinaryProvider;
99
use Internal\DLoad\Module\Common\Config\Actions;
10+
use Internal\DLoad\Module\Common\FileSystem\Path;
1011
use Internal\DLoad\Module\Downloader\SoftwareCollection;
1112
use Symfony\Component\Console\Attribute\AsCommand;
1213
use Symfony\Component\Console\Command\Command;
@@ -47,7 +48,7 @@ protected function execute(
4748
// Get all software from collection
4849
$collection = $this->container->get(SoftwareCollection::class);
4950
$binaryProvider = $this->container->get(BinaryProvider::class);
50-
$softwareName = $input->getArgument('software');
51+
$softwareName = (string) $input->getArgument('software');
5152

5253
// Get configuration if available
5354
$configFile = $this->getConfigFile($input);
@@ -57,7 +58,7 @@ protected function execute(
5758
$actions = $this->container->get(Actions::class);
5859
}
5960

60-
if ($softwareName !== null) {
61+
if ($softwareName !== '') {
6162
return $this->showSoftwareDetails($softwareName, $collection, $binaryProvider, $actions, $output);
6263
}
6364

@@ -71,8 +72,8 @@ private function listAllSoftware(
7172
InputInterface $input,
7273
OutputInterface $output,
7374
): int {
74-
$showAll = $input->getOption('all');
75-
$destinationPath = \getcwd();
75+
$showAll = (bool) $input->getOption('all');
76+
$destinationPath = Path::create((string) \getcwd());
7677

7778
$configSoftwareIds = [];
7879
if ($actions !== null) {
@@ -197,6 +198,9 @@ private function listAllSoftware(
197198
return Command::SUCCESS;
198199
}
199200

201+
/**
202+
* @param non-empty-string $softwareName
203+
*/
200204
private function showSoftwareDetails(
201205
string $softwareName,
202206
SoftwareCollection $collection,
@@ -242,7 +246,7 @@ private function showSoftwareDetails(
242246
->writeln(\sprintf('<info>Alias:</info> %s', $software->alias));
243247
$software->description and $output
244248
->writeln(\sprintf('<info>Description:</info> %s', $software->description));
245-
$software->homepage and $output
249+
$software->homepage === null or $output
246250
->writeln(\sprintf('<info>Homepage:</info> %s', $software->homepage));
247251

248252
// Show project config information
@@ -292,9 +296,10 @@ private function displayBinaryDetails(?Binary $binary, OutputInterface $output):
292296
$output->writeln(\sprintf(' <info>Version:</info> %s', $binary->getVersion() ?? 'unknown'));
293297
$output->writeln(\sprintf(' <info>Size:</info> %s', $this->formatSize($binary->getSize())));
294298

295-
$output->writeln(\sprintf(
299+
$mtime = $binary->getMTime();
300+
$mtime === null or $output->writeln(\sprintf(
296301
' <info>Last modified:</info> %s',
297-
$binary->getMTime()->format('Y-m-d H:i:s'),
302+
$mtime->format('Y-m-d H:i:s'),
298303
));
299304
}
300305

src/Module/Binary/BinaryProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Internal\DLoad\Module\Binary;
66

77
use Internal\DLoad\Module\Common\Config\Embed\Binary as BinaryConfig;
8+
use Internal\DLoad\Module\Common\FileSystem\Path;
89

910
/**
1011
* Provider for obtaining binary instances.
@@ -14,9 +15,9 @@ interface BinaryProvider
1415
/**
1516
* Gets a binary for the given configuration.
1617
*
17-
* @param non-empty-string $destinationPath Directory path where binary should exist
18+
* @param Path|non-empty-string $destinationPath Directory path where binary should exist
1819
* @param BinaryConfig $config Binary configuration
1920
* @return Binary|null Binary instance or null if it doesn't exist
2021
*/
21-
public function getBinary(string $destinationPath, BinaryConfig $config): ?Binary;
22+
public function getBinary(Path|string $destinationPath, BinaryConfig $config): ?Binary;
2223
}

0 commit comments

Comments
 (0)