Skip to content

Commit 7ace163

Browse files
committed
Fix few typing issues
1 parent 27c1154 commit 7ace163

6 files changed

Lines changed: 28 additions & 18 deletions

File tree

src/Phug/Split/Command/Analyze.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function calculatePackagesTree(Split $cli): bool
6666
return $cli->error('Root project directory should contains a '.$this->composerFile.' file.');
6767
}
6868

69-
$data = (array) json_decode(file_get_contents($this->composerFile), true);
69+
$data = (array) json_decode((string) file_get_contents($this->composerFile), true);
7070
$vendorDirectory = ($data['config'] ?? [])['vendor-dir'] ?? 'vendor';
7171

7272
$cli->writeLine((string) $data['name']);
@@ -93,7 +93,7 @@ protected function getPackages(): iterable
9393

9494
protected function dumpPackagesTree(Split $cli, iterable $packages, int $level = 0): bool
9595
{
96-
$count = is_countable($packages) ? count($packages) : INF;
96+
$count = is_countable($packages) ? count($packages) : 0;
9797

9898
foreach ($packages as $index => $package) {
9999
$symbol = $index === $count - 1 ? '' : '';
@@ -106,7 +106,8 @@ protected function dumpPackagesTree(Split $cli, iterable $packages, int $level =
106106

107107
protected function mapDirectories(string $directory, callable $callback): iterable
108108
{
109-
foreach (scandir($directory) as $element) {
109+
/** @psalm-suppress RiskyTruthyFalsyComparison */
110+
foreach ((scandir($directory) ?: []) as $element) {
110111
if (substr($element, 0, 1) === '.') {
111112
continue;
112113
}
@@ -141,7 +142,7 @@ protected function scanDirectories(string $directory): iterable
141142
$composerPath = $directory.DIRECTORY_SEPARATOR.$this->composerFile;
142143

143144
if (file_exists($composerPath)) {
144-
$data = json_decode(file_get_contents($composerPath), true);
145+
$data = json_decode((string) file_get_contents($composerPath), true);
145146
$mainPackage = $this->getPackage($directory, $data);
146147
}
147148

src/Phug/Split/Command/CommandBase.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ protected function gitEscape(string $value): string
5353
*
5454
* @return string
5555
*
56-
* @psalm-suppress UndefinedThisPropertyFetch RiskyTruthyFalsyComparison
56+
* @psalm-suppress UndefinedThisPropertyFetch
5757
*/
5858
protected function getGitCommand(string $command, array $options = [], ?string $redirect = null): string
5959
{
6060
foreach ($options as $name => $value) {
6161
$command .= ' --'.$name.'='.$this->gitEscape($value);
6262
}
6363

64+
/** @psalm-suppress RiskyTruthyFalsyComparison */
6465
return $this->gitProgram.' '.$command.($redirect ? ' '.$redirect : '');
6566
}
6667

@@ -71,13 +72,13 @@ protected function getGitCommand(string $command, array $options = [], ?string $
7172
* @param array $options CLI git command options
7273
* @param string|null $redirect redirection suffix (like '2>&1')
7374
*
74-
* @return string|null
75+
* @return string
7576
*/
76-
protected function git(string $command, array $options = [], ?string $redirect = null): ?string
77+
protected function git(string $command, array $options = [], ?string $redirect = null): string
7778
{
7879
$command = $this->getGitCommand($command, $options, $redirect);
7980

80-
return shell_exec($command);
81+
return (string) shell_exec($command);
8182
}
8283

8384
/**
@@ -117,6 +118,7 @@ protected function last(string $directory = ''): Commit
117118
* @throws Exception
118119
*
119120
* @return string|null
121+
* @psalm-return truthy-string|null
120122
*
121123
* @psalm-suppress UndefinedThisPropertyFetch
122124
*/

src/Phug/Split/Command/Copy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function run(SimpleCli $cli): bool
6565
return $cli->error('Last commit must be linked to a mono-repository commit.');
6666
}
6767

68-
$destination = realpath($this->destination);
68+
/** @psalm-var truthy-string|false $destination */
69+
$destination = @realpath($this->destination);
6970

7071
if (!$destination) {
7172
return $cli->error('Destination directory "'.$this->destination.'" does not seem to exist.');

src/Phug/Split/Command/Dist.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ protected function distribute(Split $cli): bool
7272
$this->remove($this->output);
7373
$cli->chdir($this->directory);
7474
@mkdir($this->output, 0777, true);
75-
$this->output = @realpath($this->output);
75+
/** @psalm-var truthy-string|false $output */
76+
$output = @realpath($this->output);
7677

77-
if (!$this->output) {
78+
if (!$output) {
7879
return $cli->error('Unable to create output directory.');
7980
}
8081

81-
if (!preg_match('/^\* (.+)$/m', (string) $this->git('branch', [], '2>&1') ?: '', $branch)) {
82+
$this->output = $output;
83+
84+
if (!preg_match('/^\* (.+)$/m', $this->git('branch', [], '2>&1') ?: '', $branch)) {
8285
return $cli->error('You must be on a branch in a git repository to run this command.');
8386
}
8487

8588
$branch = $branch[1];
8689

8790
if (substr($branch, 0, 18) === '(HEAD detached at ') {
88-
$branch = trim(explode("\n", (string) $this->git('describe --contains --all HEAD', [], '2>&1') ?: '')[0]);
91+
$branch = trim(explode("\n", $this->git('describe --contains --all HEAD', [], '2>&1') ?: '')[0]);
8992
}
9093

9194
foreach ($this->getPackages() as $package) {
@@ -103,7 +106,7 @@ protected function distributePackage(Split $cli, array $package, string $branch)
103106

104107
$name = (string) $package['name'];
105108

106-
$data = (array) json_decode(file_get_contents(strtr($this->api, ['%s' => $name])), true);
109+
$data = (array) json_decode((string) file_get_contents(strtr($this->api, ['%s' => $name])), true);
107110
$config = $data['packages'][$name] ?? [];
108111
$config = $config['dev-master'] ?? next($config);
109112

src/Phug/Split/Command/Update.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Update extends Dist
4545
protected function getPackage(string $directory, array $data): array
4646
{
4747
return [
48-
'name' => $data['name'],
49-
'directory' => realpath($directory),
48+
'name' => (string) $data['name'],
49+
'directory' => (string) realpath($directory),
5050
'children' => [],
5151
];
5252
}
@@ -184,7 +184,7 @@ protected function cherryPickCommit(
184184

185185
if (!$this->noPush) {
186186
$name = $package['name'];
187-
$push = (string) $this->git("push origin $branch", [], '2>&1');
187+
$push = $this->git("push origin $branch", [], '2>&1');
188188
$cli->writeLine("Pushing $name\n".$push, strpos($push, 'error:') === false ? 'light_cyan' : 'red');
189189
}
190190

@@ -215,7 +215,7 @@ protected function distributePackage(Split $cli, array $package, string $branch)
215215
}
216216

217217
$hash = $this->getCurrentLinkedCommitHash();
218-
$distributionDirectory = getcwd();
218+
$distributionDirectory = (string) getcwd();
219219
$sourceDirectory = $package['directory'];
220220

221221
$cli->chdir($sourceDirectory);

src/Phug/Split/Git/Commit.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ public function getMessage(): string
126126
* @param non-empty-string $regExp
127127
*
128128
* @return string|null
129+
* @psalm-return truthy-string|null
130+
*
131+
* @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType
129132
*/
130133
public function findInMessage(string $regExp): ?string
131134
{

0 commit comments

Comments
 (0)