Skip to content

Commit 979d4f6

Browse files
committed
linting, stanning
1 parent 1abf783 commit 979d4f6

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

tests/PHPStan/Printer/PrinterTest.php

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,56 +45,65 @@
4545
use PHPStan\PhpDocParser\Parser\TokenIterator;
4646
use PHPStan\PhpDocParser\Parser\TypeParser;
4747
use PHPUnit\Framework\TestCase;
48+
use function array_map;
4849
use function array_pop;
50+
use function array_slice;
4951
use function array_splice;
5052
use function array_unshift;
5153
use function array_values;
5254
use function count;
55+
use function implode;
56+
use function preg_match;
57+
use function preg_replace_callback;
58+
use function preg_split;
59+
use function str_repeat;
60+
use function str_replace;
61+
use function strlen;
5362
use const PHP_EOL;
5463

55-
function nowdoc(string $str): string
64+
class PrinterTest extends TestCase
5665
{
57-
$lines = \preg_split('/\\n/', $str);
5866

59-
if ($lines === false) {
60-
return '';
61-
}
67+
/** @var TypeParser */
68+
private $typeParser;
6269

63-
if (\count($lines) <= 2) {
64-
return '';
65-
}
70+
/** @var PhpDocParser */
71+
private $phpDocParser;
6672

67-
// Toss out the first line
68-
$lines = \array_slice($lines, 1, \count($lines) - 1);
73+
static function nowdoc(string $str): string
74+
{
75+
$lines = preg_split('/\\n/', $str);
6976

70-
// normalize any tabs to spaces
71-
$lines = array_map(static function($line) {
72-
return preg_replace_callback('/(\t+)/m', function ($matches) {
73-
$fixed = str_repeat(' ', strlen($matches[1]));
74-
return $fixed;
75-
}, $line);
76-
}, $lines);
77+
if ($lines === false) {
78+
return '';
79+
}
7780

78-
// take the ws from the first line and subtract them from all lines
79-
$matches = [];
80-
\preg_match('/(^[ \t]+)/', $lines[0] ?? '', $matches);
81+
if (count($lines) <= 2) {
82+
return '';
83+
}
8184

82-
$numLines = \count($lines);
83-
for ($i = 0; $i < $numLines; ++$i) {
84-
$lines[$i] = \str_replace($matches[0], '', $lines[$i]);
85-
}
85+
// Toss out the first line
86+
$lines = array_slice($lines, 1, count($lines) - 1);
8687

87-
return \implode("\n", $lines);
88-
}
88+
// normalize any tabs to spaces
89+
$lines = array_map(static function ($line) {
90+
return preg_replace_callback('/(\t+)/m', static function ($matches) {
91+
$fixed = str_repeat(' ', strlen($matches[1]));
92+
return $fixed;
93+
}, $line);
94+
}, $lines);
8995

90-
class PrinterTest extends TestCase
91-
{
96+
// take the ws from the first line and subtract them from all lines
97+
$matches = [];
98+
preg_match('/(^[ \t]+)/', $lines[0] ?? '', $matches);
9299

93-
/** @var TypeParser */
94-
private $typeParser;
100+
$numLines = count($lines);
101+
for ($i = 0; $i < $numLines; ++$i) {
102+
$lines[$i] = str_replace($matches[0], '', $lines[$i] ?? '');
103+
}
95104

96-
/** @var PhpDocParser */
97-
private $phpDocParser;
105+
return implode("\n", $lines);
106+
}
98107

99108
protected function setUp(): void
100109
{
@@ -976,35 +985,35 @@ public function enterNode(Node $node)
976985
};
977986

978987
yield [
979-
nowdoc('
988+
self::nowdoc('
980989
/**
981990
* @return object{}
982991
*/'),
983-
nowdoc('
992+
self::nowdoc('
984993
/**
985994
* @return object{foo: int}
986995
*/'),
987996
$addItemsToObjectShape,
988997
];
989998

990999
yield [
991-
nowdoc('
1000+
self::nowdoc('
9921001
/**
9931002
* @return object{bar: string}
9941003
*/'),
995-
nowdoc('
1004+
self::nowdoc('
9961005
/**
9971006
* @return object{bar: string, foo: int}
9981007
*/'),
9991008
$addItemsToObjectShape,
10001009
];
10011010

10021011
yield [
1003-
nowdoc('
1012+
self::nowdoc('
10041013
/**
10051014
* @return object{bar: string}
10061015
*/'),
1007-
nowdoc('
1016+
self::nowdoc('
10081017
/**
10091018
* @return object{bar: string, foo: int}
10101019
*/'),

0 commit comments

Comments
 (0)