Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of DowngradeStreamIsattyRector #6416

Closed
pdelre opened this issue May 14, 2021 · 1 comment · Fixed by rectorphp/rector-src#61
Closed

Incorrect behavior of DowngradeStreamIsattyRector #6416

pdelre opened this issue May 14, 2021 · 1 comment · Fixed by rectorphp/rector-src#61
Labels

Comments

@pdelre
Copy link

pdelre commented May 14, 2021

Bug Report

Subject Details
Rector version last dev-master
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/e5905dc9-f669-4f6e-9e11-f272dffa61af

<?php

final class DemoFile
{
    public function run($stream)
    {
        return stream_isatty($stream);
    }
}

Responsible rules

Expected Behavior

The resulting code relies on posix_isatty being defined, which requires the POSIX extension to be loaded. When the extension is not loaded, consuming execution fails with the following example.

PHP Fatal error:  Uncaught Error: Call to undefined function posix_isatty() in /workdir/vendor/symplify/easy-coding-standard/vendor/symfony/console/Output/StreamOutput.php:103
--
  | Stack trace:
  | #0 /workdir/vendor/symplify/easy-coding-standard/vendor/symfony/console/Output/StreamOutput.php(105): ECSPrefix20210513\Symfony\Component\Console\Output\StreamOutput->ECSPrefix20210513\Symfony\Component\Console\Output\{closure}()
  | #1 /workdir/vendor/symplify/easy-coding-standard/vendor/symfony/console/Output/StreamOutput.php(47): ECSPrefix20210513\Symfony\Component\Console\Output\StreamOutput->hasColorSupport()
  | #2 /workdir/vendor/symplify/easy-coding-standard/vendor/symfony/console/Output/ConsoleOutput.php(40): ECSPrefix20210513\Symfony\Component\Console\Output\StreamOutput->__construct()
  | #3 /workdir/vendor/symplify/easy-coding-standard/vendor/symplify/package-builder/src/Console/Style/SymfonyStyleFactory.php(32): ECSPrefix20210513\Symfony\Component\Console\Output\ConsoleOutput->__construct()
  | #4 /workdir/vendor/symplify/easy-coding-standard/b in /workdir/vendor/symplify/easy-coding-standard/vendor/symfony/console/Output/StreamOutput.php on line 103

The impact of this can be seen in symplify/easy-coding-standard's transformation of symfony/console's StreamOutput::hasColorSupport.

symfony/console might have a hint in an alternative solution without the dependency on the POSIX extension. In 4.4, they had a slightly different ordering to verify if a stream was TTY capable, which was changed for 5.0 (dropping 7.1.x support in turn) in symfony/symfony@c9b8b04

if (\function_exists('stream_isatty')) {
    return @stream_isatty($this->stream);
}

if (\function_exists('posix_isatty')) {
    return @posix_isatty($this->stream);
}

$stat = @fstat($this->stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
@TomasVotruba
Copy link
Member

Hi, thank for analysis. Could you add downgrade rule for this function?

TomasVotruba added a commit that referenced this issue Nov 12, 2024
carlos-granados added a commit to carlos-granados/rector that referenced this issue Nov 13, 2024
carlos-granados/rector-src@f7ea3db [PHP8.3] add new rectors for get_class()/get_parent_class() without arguments (rectorphp#6405)
carlos-granados/rector-src@1afc647 Rectify (rectorphp#6408)
carlos-granados/rector-src@afe7c46 [DeadCode] Skip nullable @ template on RemoveUselessReturnTagRector (rectorphp#6409)
carlos-granados/rector-src@293eb97 [Php81] Skip Doctrine Embeddable on ReadOnlyPropertyRector (rectorphp#6411)
carlos-granados/rector-src@1b1807b [Privatization] Skip with parameter on PrivatizeLocalGetterToPropertyRector (rectorphp#6412)
carlos-granados/rector-src@2c67908 Fix ClassDependencyManipulator to add dependency on right position (rectorphp#6413)
carlos-granados/rector-src@29e8932 [automated] Apply Coding Standard (rectorphp#6414)
carlos-granados/rector-src@3949fc2 Move instanceof PHPStan Type to ->is*() take 1 (rectorphp#6416)
carlos-granados/rector-src@0cac71a [CodeQuality] Add fixture test for skip nullable array from property with default value (rectorphp#6417)
carlos-granados/rector-src@d2db35e [Php80] Returns null on no change on ClassPropertyAssignToConstructorPromotionRector (rectorphp#6418)
carlos-granados/rector-src@06adce3 use ->isInteger()->yes() on ReturnTypeFromStrictNewArrayRector (rectorphp#6419)
carlos-granados/rector-src@bcfb598 Add ClassNameFromObjectTypeResolver to cover TypeWithClassName instance checks (rectorphp#6420)
carlos-granados/rector-src@84bb596 [StaticTypeMapper] Reduce instanceof TypeWithClassName usage via ClassNameFromObjectTypeResolver (rectorphp#6421)
carlos-granados/rector-src@26b8b54 [Naming] Reduce instanceof ObjectType on ExpectedNameResolver (take 5) (rectorphp#6423)
carlos-granados/rector-src@5baf487 Require-dev phpstan/phpstan-deprecation-rules to show list of deprecated (rectorphp#6415)
carlos-granados/rector-src@c23ba82 [deprecation] Remove deprecated PublicConstantVisibilityRector, cleanup deprecated SetListInterface (rectorphp#6424)
carlos-granados/rector-src@c2053c7 [deprecation] Deprecate AbstractScopeAwareRector in favor of single AbstractRector (rectorphp#6425)
carlos-granados/rector-src@2c5cd97 [deprecated] Remove deprecated AbstractTestCase (rectorphp#6426)
carlos-granados/rector-src@fb3c33a Merge commit '2c5cd97a3a98ab5af9efb846f6f78738e4a195a6'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants