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
5 changes: 5 additions & 0 deletions src/Integration/CacheBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(
public function get(string $key): ?DiscoveryResult
{
/** @var DiscoveryResult|null $result */
// @phpstan-ignore method.notFound
$result = $this->simpleCache->get($this->prefix . $key);

return $result instanceof DiscoveryResult ? $result : null;
Expand All @@ -47,6 +48,7 @@ public function get(string $key): ?DiscoveryResult
#[\Override]
public function set(string $key, DiscoveryResult $result, int $ttl = 3600): void
{
// @phpstan-ignore method.notFound
$this->simpleCache->set(
$this->prefix . $key,
$result,
Expand All @@ -57,6 +59,7 @@ public function set(string $key, DiscoveryResult $result, int $ttl = 3600): void
#[\Override]
public function delete(string $key): void
{
// @phpstan-ignore method.notFound
$this->simpleCache->delete($this->prefix . $key);
}

Expand All @@ -65,12 +68,14 @@ public function clear(): void
{
// PSR-16 clear() clears everything — not ideal.
// Prefer iterating known keys if the cache supports it.
// @phpstan-ignore method.notFound
$this->simpleCache->clear();
}

#[\Override]
public function has(string $key): bool
{
// @phpstan-ignore method.notFound
return $this->simpleCache->has($this->prefix . $key);
}
}
6 changes: 6 additions & 0 deletions src/Integration/ConfiguratorBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@
*/
public static function createScanner(array $config = []): Scanner
{
// @phpstan-ignore cast.int (mixed from array<string,mixed>)
$maxFileSize = (int) ($config['max_file_size'] ?? 10 * 1024 * 1024);
// @phpstan-ignore cast.int (mixed from array<string,mixed>)
$maxFiles = (int) ($config['max_files'] ?? 10_000);

$resolver = new ComposerNamespaceResolver(
// @phpstan-ignore argument.type (mixed from array<string,mixed>, null-safe)
composerJsonPath: $config['composer_json'] ?? null,
includeDevAutoload: (bool) ($config['include_dev'] ?? false),
);

$scanner = new AttributeScanner($resolver, $maxFileSize, $maxFiles);

// @phpstan-ignore offsetAccess.nonOffsetAccessible (mixed from array<string,mixed>)
$cacheEnabled = (bool) ($config['cache']['enabled'] ?? true);

if ($cacheEnabled) {
// @phpstan-ignore argument.type (mixed from array<string,mixed>)
$scanner->setCacheStrategy(self::createCacheStrategy($config['cache'] ?? []));
}

Expand All @@ -67,6 +72,7 @@ public static function createScanner(array $config = []): Scanner
*/
public static function createCacheStrategy(array $cacheConfig = []): CacheStrategy
{
// @phpstan-ignore cast.string (mixed from array<string,mixed>)
$dir = (string) ($cacheConfig['dir'] ?? sys_get_temp_dir() . '/kariricode_discovery');

return new ChainCacheStrategy(
Expand Down
3 changes: 3 additions & 0 deletions src/Result/DiscoveryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public function count(): int
return \count($this->classes);
}

/**
* @return \ArrayIterator<string, ClassMetadata>
*/
#[\Override]
public function getIterator(): \ArrayIterator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Scanner/ComposerNamespaceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function loadFromComposerJson(string $path, bool $includeDevAutoload): v

$baseDir = \dirname(realpath($path) ?: $path);

$this->extractPsr4Mappings($data['autoload']['psr-4'] ?? [], $baseDir);
$this->extractPsr4Mappings($data['autoload']['psr-4'] ?? [], $baseDir); // @phpstan-ignore offsetAccess.nonOffsetAccessible, argument.type

if ($includeDevAutoload) {
$this->extractPsr4Mappings($data['autoload-dev']['psr-4'] ?? [], $baseDir);
Expand Down
5 changes: 3 additions & 2 deletions src/Scanner/DirectoryScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class DirectoryScanner implements DirectoryScannerContract
private readonly FileScanner $fileScanner;

public function __construct(
/** @phpstan-ignore property.onlyWritten (stored for future use / interface requirement) */
private readonly NamespaceResolver $namespaceResolver,
) {
$this->fileScanner = new FileScanner($namespaceResolver);
Expand Down Expand Up @@ -178,9 +179,9 @@ private function collectFromDirectory(string $directory, string $root, int $dept
$fullPath = $target;
}

// $fullPath is guaranteed to be string at this point.
// $fullPath is guaranteed to be non-empty-string at this point.
// Psalm cannot infer this after the symlink branch, so we assert.
/** @var string $fullPath */
/** @var non-empty-string $fullPath */
if (is_dir($fullPath)) {
$files = array_merge(
$files,
Expand Down
1 change: 1 addition & 0 deletions src/Scanner/FileScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class FileScanner implements ScannerContract
private ?CacheStrategy $cache = null;

public function __construct(
/** @phpstan-ignore property.onlyWritten (stored for interface contract compliance) */
private readonly NamespaceResolver $namespaceResolver,
private readonly int $maxFileSize = self::MAX_FILE_SIZE,
private readonly int $maxFiles = self::MAX_FILES_PER_SCAN,
Expand Down
Loading