Skip to content

Commit

Permalink
add types
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jul 17, 2024
1 parent 2e870c8 commit 455f6b6
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 13 deletions.
118 changes: 109 additions & 9 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,21 +1,121 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\|Pest\\\\Support\\\\HigherOrderTapProxy\\:\\:get\\(\\)\\.$#"
count: 2
path: src/RouteTesting.php
message: "#^Function Spatie\\\\RouteTesting\\\\routeTesting\\(\\) has no return type specified\\.$#"
count: 1
path: src/Autoload.php

-
message: "#^Parameter \\#1 \\$testCall of class Spatie\\\\RouteTesting\\\\RouteTestingTestCall constructor expects Pest\\\\PendingCalls\\\\TestCall, Pest\\\\PendingCalls\\\\TestCall\\|Pest\\\\Support\\\\HigherOrderTapProxy given\\.$#"
count: 1
path: src/Autoload.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteResolver\\:\\:bindingNames\\(\\) has parameter \\$bindingNames with no value type specified in iterable type array\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteResolver\\:\\:exceptPaths\\(\\) has parameter \\$paths with no value type specified in iterable type array\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteResolver\\:\\:getBindingsFromUrl\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteResolver\\:\\:getFilteredRouteList\\(\\) should return array\\<int, array\\{method\\: string, uri\\: string\\}\\> but returns array\\<int, mixed\\>\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteResolver\\:\\:paths\\(\\) has parameter \\$paths with no value type specified in iterable type array\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteResolver\\:\\:resolveFullRouteList\\(\\) should return Illuminate\\\\Support\\\\Collection\\<int, array\\{method\\: string, uri\\: string\\}\\> but returns Illuminate\\\\Support\\\\Collection\\<int, array\\{method\\: string, uri\\: mixed\\}\\>\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:flatMap\\(\\) expects callable\\(mixed, int\\|string\\)\\: \\(array\\<int, array\\{method\\: string, uri\\: mixed\\}\\>\\|Illuminate\\\\Support\\\\Collection\\<int, array\\{method\\: string, uri\\: mixed\\}\\>\\), Closure\\(array\\)\\: Illuminate\\\\Support\\\\Collection\\<int, array\\{method\\: string, uri\\: mixed\\}\\> given\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Parameter \\#1 \\$value of function collect expects Illuminate\\\\Contracts\\\\Support\\\\Arrayable\\<\\(int\\|string\\), mixed\\>\\|iterable\\<\\(int\\|string\\), mixed\\>\\|null, mixed given\\.$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Unable to resolve the template type TKey in call to function collect$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Unable to resolve the template type TValue in call to function collect$#"
count: 1
path: src/RouteResolver.php

-
message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\:\\:defer\\(\\)\\.$#"
count: 1
path: src/RouteTest.php

-
message: "#^Cannot call method toRoute\\(\\) on Illuminate\\\\Contracts\\\\Routing\\\\UrlGenerator\\|string\\.$#"
count: 1
path: src/RouteTest.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteTest\\:\\:test\\(\\) has parameter \\$assertions with no value type specified in iterable type array\\.$#"
count: 1
path: src/RouteTest.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:first\\(\\) expects \\(callable\\(mixed, int\\|string\\)\\: bool\\)\\|null, Closure\\(Illuminate\\\\Routing\\\\Route\\)\\: bool given\\.$#"
count: 1
path: src/RouteTest.php

-
message: "#^Unable to resolve the template type TKey in call to function collect$#"
count: 1
path: src/RouteTest.php

-
message: "#^Unable to resolve the template type TValue in call to function collect$#"
count: 1
path: src/RouteTest.php

-
message: "#^Undefined variable\\: \\$this$#"
count: 6
path: src/RouteTest.php

-
message: "#^Variable \\$this on left side of \\?\\? is never defined\\.$#"
count: 1
path: src/RouteTest.php

-
message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\:\\:defer\\(\\)\\.$#"
count: 1
path: src/RouteTestingTestCall.php

-
message: "#^Method Spatie\\\\RouteTesting\\\\RouteTesting\\:\\:routesToAssert\\(\\) should return array\\<Illuminate\\\\Routing\\\\Route\\> but returns array\\<string, mixed\\>\\.$#"
message: "#^Method Spatie\\\\RouteTesting\\\\RouteTestingTestCall\\:\\:__call\\(\\) has parameter \\$method with no type specified\\.$#"
count: 1
path: src/RouteTesting.php
path: src/RouteTestingTestCall.php

-
message: "#^Parameter \\#1 \\$haystack of function str_starts_with expects string, string\\|null given\\.$#"
message: "#^Method Spatie\\\\RouteTesting\\\\RouteTestingTestCall\\:\\:__call\\(\\) has parameter \\$parameters with no type specified\\.$#"
count: 1
path: src/RouteTesting.php
path: src/RouteTestingTestCall.php

-
message: "#^Property Spatie\\\\RouteTesting\\\\RouteTesting\\:\\:\\$assertedRoutes \\(array\\<string, Illuminate\\\\Routing\\\\Route\\>\\) does not accept array\\.$#"
message: "#^Method Spatie\\\\RouteTesting\\\\RouteTestingTestCall\\:\\:with\\(\\) has parameter \\$routes with no value type specified in iterable type array\\.$#"
count: 1
path: src/RouteTesting.php
path: src/RouteTestingTestCall.php
15 changes: 11 additions & 4 deletions src/RouteResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@

class RouteResolver
{
/** @var array<int, string>|null */
protected ?array $paths = null;

/** @var array<int, string>|null */
protected ?array $exceptPaths = null;

/** @var array<int, string> */
protected array $methods = ['GET'];

protected bool $exceptRoutesWithMissingBindings = false;

/** @var array<int, string> */
protected array $bindingNames = [];

/** @var Collection<int, array{method: string, uri: string}> */
Expand All @@ -34,7 +38,7 @@ protected function resolveFullRouteList(): Collection
$routes = json_decode($result->output(), true);

return collect($routes)->flatMap(
fn ($route) => Str::of($route['method'])
fn (array $route) => Str::of($route['method'])
->explode('|')
->intersect($this->methods)
->map(fn ($method) => ['method' => $method, 'uri' => $route['uri']])
Expand Down Expand Up @@ -69,25 +73,28 @@ public function exceptRoutesWithMissingBindings(): self
return $this;
}

/**
* @return array<int, array{method: string, uri: string}>
*/
public function getFilteredRouteList(): array
{
return $this->fullRouteList
->filter(function ($route) {
->filter(function (array $route) {
if ($this->paths) {
return collect($this->paths)->contains(fn ($path) => Str::is($path, $route['uri']));
}

return true;
})
->filter(function ($route) {
->filter(function (array $route) {
if ($this->exceptPaths) {
return ! collect($this->exceptPaths)->contains(fn ($path) => Str::is($path, $route['uri']));
}

return true;
})
->when($this->exceptRoutesWithMissingBindings, function (Collection $routes) {
return $routes->filter(function ($route) {
return $routes->filter(function (array $route) {
$uriBindings = $this->getBindingsFromUrl($route['uri']);

if (count($uriBindings) === 0) {
Expand Down

0 comments on commit 455f6b6

Please sign in to comment.