Skip to content

Commit 1758010

Browse files
committed
[Process] fix phpdoc and timeout of 0
1 parent 99f3b3f commit 1758010

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ class Process
117117
/**
118118
* Constructor.
119119
*
120-
* @param string $commandline The command line to run
121-
* @param string $cwd The working directory
122-
* @param array $env The environment variables or null to inherit
123-
* @param string $stdin The STDIN content
124-
* @param integer $timeout The timeout in seconds
125-
* @param array $options An array of options for proc_open
120+
* @param string $commandline The command line to run
121+
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
122+
* @param array|null $env The environment variables or null to inherit
123+
* @param string|null $stdin The STDIN content
124+
* @param integer|float|null $timeout The timeout in seconds or null to disable
125+
* @param array $options An array of options for proc_open
126126
*
127127
* @throws RuntimeException When proc_open is not installed
128128
*
@@ -658,7 +658,7 @@ public function setCommandLine($commandline)
658658
/**
659659
* Gets the process timeout.
660660
*
661-
* @return integer|null The timeout in seconds or null if it's disabled
661+
* @return float|null The timeout in seconds or null if it's disabled
662662
*/
663663
public function getTimeout()
664664
{
@@ -670,23 +670,19 @@ public function getTimeout()
670670
*
671671
* To disable the timeout, set this value to null.
672672
*
673-
* @param float|null $timeout The timeout in seconds
673+
* @param integer|float|null $timeout The timeout in seconds
674674
*
675675
* @return self The current Process instance
676676
*
677677
* @throws InvalidArgumentException if the timeout is negative
678678
*/
679679
public function setTimeout($timeout)
680680
{
681-
if (null === $timeout) {
682-
$this->timeout = null;
683-
684-
return $this;
685-
}
686-
687681
$timeout = (float) $timeout;
688682

689-
if ($timeout < 0) {
683+
if (0.0 === $timeout) {
684+
$timeout = null;
685+
} elseif ($timeout < 0) {
690686
throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
691687
}
692688

@@ -698,11 +694,10 @@ public function setTimeout($timeout)
698694
/**
699695
* Gets the working directory.
700696
*
701-
* @return string The current working directory
697+
* @return string|null The current working directory or null on failure
702698
*/
703699
public function getWorkingDirectory()
704700
{
705-
// This is for BC only
706701
if (null === $this->cwd) {
707702
// getcwd() will return false if any one of the parent directories does not have
708703
// the readable or search mode set, even if the current directory does
@@ -765,7 +760,7 @@ public function setEnv(array $env)
765760
/**
766761
* Gets the contents of STDIN.
767762
*
768-
* @return string The current contents
763+
* @return string|null The current contents
769764
*/
770765
public function getStdin()
771766
{
@@ -775,7 +770,7 @@ public function getStdin()
775770
/**
776771
* Sets the contents of STDIN.
777772
*
778-
* @param string $stdin The new contents
773+
* @param string|null $stdin The new contents
779774
*
780775
* @return self The current Process instance
781776
*/
@@ -875,7 +870,7 @@ public function setEnhanceSigchildCompatibility($enhance)
875870
*/
876871
public function checkTimeout()
877872
{
878-
if (0 < $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
873+
if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
879874
$this->stop(0);
880875

881876
throw new RuntimeException('The process timed-out.');

src/Symfony/Component/Process/ProcessPipes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public function hasOpenHandles()
156156
/**
157157
* Writes stdin data.
158158
*
159-
* @param Boolean $blocking Whether to use blocking calls or not.
160-
* @param string $stdin The data to write.
159+
* @param Boolean $blocking Whether to use blocking calls or not.
160+
* @param string|null $stdin The data to write.
161161
*/
162162
public function write($blocking, $stdin)
163163
{

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ public function testNegativeTimeoutFromSetter()
3636
$p->setTimeout(-1);
3737
}
3838

39-
public function testNullTimeout()
39+
public function testFloatAndNullTimeout()
4040
{
4141
$p = $this->getProcess('');
42+
4243
$p->setTimeout(10);
44+
$this->assertSame(10.0, $p->getTimeout());
45+
4346
$p->setTimeout(null);
47+
$this->assertNull($p->getTimeout());
4448

49+
$p->setTimeout(0.0);
4550
$this->assertNull($p->getTimeout());
4651
}
4752

0 commit comments

Comments
 (0)