Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"require-dev": {
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^13.1",
"squizlabs/php_codesniffer": "^3.10"
},
Expand Down
58 changes: 57 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 8
level: 10
treatPhpDocTypesAsCertain: false
paths:
- src
Expand Down
2 changes: 1 addition & 1 deletion src/Ast/AstMatchCodec.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function encodeCaptureArray(array $captures): array
}

/**
* @param array<string, mixed> $captures
* @param array<array-key, mixed> $captures
* @return array<string, mixed>
*/
private function decodeCaptureArray(array $captures): array
Expand Down
11 changes: 7 additions & 4 deletions src/Ast/AstSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function compilePattern(string $pattern, AstSearchOptions $options): Patt

/**
* @param list<Node> $statements
* @param callable(): string|string|null $source
* @param (callable(): string)|string|null $source
* @return list<AstMatch>
*/
public function searchParsedStatements(
Expand All @@ -153,9 +153,12 @@ public function searchParsedStatements(
}

if ($loadedSource === null) {
$loadedSource = is_callable($source)
? (string) $source()
: (string) ($source ?? '');
if (is_callable($source)) {
$invoked = $source();
$loadedSource = is_string($invoked) ? $invoked : '';
} else {
$loadedSource = $source ?? '';
}
}

$matches[] = $this->createMatch($candidate, $captures, $loadedSource, $file);
Expand Down
2 changes: 1 addition & 1 deletion src/Ast/PatternMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function fingerprintNode(Node $node): string
}

/**
* @param array<int, mixed> $subNodeValue
* @param array<array-key, mixed> $subNodeValue
* @return list<string>
*/
private function serializeSubNodeArray(array $subNodeValue): array
Expand Down
4 changes: 4 additions & 0 deletions src/Cli/IndexApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,10 @@ private function directorySize(string $path): int
);

foreach ($iterator as $entry) {
if (!$entry instanceof \SplFileInfo) {
continue;
}

$entrySize = $entry->getSize();
$size += is_int($entrySize) ? $entrySize : 0;
}
Expand Down
52 changes: 29 additions & 23 deletions src/FeatureMatrix/FeatureMatrixGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@
use Greph\Support\ProcessResult;
use Greph\Support\ToolResolver;

/**
* @phpstan-type FeatureMatrixResult array{
* status: string,
* command: ?list<string>,
* exit_code: ?int,
* stdout: string,
* stderr: string,
* note: string
* }
* @phpstan-type FeatureMatrixRow array{
* feature: string,
* notes: string,
* results: array<string, FeatureMatrixResult>
* }
* @phpstan-type FeatureMatrixSection array{
* title: string,
* providers: list<string>,
* rows: list<FeatureMatrixRow>
* }
* @phpstan-type FeatureMatrixReport array{
* generated_at: string,
* root_path: string,
* sections: list<FeatureMatrixSection>
* }
*/
final class FeatureMatrixGenerator
{
private const STATUS_PASS = 'Pass';
Expand All @@ -29,26 +54,7 @@ public function __construct(
}

/**
* @return array{
* generated_at: string,
* root_path: string,
* sections: list<array{
* title: string,
* providers: list<string>,
* rows: list<array{
* feature: string,
* notes: string,
* results: array<string, array{
* status: string,
* command: ?list<string>,
* exit_code: ?int,
* stdout: string,
* stderr: string,
* note: string
* }>
* }>
* }>
* }
* @return FeatureMatrixReport
*/
public function generate(): array
{
Expand Down Expand Up @@ -1509,7 +1515,7 @@ private function normalizeOutput(string $output, string $workspace): string
}

/**
* @param array<string, mixed> $report
* @param FeatureMatrixReport $report
*/
public function renderMarkdown(array $report): string
{
Expand Down Expand Up @@ -1574,7 +1580,7 @@ private function escapeInline(string $value): string
}

/**
* @return array<string, mixed>
* @return FeatureMatrixReport
*/
public function write(string $markdownPath, string $jsonPath): array
{
Expand Down Expand Up @@ -1888,7 +1894,7 @@ private static function expectGrephTextJson(ProcessResult $result): ?string
}

foreach ($decoded as $entry) {
if (($entry['file'] ?? null) === 'single.txt') {
if (is_array($entry) && ($entry['file'] ?? null) === 'single.txt') {
return null;
}
}
Expand Down
25 changes: 23 additions & 2 deletions src/Index/AstCacheStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ public function load(string $indexPath): AstCache
* cached: bool
* }> $facts
*/
$buildDuration = $metadata['buildDurationMs'] ?? 0.0;
$buildDurationMs = is_int($buildDuration) || is_float($buildDuration) ? (float) $buildDuration : 0.0;
$stringKeyedMetadata = self::stringKeyed($metadata);

return new AstCache(
rootPath: $metadata['rootPath'],
indexPath: Filesystem::normalizePath($indexPath),
version: $metadata['version'],
builtAt: $metadata['builtAt'],
buildDurationMs: (float) ($metadata['buildDurationMs'] ?? 0.0),
lifecycle: IndexLifecycle::fromMetadata($metadata),
buildDurationMs: $buildDurationMs,
lifecycle: IndexLifecycle::fromMetadata($stringKeyedMetadata),
nextFileId: $metadata['nextFileId'],
files: $files,
facts: $facts,
Expand Down Expand Up @@ -295,4 +299,21 @@ private function writeAtomic(string $path, mixed $payload): void
throw new \RuntimeException(sprintf('Failed to finalize AST cache file: %s', $path));
}
}

/**
* @param array<array-key, mixed> $array
* @return array<string, mixed>
*/
private static function stringKeyed(array $array): array
{
$result = [];

foreach ($array as $key => $value) {
if (is_string($key)) {
$result[$key] = $value;
}
}

return $result;
}
}
8 changes: 7 additions & 1 deletion src/Index/AstFactExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ private function isObjectOperator(mixed $token): bool

private function tokenId(mixed $token): ?int
{
return is_array($token) ? $token[0] : null;
if (!is_array($token)) {
return null;
}

$id = $token[0] ?? null;

return is_int($id) ? $id : null;
}

private function blocksFunctionCallClassification(mixed $previousToken): bool
Expand Down
Loading
Loading