Skip to content

Commit b8672dc

Browse files
committed
Updates for phpstan level 9
1 parent f2ac09b commit b8672dc

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"require": {
2121
"php": "^5.3.2 || ^7.0 || ^8.0",
22-
"psr/log": "^1 || ^2 || ^3"
22+
"psr/log": "^1 || ^2 || ^3",
23+
"composer/pcre": "^1"
2324
},
2425
"require-dev": {
2526
"symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0",

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: 7
2+
level: 9
33
bootstrapFiles:
44
- tests/bootstrap_phpstan.php
55
paths:

src/Process.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Composer\XdebugHandler;
1313

14+
use Composer\Pcre\Preg;
15+
1416
/**
1517
* Process utility functions
1618
*
@@ -38,10 +40,10 @@ public static function escape($arg, $meta = true, $module = false)
3840

3941
$quote = strpbrk($arg, " \t") !== false || $arg === '';
4042

41-
$arg = preg_replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);
43+
$arg = Preg::replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);
4244

4345
if ($meta) {
44-
$meta = $dquotes || preg_match('/%[^%]+%/', $arg);
46+
$meta = $dquotes || Preg::isMatch('/%[^%]+%/', $arg);
4547

4648
if (!$meta) {
4749
$quote = $quote || strpbrk($arg, '^&|<>()') !== false;
@@ -51,11 +53,11 @@ public static function escape($arg, $meta = true, $module = false)
5153
}
5254

5355
if ($quote) {
54-
$arg = '"'.preg_replace('/(\\\\*)$/', '$1$1', $arg).'"';
56+
$arg = '"'.(Preg::replace('/(\\\\*)$/', '$1$1', $arg)).'"';
5557
}
5658

5759
if ($meta) {
58-
$arg = preg_replace('/(["^&|<>()%])/', '^$1', $arg);
60+
$arg = Preg::replace('/(["^&|<>()%])/', '^$1', $arg);
5961
}
6062

6163
return $arg;

src/XdebugHandler.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Composer\XdebugHandler;
1313

14+
use Composer\Pcre\Preg;
1415
use Psr\Log\LoggerInterface;
1516

1617
/**
@@ -96,7 +97,7 @@ public function __construct($envPrefix)
9697
$this->mode = empty($modes) ? 'off' : implode(',', $modes);
9798
} elseif (false !== ($mode = ini_get('xdebug.mode'))) {
9899
$this->mode = getenv('XDEBUG_MODE') ?: ($mode ?: 'off');
99-
if (preg_match('/^,+$/', str_replace(' ', '', $this->mode))) {
100+
if (Preg::isMatch('/^,+$/', str_replace(' ', '', $this->mode))) {
100101
$this->mode = 'off';
101102
}
102103
}
@@ -346,7 +347,7 @@ private function doRestart(array $command)
346347
if ($this->debug === '2') {
347348
$this->notify(Status::INFO, 'Temp ini saved: '.$this->tmpIni);
348349
} else {
349-
@unlink($this->tmpIni);
350+
@unlink((string) $this->tmpIni);
350351
}
351352

352353
exit($exitCode);
@@ -423,10 +424,10 @@ private function writeTmpIni(array $iniFiles, $tmpDir, &$error)
423424
return false;
424425
}
425426
// Check and remove directives after HOST and PATH sections
426-
if (preg_match($sectionRegex, $data, $matches, PREG_OFFSET_CAPTURE)) {
427+
if (Preg::isMatchWithOffsets($sectionRegex, $data, $matches, PREG_OFFSET_CAPTURE)) {
427428
$data = substr($data, 0, $matches[0][1]);
428429
}
429-
$content .= preg_replace($xdebugRegex, ';$1', $data).PHP_EOL;
430+
$content .= Preg::replace($xdebugRegex, ';$1', $data).PHP_EOL;
430431
}
431432

432433
// Merge loaded settings into our ini content, if it is valid

tests/IniFilesTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Composer\XdebugHandler\Tests;
1313

14+
use Composer\Pcre\Preg;
1415
use Composer\XdebugHandler\Process;
1516
use Composer\XdebugHandler\Tests\Helpers\BaseTestCase;
1617
use Composer\XdebugHandler\Tests\Helpers\IniHelper;
@@ -73,12 +74,12 @@ public function testTmpIni($iniFunc, $matches)
7374

7475
$content = $this->getTmpIniContent($xdebug);
7576
$regex = '/^\s*;zend_extension\s*=.*xdebug.*$/mi';
76-
$result = preg_match_all($regex, $content);
77+
$result = Preg::matchAll($regex, $content);
7778
$this->assertSame($result, $matches);
7879

7980
// Check content is end-of-line terminated
8081
$regex = sprintf('/%s/', preg_quote(PHP_EOL));
81-
$this->assertTrue((bool) preg_match($regex, $content));
82+
$this->assertTrue(Preg::isMatch($regex, $content));
8283
}
8384

8485
public function tmpIniProvider()

tests/RestartTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Composer\XdebugHandler\Tests;
1313

14+
use Composer\Pcre\Preg;
1415
use Composer\XdebugHandler\Tests\Helpers\BaseTestCase;
1516
use Composer\XdebugHandler\Tests\Mocks\CoreMock;
1617
use Composer\XdebugHandler\Tests\Mocks\FailMock;
@@ -38,7 +39,7 @@ public function testRestartWhenLoaded()
3839
$tmpIni = $xdebug->getTmpIni();
3940

4041
$pattern = preg_quote(sprintf(' -n -c %s ', $tmpIni), '/');
41-
$matched = (bool) preg_match('/'.$pattern.'/', $command);
42+
$matched = Preg::isMatch('/'.$pattern.'/', $command);
4243
$this->assertTrue($matched);
4344
}
4445

0 commit comments

Comments
 (0)