Skip to content

Commit

Permalink
chore: fix psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ksassnowski committed Mar 22, 2024
1 parent 337b628 commit 653347a
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 42 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"psr/container": "^2.0.2",
"psy/psysh": "^0.11.22 || ^0.12.0",
"spatie/robots-txt": "^2.0.3",
"symfony/console": "^6.3.8 || ^7.0",
"symfony/css-selector": "^6.3.2 || ^7.0",
"symfony/dom-crawler": "^6.3.4 || ^7.0",
"symfony/event-dispatcher": "^6.3.2 || ^7.0",
"symfony/options-resolver": "^6.3 || ^7.0"
"symfony/console": "^7.0",
"symfony/css-selector": "^7.0",
"symfony/dom-crawler": "^7.0",
"symfony/event-dispatcher": "^7.0",
"symfony/options-resolver": "^7.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.39",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

2 changes: 1 addition & 1 deletion src/Core/FakeRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class FakeRunner implements RunnerInterface
{
/**
* @var list<class-string<SpiderInterface>, array<int, array{overrides: null|Overrides, context: array}>>
* @var array<class-string<SpiderInterface>, array<int, array{overrides: null|Overrides, context: array}>>
*/
private array $runs = [];

Expand Down
10 changes: 5 additions & 5 deletions src/Core/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
final class Run
{
/**
* @param list<Request> $startRequests
* @param list<DownloaderMiddlewareInterface> $downloaderMiddleware
* @param list<ItemProcessorInterface> $itemProcessors
* @param list<SpiderMiddlewareInterface> $responseMiddleware
* @param list<ExtensionInterface> $extensions
* @param array<array-key, Request> $startRequests
* @param array<array-key, DownloaderMiddlewareInterface> $downloaderMiddleware
* @param array<array-key, ItemProcessorInterface> $itemProcessors
* @param array<array-key, SpiderMiddlewareInterface> $responseMiddleware
* @param array<array-key, ExtensionInterface> $extensions
*/
public function __construct(
public array $startRequests,
Expand Down
16 changes: 8 additions & 8 deletions src/Core/RunFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function fromSpider(SpiderInterface $spider, ?Overrides $overrides = null
}

/**
* @psalm-param class-string<DownloaderMiddlewareInterface>[] $downloaderMiddleware
* @param array<array-key, class-string<DownloaderMiddlewareInterface>> $downloaderMiddleware
*
* @return list<DownloaderMiddlewareInterface>
* @return array<array-key, DownloaderMiddlewareInterface>
*/
private function buildDownloaderMiddleware(array $downloaderMiddleware): array
{
Expand All @@ -63,19 +63,19 @@ private function buildDownloaderMiddleware(array $downloaderMiddleware): array
}

/**
* @psalm-param array<class-string<ItemProcessorInterface>> $processors
* @param array<array-key, class-string<ItemProcessorInterface>> $processors
*
* @return list<ItemProcessorInterface>
* @return array<array-key, ItemProcessorInterface>
*/
private function buildItemPipeline(array $processors): array
{
return \array_map([$this, 'buildConfigurable'], $processors);
}

/**
* @psalm-param array<class-string<SpiderMiddlewareInterface>> $handlers
* @param array<array-key, class-string<SpiderMiddlewareInterface>> $handlers
*
* @return list<SpiderMiddlewareInterface>
* @return array<array-key, SpiderMiddlewareInterface>
*/
private function buildResponseMiddleware(array $handlers): array
{
Expand All @@ -85,9 +85,9 @@ private function buildResponseMiddleware(array $handlers): array
}

/**
* @param list<class-string<ExtensionInterface>> $extensions
* @param array<array-key, class-string<ExtensionInterface>> $extensions
*
* @return list<ExtensionInterface>
* @return array<array-key, ExtensionInterface>
*/
private function buildExtensions(array $extensions): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Downloader/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
final class Downloader
{
/**
* @var list<DownloaderMiddlewareInterface>
* @var array<array-key, DownloaderMiddlewareInterface>
*/
private array $middleware = [];

Expand Down
2 changes: 1 addition & 1 deletion src/ItemPipeline/AbstractItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ final public function offsetSet(mixed $offset, mixed $value): void

final public function offsetUnset(mixed $offset): void
{
throw new RuntimeException('Unsetting properties is not supported for custom item classes');
throw new \RuntimeException('Unsetting properties is not supported for custom item classes');
}
}
2 changes: 1 addition & 1 deletion src/ItemPipeline/ItemPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
final class ItemPipeline implements ItemPipelineInterface
{
/**
* @var list<ItemProcessorInterface>
* @var array<array-key, ItemProcessorInterface>
*/
private array $processors = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Roach.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function startSpider(string $spiderClass, ?Overrides $overrides =
*
* @psalm-param class-string<SpiderInterface> $spiderClass
*
* @return list<ItemInterface>
* @return array<array-key, ItemInterface>
*/
public static function collectSpider(string $spiderClass, ?Overrides $overrides = null, array $context = []): array
{
Expand Down
6 changes: 4 additions & 2 deletions src/Scheduling/ArrayRequestScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function empty(): bool
}

/**
* @return list<Request>
* @return array<array-key, Request>
*/
public function nextRequests(int $batchSize): array
{
Expand Down Expand Up @@ -77,7 +77,9 @@ private function updateNextBatchTime(): void
}

/**
* @return list<Request>
* @psalm-suppress MixedReturnTypeCoercion
*
* @return array<array-key, Request>
*/
private function getNextRequests(int $batchSize): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Scheduling/RequestSchedulerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public function schedule(Request $request): void;
* Return the next number of requests as defined by $batchSize as soon
* as they are ready.
*
* @return list<Request>
* @return array<array-key, Request>
*/
public function nextRequests(int $batchSize): array;

/**
* Immediately return the next number of requests as defined by $batchSize
* regardless of the configured delay.
*
* @return list<Request>
* @return array<array-key, Request>
*/
public function forceNextRequests(int $batchSize): array;

Expand Down
2 changes: 1 addition & 1 deletion src/Shell/Commands/FetchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#[AsCommand(name: 'fetch')]
final class FetchCommand extends Command
{
protected static $defaultName = 'fetch';
protected static string $defaultName = 'fetch';

protected function configure(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Shell/Commands/RunSpiderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#[AsCommand(name: 'roach:run')]
final class RunSpiderCommand extends Command
{
protected static $defaultName = 'roach:run';
protected static string $defaultName = 'roach:run';

protected static $defaultDescription = 'Start a spider run for the provided spider class';
protected static string $defaultDescription = 'Start a spider run for the provided spider class';

protected function configure(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Shell/Repl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#[AsCommand(name: 'roach:shell')]
final class Repl extends Command
{
protected static $defaultName = 'roach:shell';
protected static string $defaultName = 'roach:shell';

protected static $defaultDescription = 'Launch an interactive roach shell';
protected static string $defaultDescription = 'Launch an interactive roach shell';

protected function configure(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Spider/AbstractSpider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(ConfigurationLoaderStrategy $loaderStrategy)
abstract public function parse(Response $response): \Generator;

/**
* @return list<Request>
* @return array<array-key, Request>
*/
final public function getInitialRequests(): array
{
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function item(array|ItemInterface $item): ParseResult
}

/**
* @return list<Request>
* @return array<array-key, Request>
*/
protected function initialRequests(): array
{
Expand Down
10 changes: 5 additions & 5 deletions src/Spider/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
final class Configuration
{
/**
* @param list<string> $startUrls
* @param list<class-string<DownloaderMiddlewareInterface>> $downloaderMiddleware
* @param list<class-string<ItemProcessorInterface>> $itemProcessors
* @param list<class-string<SpiderMiddlewareInterface>> $spiderMiddleware
* @param list<class-string<ExtensionInterface>> $extensions
* @param array<array-key, string> $startUrls
* @param array<array-key, class-string<DownloaderMiddlewareInterface>> $downloaderMiddleware
* @param array<array-key, class-string<ItemProcessorInterface>> $itemProcessors
* @param array<array-key, class-string<SpiderMiddlewareInterface>> $spiderMiddleware
* @param array<array-key, class-string<ExtensionInterface>> $extensions
*/
public function __construct(
public array $startUrls,
Expand Down
2 changes: 1 addition & 1 deletion src/Spider/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class Processor
{
/**
* @var list<SpiderMiddlewareInterface>
* @var array<array-key, SpiderMiddlewareInterface>
*/
private array $middleware = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Spider/SpiderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function withConfiguration(Configuration $configuration): void;
public function withContext(array $context): void;

/**
* @return list<Request>
* @return array<array-key, Request>
*/
public function getInitialRequests(): array;
}

0 comments on commit 653347a

Please sign in to comment.