Skip to content

Commit fbfe454

Browse files
committed
simplify
1 parent 5d0861b commit fbfe454

File tree

2 files changed

+1
-50
lines changed

2 files changed

+1
-50
lines changed

src/Parser/CachedParser.php

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@
33
namespace PHPStan\Parser;
44

55
use PhpParser\Node;
6-
use PHPStan\File\FileReader;
76
use function array_slice;
87

98
final class CachedParser implements Parser
109
{
1110

12-
/** @var array<string, Node\Stmt[]>*/
13-
private array $cachedNodesByString = [];
14-
15-
private int $cachedNodesByStringCount = 0;
16-
1711
/** @var array<string, Node\Stmt[]>*/
1812
private array $cachedNodesByFile = [];
1913

@@ -55,40 +49,12 @@ public function parseFile(string $file): array
5549
*/
5650
public function parseString(string $sourceCode): array
5751
{
58-
if ($this->cachedNodesByStringCountMax !== 0 && $this->cachedNodesByStringCount >= $this->cachedNodesByStringCountMax) {
59-
$this->cachedNodesByString = array_slice(
60-
$this->cachedNodesByString,
61-
1,
62-
preserve_keys: true,
63-
);
64-
65-
--$this->cachedNodesByStringCount;
66-
}
67-
68-
if (!isset($this->cachedNodesByString[$sourceCode])) {
69-
$this->cachedNodesByString[$sourceCode] = $this->originalParser->parseString($sourceCode);
70-
$this->cachedNodesByStringCount++;
71-
}
72-
73-
return $this->cachedNodesByString[$sourceCode];
74-
}
75-
76-
public function getCachedNodesByStringCount(): int
77-
{
78-
return $this->cachedNodesByStringCount;
52+
return $this->originalParser->parseString($sourceCode);
7953
}
8054

8155
public function getCachedNodesByStringCountMax(): int
8256
{
8357
return $this->cachedNodesByStringCountMax;
8458
}
8559

86-
/**
87-
* @return array<string, Node[]>
88-
*/
89-
public function getCachedNodesByString(): array
90-
{
91-
return $this->cachedNodesByString;
92-
}
93-
9460
}

tests/PHPStan/Parser/CachedParserTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ public function testParseFileClearCache(
2929
$cachedNodesByStringCountMax,
3030
$parser->getCachedNodesByStringCountMax(),
3131
);
32-
33-
// Add strings to cache
34-
for ($i = 0; $i <= $cachedNodesByStringCountMax; $i++) {
35-
$parser->parseString('string' . $i);
36-
}
37-
38-
$this->assertSame(
39-
$cachedNodesByStringCountExpected,
40-
$parser->getCachedNodesByStringCount(),
41-
);
42-
43-
$this->assertCount(
44-
$cachedNodesByStringCountExpected,
45-
$parser->getCachedNodesByString(),
46-
);
4732
}
4833

4934
/**

0 commit comments

Comments
 (0)