Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/coverage_report.xml
/html_docs
/phpunit.xml
/clover.xml
/clover.xml
/auth.json
4 changes: 3 additions & 1 deletion src/CodeMultiRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public function __construct(
$this->setupInterpreter($interpreter, $interpreterArgs);

$this->setupCwdForCode($baseFolder);

// phpcs:disable
/** @psalm-suppress PossiblyNullOperand */
// phpcs:enable
$this->mainScriptFullPath = $this->cwd . DIRECTORY_SEPARATOR
. 'main' . $this->scriptFileExtension($interpreter);
if (file_put_contents($this->mainScriptFullPath, $scriptText) === false) {
Expand Down
4 changes: 4 additions & 0 deletions src/DTO/RunningProcessData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

/**
* Just LocalDTO class for keeping data of each running process
*
* phpcs:disable
* @psalm-suppress MissingConstructor
* phpcs:enable
*/
class RunningProcessData
{
Expand Down
4 changes: 3 additions & 1 deletion src/DiffCodeMultiRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function addProcess(
if ($this->osCommandsWrapper->programExists($interpreter) !== 0) {
throw new RuntimeException('Interpreter ' . $interpreter . ' not found');
}

// phpcs:disable
/** @psalm-suppress PossiblyNullOperand */
// phpcs:enable
$mainScriptFullPath = $this->cwd . DIRECTORY_SEPARATOR .
$processId . '_script' . $this->scriptFileExtension($interpreter);
if (file_put_contents($mainScriptFullPath, $scriptText) === false) {
Expand Down
12 changes: 11 additions & 1 deletion src/Helpers/OsCommandsWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RuntimeException;
use SplFileInfo;

/**
* The class with methods to work with OS dependent functions.
Expand Down Expand Up @@ -156,6 +157,10 @@ public function escapeArgWin32(string $value): string
case '\\': // Matching backslashes are escaped if quoted.
return $match[0] . $match[0];
default:
// phpcs:disable
/** @psalm-suppress PossiblyFalseArgument */
// phpcs:enable
// Because there is no way $match[0] can be false.
throw new InvalidArgumentException(
sprintf(
"Invalid byte at offset %d: 0x%02X",
Expand All @@ -173,7 +178,9 @@ public function escapeArgWin32(string $value): string
? new InvalidArgumentException("Invalid UTF-8 string")
: new Error("PCRE error: " . preg_last_error());
}

// phpcs:disable
/** @psalm-suppress RedundantCondition, TypeDoesNotContainType */
// phpcs:enable
return $quote // Only quote when needed.
? '"' . $escaped . '"'
: $value;
Expand Down Expand Up @@ -213,6 +220,9 @@ public function clearFolder(string $folder): void
new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
// phpcs:disable
/** @var SplFileInfo $file */
// phpcs:enable
foreach ($files as $file) {
if ($file->isDir() === true) {
rmdir($file->getPathName());
Expand Down
35 changes: 25 additions & 10 deletions src/MultiRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ protected function getResultsAndCloseCompletedProcesses(int $timeLimit): array
// Before we can get the status of a process
// we should get the contents of stdout and stderr pipes
// to avoid deadlocks if the process sends a lot of output.
// phpcs:disable
/** @psalm-suppress RedundantCondition, TypeDoesNotContainType */
// phpcs:enable
$processData->stdout = ($processData->stdout ?? '') .
stream_get_contents($processData->pipes[self::STDOUT]);
// phpcs:disable
/** @psalm-suppress RedundantCondition, TypeDoesNotContainType */
// phpcs:enable
$processData->stderr = ($processData->stderr ?? '') .
stream_get_contents($processData->pipes[self::STDERR]);
$procStatus = proc_get_status($processData->process);
Expand Down Expand Up @@ -305,8 +311,8 @@ public function __destruct()
*/
protected function checkAndNormalizeCWD(?string $cwd): ?string
{
if (empty($cwd)) {
return $cwd;
if (is_null($cwd)) {
return null;
}
$cwdRealPath = realpath($cwd);
if ($cwdRealPath === false) {
Expand Down Expand Up @@ -339,7 +345,7 @@ protected function setupCwdForCode(?string $baseFolder): void
set_error_handler(
function ($errorSeverityNum, $message, $file, $line): bool {
if (error_reporting()) {
// @noinspection PhpUnhandledExceptionInspection
/* @noinspection PhpUnhandledExceptionInspection */
throw new ErrorException($message, 0, $errorSeverityNum, $file, $line);
}
return true;
Expand Down Expand Up @@ -509,11 +515,17 @@ protected function justRunAndForget(): void
protected function canProcessesRunViaPopen(): bool
{
foreach ($this->processesQueue as $processParams) {
if (
!empty($processParams->cwd) ||
!empty($processParams->envVars) ||
strpos($processParams->commandLine, '%') !== false
) {
/* @phpstan-ignore booleanAnd.rightAlwaysTrue */
if (isset($processParams->cwd) && is_string($processParams->cwd) && strlen(trim($processParams->cwd)) > 0) {
return false;
}
if (isset($processParams->envVars) && count($processParams->envVars) > 0) {
return false;
}
// phpcs:disable
/** @psalm-suppress RedundantCondition */
// phpcs:enable
if (isset($processParams->commandLine) && strpos($processParams->commandLine, '%') !== false) {
return false;
}
}
Expand All @@ -533,6 +545,9 @@ protected function canProcessesRunViaPopen(): bool
protected function closeProcess(string $processId, RunningProcessData $processData): int
{
foreach ($processData->pipes as $pipe) {
// phpcs:disable
/** @psalm-suppress RedundantConditionGivenDocblockType */
// phpcs:enable
if (is_resource($pipe)) {
fclose($pipe);
}
Expand Down Expand Up @@ -562,7 +577,7 @@ protected function checkAndNormaliseProgram(string $program, ?string $cwd): stri
if ($this->osCommandsWrapper->programExists($program) === 0) {
return $program;
}
if (!empty($cwd) && file_exists($cwd)) {
if (is_string($cwd) && strlen(trim($cwd)) > 0 && file_exists($cwd)) {
$programInCwd = $cwd . DIRECTORY_SEPARATOR . $program;
if ($this->osCommandsWrapper->programExists($programInCwd) === 0) {
return $programInCwd;
Expand All @@ -579,7 +594,7 @@ protected function checkAndNormaliseProgram(string $program, ?string $cwd): stri
*/
protected function clearAndDeleteCwd()
{
if (!empty($this->cwd) && file_exists($this->cwd)) {
if (isset($this->cwd) && strlen(trim($this->cwd)) > 0 && file_exists($this->cwd)) {
$this->osCommandsWrapper->removeDirRecursive($this->cwd);
}
}
Expand Down