-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp72] Handle variable exists on DowngradeStreamIsattyRector (
#1997) Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
232257d
commit e077d7c
Showing
2 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...owngradePhp72/Rector/FuncCall/DowngradeStreamIsattyRector/Fixture/variable_exists.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeStreamIsattyRector\Fixture; | ||
|
||
class VariableExists | ||
{ | ||
public function run($stream) | ||
{ | ||
$streamIsatty = function () {}; | ||
$isStream = stream_isatty($stream); | ||
|
||
$streamIsatty(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeStreamIsattyRector\Fixture; | ||
|
||
class VariableExists | ||
{ | ||
public function run($stream) | ||
{ | ||
$streamIsatty = function () {}; | ||
$streamIsatty2 = function ($stream) { | ||
if (\function_exists('stream_isatty')) { | ||
return stream_isatty($stream); | ||
} | ||
if (!\is_resource($stream)) { | ||
trigger_error('stream_isatty() expects parameter 1 to be resource, ' . \gettype($stream) . ' given', \E_USER_WARNING); | ||
return false; | ||
} | ||
if ('\\' === \DIRECTORY_SEPARATOR) { | ||
$stat = @fstat($stream); | ||
// Check if formatted mode is S_IFCHR | ||
return $stat ? 020000 === ($stat['mode'] & 0170000) : false; | ||
} | ||
return \function_exists('posix_isatty') && @posix_isatty($stream); | ||
}; | ||
$isStream = $streamIsatty2($stream); | ||
|
||
$streamIsatty(); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters