Skip to content

Commit

Permalink
Update Process.stub
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 30, 2024
1 parent f7d5782 commit 270c2ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ parameters:
- stubs/Symfony/Component/Messenger/Envelope.stub
- stubs/Symfony/Component/OptionsResolver/Exception/InvalidOptionsException.stub
- stubs/Symfony/Component/OptionsResolver/Options.stub
- stubs/Symfony/Component/Process/Exception/LogicException.stub
- stubs/Symfony/Component/Process/Process.stub
- stubs/Symfony/Component/PropertyAccess/Exception/AccessException.stub
- stubs/Symfony/Component/PropertyAccess/Exception/ExceptionInterface.stub
Expand Down
8 changes: 8 additions & 0 deletions stubs/Symfony/Component/Process/Exception/LogicException.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Symfony\Component\Process\Exception;

class LogicException extends \Exception
{

}
15 changes: 15 additions & 0 deletions stubs/Symfony/Component/Process/Process.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\LogicException;

/**
* @implements \IteratorAggregate<string, string>
*/
class Process implements \IteratorAggregate
{

/**
* @param int $flags
*
* @return \Generator<string, string, mixed, mixed>
*
* @throws LogicException in case the output has been disabled
* @throws LogicException In case the process is not started
*/
public function getIterator(int $flags = 0): \Generator
{

}

}

3 comments on commit 270c2ee

@janedbal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ondrejmirtes Please be aware that the function getIterator does NOT throw the exceptions you annotated. It is thrown once iterated, which is NOT detected by PHPStan: https://phpstan.org/r/d07ac0f0-a49d-4f82-b1dd-1939058bbeed

Related: https://github.com/shipmonk-rnd/phpstan-rules?tab=readme-ov-file#forbidcheckedexceptioninyieldingmethod

@ondrejmirtes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not exactly precise, but I don't know what to do about this. If someone does foreach ($process as $v), then PHPStan could correctly use these @throws above getIterator. (But it currently does not.)

@ondrejmirtes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I didn't make anything worse with this commit, this was copied from Symfony sources.

Please sign in to comment.