Skip to content

Commit f2a29dc

Browse files
committed
mics
1 parent c58a218 commit f2a29dc

14 files changed

Lines changed: 82 additions & 74 deletions

File tree

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/vendor
22
composer.lock
3-
/.phpunit.result.cache
3+
4+
# phpunit 10+
5+
.phpunit.cache

.phpunit.cache/test-results

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\ContainerGetReturnTypeExtension\\ContainerGetReturnTypeExtensionTest::testAsserts":7,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\SplFileInfoTolerantReturnTypeExtension\\SplFileInfoTolerantReturnTypeExtensionTest::testAsserts":7},"times":{"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\FuncCall\\NativeFunctionDynamicFunctionReturnTypeExtension\\NativeFunctionDynamicFunctionReturnTypeExtensionTest::testAsserts":0.321,"Symplify\\PHPStanExtensions\\Tests\\ErrorFormatter\\SymplifyErrorFormatterTest::testFormatErrors#0":0.371,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\ContainerGetReturnTypeExtension\\ContainerGetReturnTypeExtensionTest::testAsserts":0.397,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\SplFileInfoTolerantReturnTypeExtension\\SplFileInfoTolerantReturnTypeExtensionTest::testAsserts":0.47}}

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"Symplify\\PHPStanExtensions\\Tests\\ErrorFormatter\\SymplifyErrorFormatterTest::testFormatErrors":4,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\FuncCall\\NativeFunctionDynamicFunctionReturnTypeExtension\\NativeFunctionDynamicFunctionReturnTypeExtensionTest::testAsserts":4,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\ContainerGetReturnTypeExtension\\ContainerGetReturnTypeExtensionTest::testAsserts":4,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\SplFileInfoTolerantReturnTypeExtension\\SplFileInfoTolerantReturnTypeExtensionTest::testAsserts":4},"times":{"Symplify\\PHPStanExtensions\\Tests\\ErrorFormatter\\SymplifyErrorFormatterTest::testFormatErrors":0.002,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\FuncCall\\NativeFunctionDynamicFunctionReturnTypeExtension\\NativeFunctionDynamicFunctionReturnTypeExtensionTest::testAsserts":0.59,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\ContainerGetReturnTypeExtension\\ContainerGetReturnTypeExtensionTest::testAsserts":0,"Symplify\\PHPStanExtensions\\Tests\\TypeExtension\\MethodCall\\SplFileInfoTolerantReturnTypeExtension\\SplFileInfoTolerantReturnTypeExtensionTest::testAsserts":0}}

composer.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=8.1",
8-
"phpstan/phpstan": "^1.9.7"
8+
"phpstan/phpstan": "^1.9.7",
9+
"symfony/filesystem": "^6.2"
910
},
1011
"require-dev": {
1112
"php-parallel-lint/php-parallel-lint": "^1.3",
1213
"phpstan/extension-installer": "^1.2",
1314
"phpunit/phpunit": "^10.0",
14-
"rector/rector": "^0.15.10",
15-
"symplify/easy-ci": "^11.1",
15+
"rector/rector": "^0.15.13",
16+
"symfony/dependency-injection": "^6.2",
17+
"symfony/finder": "^6.2",
18+
"symplify/easy-ci": "^11.2",
1619
"symplify/easy-coding-standard": "^11.2",
17-
"symplify/phpstan-rules": "11.2.3.72",
18-
"tomasvotruba/unused-public": "^0.0.34"
20+
"symplify/phpstan-rules": "^11.2",
21+
"tomasvotruba/unused-public": "^0.0.34",
22+
"tracy/tracy": "^2.9"
1923
},
2024
"autoload": {
2125
"psr-4": {

easy-ci.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
declare(strict_types=1);
44

5+
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
6+
use PHPStan\Type\DynamicMethodReturnTypeExtension;
57
use Symplify\EasyCI\Config\EasyCIConfig;
6-
use Symplify\PHPStanExtensions\TypeExtension\FuncCall\NativeFunctionDynamicFunctionReturnTypeExtension;
7-
use Symplify\PHPStanExtensions\TypeExtension\MethodCall\ContainerGetReturnTypeExtension;
8-
use Symplify\PHPStanExtensions\TypeExtension\MethodCall\SplFileInfoTolerantReturnTypeExtension;
98

109
return static function (EasyCIConfig $easyCIConfig): void {
1110
$easyCIConfig->typesToSkip([
12-
NativeFunctionDynamicFunctionReturnTypeExtension::class,
13-
ContainerGetReturnTypeExtension::class,
14-
SplFileInfoTolerantReturnTypeExtension::class,
11+
DynamicFunctionReturnTypeExtension::class,
12+
DynamicMethodReturnTypeExtension::class,
1513
]);
1614
};

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ parameters:
1212
- '*/tests/**/Source/*'
1313
- '*/tests/**/Fixture/*'
1414
- '*/tests/**/data/*'
15+
# copy-pasted 3rd party code
16+
- src/Console/Terminal.php
1517

1618
unused_public:
1719
methods: true

phpunit.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
<phpunit
2-
bootstrap="vendor/autoload.php"
3-
colors="true"
4-
verbose="true"
5-
>
6-
<testsuite name="all">
7-
<directory>tests</directory>
8-
</testsuite>
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<testsuite name="all">
4+
<directory>tests</directory>
5+
</testsuite>
96
</phpunit>

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
return static function (RectorConfig $rectorConfig): void {
1111
$rectorConfig->sets([
12+
PHPUnitSetList::PHPUNIT_100,
1213
SetList::CODE_QUALITY,
1314
SetList::DEAD_CODE,
1415
LevelSetList::UP_TO_PHP_81,

src/Console/Terminal.php

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@
1010
*/
1111
final class Terminal
1212
{
13-
private static $width;
13+
/**
14+
* @var array<int, array<string>>
15+
*/
16+
private const DESCRIPTORSPEC = [
17+
1 => ['pipe', 'w'],
18+
2 => ['pipe', 'w'],
19+
];
1420

15-
private static $stty;
21+
private static ?int $width = null;
22+
23+
private static ?bool $stty = null;
1624

1725
public static function getWidth(): int
1826
{
1927
$width = \getenv('COLUMNS');
2028
if ($width !== \false) {
2129
return (int) \trim($width);
2230
}
31+
2332
if (self::$width === null) {
2433
self::initDimensions();
2534
}
35+
2636
return self::$width ?: 80;
2737
}
2838

@@ -31,24 +41,26 @@ public static function hasSttyAvailable(): bool
3141
if (self::$stty !== null) {
3242
return self::$stty;
3343
}
44+
3445
if (! \function_exists('exec')) {
3546
return \false;
3647
}
48+
3749
\exec('stty 2>&1', $output, $exitcode);
3850
return self::$stty = $exitcode === 0;
3951
}
4052

41-
private static function initDimensions()
53+
private static function initDimensions(): void
4254
{
43-
$dimensions = self::getConsoleMode();
55+
$consoleMode = self::getConsoleMode();
4456

4557
if ('\\' === \DIRECTORY_SEPARATOR) {
46-
if (\preg_match('/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/', \trim(\getenv('ANSICON')), $matches)) {
58+
if (\preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) {
4759
self::$width = (int) $matches[1];
4860
} elseif (! self::hasVt100Support() && self::hasSttyAvailable()) {
4961
self::initDimensionsUsingStty();
50-
} elseif ($dimensions) {
51-
self::$width = (int) $dimensions[0];
62+
} elseif ($consoleMode) {
63+
self::$width = (int) $consoleMode[0];
5264
}
5365
} else {
5466
self::initDimensionsUsingStty();
@@ -62,12 +74,12 @@ private static function hasVt100Support(): bool
6274

6375
private static function initDimensionsUsingStty(): void
6476
{
65-
$sttyString = self::getSttyColumns();
77+
$sttyColumns = self::getSttyColumns();
6678

67-
if ($sttyString) {
68-
if (\preg_match('/rows.(\\d+);.columns.(\\d+);/i', $sttyString, $matches)) {
79+
if ($sttyColumns) {
80+
if (\preg_match('#rows.(\d+);.columns.(\d+);#i', $sttyColumns, $matches)) {
6981
self::$width = (int) $matches[2];
70-
} elseif (\preg_match('/;.(\\d+).rows;.(\\d+).columns/i', $sttyString, $matches)) {
82+
} elseif (\preg_match('#;.(\d+).rows;.(\d+).columns#i', $sttyColumns, $matches)) {
7183
self::$width = (int) $matches[2];
7284
}
7385
}
@@ -76,9 +88,14 @@ private static function initDimensionsUsingStty(): void
7688
private static function getConsoleMode(): ?array
7789
{
7890
$info = self::readFromProcess('mode CON');
79-
if ($info === null || ! \preg_match('/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/', $info, $matches)) {
91+
if ($info === null) {
8092
return null;
8193
}
94+
95+
if (! \preg_match('#--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n#', $info, $matches)) {
96+
return null;
97+
}
98+
8299
return [(int) $matches[2], (int) $matches[1]];
83100
}
84101

@@ -92,16 +109,14 @@ private static function readFromProcess(string $command): ?string
92109
if (! \function_exists('proc_open')) {
93110
return null;
94111
}
95-
$descriptorspec = [
96-
1 => ['pipe', 'w'],
97-
2 => ['pipe', 'w'],
98-
];
99-
$process = \proc_open($command, $descriptorspec, $pipes, null, null, [
112+
113+
$process = \proc_open($command, self::DESCRIPTORSPEC, $pipes, null, null, [
100114
'suppress_errors' => \true,
101115
]);
102116
if (! \is_resource($process)) {
103117
return null;
104118
}
119+
105120
$info = \stream_get_contents($pipes[1]);
106121
\fclose($pipes[1]);
107122
\fclose($pipes[2]);

0 commit comments

Comments
 (0)