Skip to content

Commit

Permalink
Add early returning for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Jun 24, 2024
1 parent 8789df6 commit 997e046
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Command/Serve.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($this->isAddressTaken($address)) {
if ($this->isWindows()) {
$io->error("Port {$port} is taken by another process");
return self::EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_PROCESS;
}

$runningCommandPIDs = trim((string) shell_exec('lsof -ti :8080 -s TCP:LISTEN'));

Check failure on line 140 in src/Command/Serve.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

ForbiddenCode

src/Command/Serve.php:140:49: ForbiddenCode: Unsafe shell_exec (see https://psalm.dev/002)

Check failure on line 140 in src/Command/Serve.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

ForbiddenCode

src/Command/Serve.php:140:49: ForbiddenCode: Unsafe shell_exec (see https://psalm.dev/002)

Check failure on line 140 in src/Command/Serve.php

View workflow job for this annotation

GitHub Actions / psalm80 / PHP 8.0-ubuntu-latest

ForbiddenCode

src/Command/Serve.php:140:49: ForbiddenCode: Unsafe shell_exec (see https://psalm.dev/002)
if (empty($runningCommandPIDs)) {
$io->error("Port {$port} is taken by another process");
Expand Down Expand Up @@ -273,4 +278,9 @@ private function getRootPath(): string

return getcwd();
}

private function isWindows(): bool
{
return stripos(PHP_OS, 'Win') === 0;
}
}

0 comments on commit 997e046

Please sign in to comment.