Skip to content

Commit

Permalink
Merge pull request #254 from TravisCarden/feature/non-nullable-timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisCarden authored Aug 17, 2023
2 parents 2416cdd + 3a2ffdb commit 4b07d1f
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 62 deletions.
8 changes: 4 additions & 4 deletions src/API/Core/BeginnerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ interface BeginnerInterface
* as when committing.
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException
* If the preconditions are unfulfilled.
Expand All @@ -55,6 +55,6 @@ public function begin(
PathInterface $stagingDir,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/Core/CleanerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ interface CleanerInterface
* The staging directory.
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException
* If the preconditions are unfulfilled.
Expand All @@ -37,6 +37,6 @@ public function clean(
PathInterface $activeDir,
PathInterface $stagingDir,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/Core/CommitterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ interface CommitterInterface
* you should use the same exclusions when committing as when beginning.
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException
* If the preconditions are unfulfilled.
Expand All @@ -44,6 +44,6 @@ public function commit(
PathInterface $activeDir,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/Core/StagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ interface StagerInterface
* The staging directory.
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\InvalidArgumentException
* If the given Composer command is invalid.
Expand All @@ -51,6 +51,6 @@ public function stage(
PathInterface $activeDir,
PathInterface $stagingDir,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/FileSyncer/Service/FileSyncerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ interface FileSyncerInterface
* "underneath" or "inside" it.
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\IOException
* If the destination directory cannot be created.
Expand All @@ -49,6 +49,6 @@ public function sync(
PathInterface $destination,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/Filesystem/Service/FilesystemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ public function readLink(PathInterface $path): PathInterface;
* A path to remove.
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\IOException
* If the file cannot be removed.
*/
public function remove(
PathInterface $path,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/Process/Service/ComposerProcessRunnerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ interface ComposerProcessRunnerInterface
* ```
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\LogicException
* If the command process cannot be created due to host configuration.
Expand All @@ -40,6 +40,6 @@ interface ComposerProcessRunnerInterface
public function run(
array $command,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
8 changes: 4 additions & 4 deletions src/API/Process/Service/ProcessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public function setEnv(array $env): self;
/**
* Sets the process timeout (max. runtime) in seconds.
*
* @param float|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\InvalidArgumentException
* If the given timeout is negative.
*/
public function setTimeout(?float $timeout = self::DEFAULT_TIMEOUT): self;
public function setTimeout(int $timeout = self::DEFAULT_TIMEOUT): self;
}
8 changes: 4 additions & 4 deletions src/API/Process/Service/RsyncProcessRunnerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ interface RsyncProcessRunnerInterface
* ```
* @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback
* An optional PHP callback to run whenever there is process output.
* @param int|null $timeout
* An optional process timeout (maximum runtime) in seconds. Set to null
* to disable.
* @param int $timeout
* An optional process timeout (maximum runtime) in seconds. If set to
* zero (0), no time limit is imposed.
*
* @throws \PhpTuf\ComposerStager\API\Exception\LogicException
* If the command process cannot be created due to host configuration.
Expand All @@ -40,6 +40,6 @@ interface RsyncProcessRunnerInterface
public function run(
array $command,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void;
}
2 changes: 1 addition & 1 deletion src/Internal/Core/Beginner.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function begin(
PathInterface $stagingDir,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
$this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions);

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Core/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function clean(
PathInterface $activeDir,
PathInterface $stagingDir,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
$this->preconditions->assertIsFulfilled($activeDir, $stagingDir);

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Core/Committer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function commit(
PathInterface $activeDir,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
$this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions);

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Core/Stager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function stage(
PathInterface $activeDir,
PathInterface $stagingDir,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
$this->preconditions->assertIsFulfilled($activeDir, $stagingDir);

Expand Down Expand Up @@ -86,7 +86,7 @@ private function runCommand(
PathInterface $stagingDir,
array $composerCommand,
?OutputCallbackInterface $callback,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
$command = array_merge(
['--working-dir=' . $stagingDir->absolute()],
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/FileSyncer/Service/PhpFileSyncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function sync(
PathInterface $destination,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
set_time_limit((int) $timeout);
set_time_limit($timeout);

$exclusions ??= new PathList();

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/FileSyncer/Service/RsyncFileSyncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public function sync(
PathInterface $destination,
?PathListInterface $exclusions = null,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
$sourceAbsolute = $source->absolute();
$destinationAbsolute = $destination->absolute();

$this->assertDirectoriesAreNotTheSame($source, $destination);
$this->assertSourceExists($source);
set_time_limit((int) $timeout);
set_time_limit($timeout);
$this->runCommand($exclusions, $sourceAbsolute, $destinationAbsolute, $destination, $callback);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Filesystem/Service/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ public function readLink(PathInterface $path): PathInterface
public function remove(
PathInterface $path,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
try {
// Symfony Filesystem doesn't have a builtin mechanism for setting a
// timeout, so we have to enforce it ourselves.
set_time_limit((int) $timeout);
set_time_limit($timeout);

$this->symfonyFilesystem->remove($path->absolute());
} catch (SymfonyExceptionInterface $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Process/Service/AbstractProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(
public function run(
array $command,
?OutputCallbackInterface $callback = null,
?int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
int $timeout = ProcessInterface::DEFAULT_TIMEOUT,
): void {
array_unshift($command, $this->findExecutable());
$process = $this->processFactory->create($command);
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Process/Service/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function setEnv(array $env): ProcessInterface
return $this;
}

public function setTimeout(?float $timeout = self::DEFAULT_TIMEOUT): self
public function setTimeout(int $timeout = self::DEFAULT_TIMEOUT): self
{
try {
$this->symfonyProcess->setTimeout($timeout);
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/BeginnerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testBeginWithOptionalParams(
string $stagingDir,
?PathListInterface $exclusions,
?OutputCallbackInterface $callback,
?int $timeout,
int $timeout,
): void {
$activeDir = new TestPath($activeDir);
$stagingDir = new TestPath($stagingDir);
Expand All @@ -93,7 +93,7 @@ public function providerBeginWithOptionalParams(): array
'stagingDir' => 'three/four',
'givenExclusions' => null,
'callback' => null,
'timeout' => null,
'timeout' => 0,
],
[
'activeDir' => 'five/six',
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/CleanerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testCleanWithMinimumParams(): void
*
* @dataProvider providerCleanWithOptionalParams
*/
public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterface $callback, ?int $timeout): void
public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterface $callback, int $timeout): void
{
$path = new TestPath($path);
$this->preconditions
Expand All @@ -81,7 +81,7 @@ public function providerCleanWithOptionalParams(): array
[
'path' => '/one/two',
'callback' => null,
'timeout' => null,
'timeout' => 0,
],
[
'path' => 'three/four',
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/CommitterUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testCommitWithOptionalParams(
string $activeDir,
?PathListInterface $exclusions,
?OutputCallbackInterface $callback,
?int $timeout,
int $timeout,
): void {
$activeDir = new TestPath($activeDir);
$stagingDir = new TestPath($stagingDir);
Expand All @@ -93,7 +93,7 @@ public function providerCommitWithOptionalParams(): array
'activeDir' => '/three/four',
'exclusions' => null,
'callback' => null,
'timeout' => null,
'timeout' => 0,
],
[
'stagingDir' => 'five/six',
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/StagerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testStageWithOptionalParams(
array $givenCommand,
array $expectedCommand,
?OutputCallbackInterface $callback,
?int $timeout,
int $timeout,
): void {
$activeDirPath = PathHelper::activeDirPath();
$stagingDirPath = PathHelper::stagingDirPath();
Expand All @@ -102,7 +102,7 @@ public function providerStageWithOptionalParams(): array
'update',
],
'callback' => null,
'timeout' => null,
'timeout' => 0,
],
[
'givenCommand' => [self::INERT_COMMAND],
Expand Down
4 changes: 2 additions & 2 deletions tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract protected function fileSyncerClass(): string;
*
* @dataProvider providerSyncTimeout
*/
public function testSyncTimeout(?int $givenTimeout, int $expectedTimeout): void
public function testSyncTimeout(int $givenTimeout, int $expectedTimeout): void
{
$sut = $this->createSut();

Expand All @@ -53,7 +53,7 @@ public function providerSyncTimeout(): array
{
return [
[
'givenTimeout' => null,
'givenTimeout' => 0,
'expectedTimeout' => 0,
],
[
Expand Down
2 changes: 1 addition & 1 deletion tests/Filesystem/Service/FilesystemUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function providerRemove(): array
[
'path' => '/one/two',
'callback' => null,
'givenTimeout' => null,
'givenTimeout' => 0,
'expectedTimeout' => 0,
],
[
Expand Down
Loading

0 comments on commit 4b07d1f

Please sign in to comment.