Skip to content

Commit f2ac09b

Browse files
committed
Updates for phpstan level 7
Note that the removal of the version check (>= 5.3.6) for `DEBUG_BACKTRACE_IGNORE_ARGS` is safe, because we have already bailed on PHP < 5.4.
1 parent 917b1fa commit f2ac09b

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 7
33
bootstrapFiles:
44
- tests/bootstrap_phpstan.php
55
paths:

src/XdebugHandler.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function __construct($envPrefix)
105105
self::$xdebugActive = $this->loaded && $this->mode !== 'off';
106106

107107
if ($this->cli = PHP_SAPI === 'cli') {
108-
$this->debug = getenv(self::DEBUG);
108+
$this->debug = (string) getenv(self::DEBUG);
109109
}
110110

111111
$this->statusWriter = new Status($this->envAllowXdebug, (bool) $this->debug);
@@ -403,7 +403,7 @@ private function prepareRestart()
403403
*/
404404
private function writeTmpIni(array $iniFiles, $tmpDir, &$error)
405405
{
406-
if (!$this->tmpIni = @tempnam($tmpDir, '')) {
406+
if (!$this->tmpIni = (string) @tempnam($tmpDir, '')) {
407407
return false;
408408
}
409409

@@ -430,15 +430,20 @@ private function writeTmpIni(array $iniFiles, $tmpDir, &$error)
430430
}
431431

432432
// Merge loaded settings into our ini content, if it is valid
433-
if ($config = parse_ini_string($content)) {
434-
$loaded = ini_get_all(null, false);
435-
$content .= $this->mergeLoadedConfig($loaded, $config);
433+
$config = parse_ini_string($content);
434+
$loaded = ini_get_all(null, false);
435+
436+
if (false === $config || false === $loaded) {
437+
$error = 'Unable to parse ini data';
438+
return false;
436439
}
437440

441+
$content .= $this->mergeLoadedConfig($loaded, $config);
442+
438443
// Work-around for https://bugs.php.net/bug.php?id=75932
439444
$content .= 'opcache.enable_cli=0'.PHP_EOL;
440445

441-
return @file_put_contents($this->tmpIni, $content);
446+
return (bool) @file_put_contents($this->tmpIni, $content);
442447
}
443448

444449
/**
@@ -556,9 +561,8 @@ private function checkMainScript()
556561
return true;
557562
}
558563

559-
// Use a backtrace to resolve Phar and chdir issues
560-
$options = PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false;
561-
$trace = debug_backtrace($options);
564+
// Use a backtrace to resolve Phar and chdir issues.
565+
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
562566

563567
if (($main = end($trace)) && isset($main['file'])) {
564568
return file_exists($this->script = $main['file']);
@@ -646,10 +650,14 @@ private function checkConfiguration(&$info)
646650
}
647651
}
648652

653+
// Check UNC paths when using cmd.exe
654+
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 70400) {
655+
if (!$workingDir = getcwd()) {
656+
$info = 'unable to determine working directory';
657+
return false;
658+
}
649659

650-
$workingDir = getcwd();
651-
if (0 === strpos($workingDir, '\\\\')) {
652-
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 70400) {
660+
if (0 === strpos($workingDir, '\\\\')) {
653661
$info = 'cmd.exe does not support UNC paths: '.$workingDir;
654662
return false;
655663
}

0 commit comments

Comments
 (0)