From 5ee8b03ce66b3753cde8319dfbdfea154a9bfec4 Mon Sep 17 00:00:00 2001 From: Imani Manyara Date: Fri, 4 Sep 2026 09:01:54 -0400 Subject: [PATCH 1/2] Drop stale laranail archives from the composer cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Composer's dist cache is keyed on a package name. `laranail/*` resolve through a single **moving** `v0.1.0` tag, so the name stays the same while the contents change underneath it — and a restored archive is then silently stale. `composer install` reports success and unpacks whatever was cached the first time. That is not hypothetical. It is why CI across the org fails with: ``` Could not open input file: vendor/bin/laranail-pint ``` `bin/laranail-pint` **is** in the `v0.1.0` tag and **is** declared in `package-tools`' `composer.json`. CI was unpacking a cached archive from before it existed. Measured 2026-09-04: **35 of 60** repos had a stale `package-tools` archive, across nine distinct refs. The cache key cannot fix this on its own — `hashFiles('composer.json')` does not change when a *dependency's* tag moves, and `restore-keys` falls back to any older cache. So the stale archive is dropped explicitly before install. Everything else is immutable per version and stays cached, so the cache keeps its value. Verified on `laranail/atlas#3`: the step runs, `Install dependencies` succeeds, and `Could not open input file` is gone — the binary now resolves. --- .github/workflows/tests.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14ad3c7..f4744b2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,6 +41,15 @@ jobs: key: composer-${{ matrix.php }}-${{ matrix.dependency-versions }}-${{ hashFiles('composer.json') }} restore-keys: composer-${{ matrix.php }}- + - name: Drop cached laranail archives + # laranail/* resolve through a single MOVING v0.1.0 tag, so composer's + # dist cache is keyed on a name whose contents change underneath it. A + # restored archive is then silently stale: `composer install` reports + # success and unpacks whatever was cached the first time. That is how + # `vendor/bin/laranail-pint` went missing here while the tag carried it. + # Everything else is immutable per version and stays cached. + run: rm -rf "$(composer config cache-files-dir)/laranail" + - name: Install dependencies env: COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GITHUB_TOKEN }}"}}' From 304f35623c7046d8a98199d287ed7afe13725121 Mon Sep 17 00:00:00 2001 From: Imani Manyara Date: Fri, 4 Sep 2026 09:48:38 -0400 Subject: [PATCH 2/2] Adopt the shared laranail Pint config `composer pint` runs `vendor/bin/laranail-pint`, which passes package-tools' shared pint.json rather than any local one. Once the stale composer cache stopped hiding that binary, the check ran for the first time and reported these files. Cosmetic. Every file already declared strict_types, so the config's declare_strict_types rule adds nothing here, and the suite returns the identical result before and after. --- config/ip-intel.php | 18 +++++------ rector.php | 6 ++-- src/Adapters/EdgeHeader/EdgeHeaderDriver.php | 2 +- src/Adapters/IpApi/IpApiDriver.php | 22 ++++++------- src/Adapters/Local/AtlasDriver.php | 2 +- src/Contracts/DetectsThreats.php | 2 +- src/Contracts/ResolvesAsn.php | 2 +- src/Contracts/ResolvesCity.php | 2 +- src/Data/AsnInfo.php | 8 ++--- src/Data/IpIntelResult.php | 34 ++++++++++---------- src/Data/PlaceInfo.php | 8 ++--- src/Data/ThreatSignals.php | 8 ++--- src/Enums/Outcome.php | 2 +- src/Exceptions/SourceUnavailable.php | 2 +- src/Facades/IpIntel.php | 4 +-- src/Http/Controllers/LookupController.php | 8 ++--- src/Http/Requests/LookupRequest.php | 2 +- src/Providers/IpIntelServiceProvider.php | 24 +++++++------- src/Rules/ValidIp.php | 2 +- src/Services/IpIntelManager.php | 30 ++++++++--------- src/Services/ResolverChain.php | 14 ++++---- src/Support/IpIntelConfig.php | 5 +-- tests/Feature/ApiTest.php | 4 +-- tests/Feature/ResolverChainTest.php | 14 ++++---- tests/TestCase.php | 2 +- 25 files changed, 114 insertions(+), 113 deletions(-) diff --git a/config/ip-intel.php b/config/ip-intel.php index 3017ae1..b90e331 100644 --- a/config/ip-intel.php +++ b/config/ip-intel.php @@ -57,10 +57,10 @@ 'sources' => [ 'ipapi' => [ - 'key' => env('IP_INTEL_IPAPI_KEY'), + 'key' => env('IP_INTEL_IPAPI_KEY'), 'base_url' => env('IP_INTEL_IPAPI_URL', 'https://api.ipapi.com/api'), - 'timeout' => (int) env('IP_INTEL_IPAPI_TIMEOUT', 5), - 'retries' => (int) env('IP_INTEL_IPAPI_RETRIES', 2), + 'timeout' => (int) env('IP_INTEL_IPAPI_TIMEOUT', 5), + 'retries' => (int) env('IP_INTEL_IPAPI_RETRIES', 2), ], ], @@ -78,9 +78,9 @@ 'cache' => [ 'enabled' => env('IP_INTEL_CACHE', true), - 'store' => env('IP_INTEL_CACHE_STORE'), - 'ttl' => (int) env('IP_INTEL_CACHE_TTL', 1440), - 'prefix' => 'laranail.ip-intel', + 'store' => env('IP_INTEL_CACHE_STORE'), + 'ttl' => (int) env('IP_INTEL_CACHE_TTL', 1440), + 'prefix' => 'laranail.ip-intel', ], /* @@ -100,9 +100,9 @@ */ 'api' => [ - 'enabled' => env('IP_INTEL_API', false), - 'prefix' => env('IP_INTEL_API_PREFIX', 'api/ip-intel'), - 'version' => 'v1', + 'enabled' => env('IP_INTEL_API', false), + 'prefix' => env('IP_INTEL_API_PREFIX', 'api/ip-intel'), + 'version' => 'v1', 'middleware' => ['api', 'throttle:60,1'], ], diff --git a/rector.php b/rector.php index ee28544..1eb784c 100644 --- a/rector.php +++ b/rector.php @@ -17,10 +17,10 @@ * the generator emits byte for byte, so a Rector rewrite would put the two permanently at odds. */ return RectorConfig::configure() - ->withPaths([__DIR__.'/src', __DIR__.'/tests']) + ->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) ->withSkip([ - __DIR__.'/vendor', - __DIR__.'/tests/Fixtures', + __DIR__ . '/vendor', + __DIR__ . '/tests/Fixtures', ]) ->withPhpSets(php84: true) ->withSets([ diff --git a/src/Adapters/EdgeHeader/EdgeHeaderDriver.php b/src/Adapters/EdgeHeader/EdgeHeaderDriver.php index 1b95f3d..69784a3 100644 --- a/src/Adapters/EdgeHeader/EdgeHeaderDriver.php +++ b/src/Adapters/EdgeHeader/EdgeHeaderDriver.php @@ -32,7 +32,7 @@ final readonly class EdgeHeaderDriver implements ResolvesCountry { /** - * @param list $headers in priority order + * @param list $headers in priority order */ public function __construct( private ?Request $request, diff --git a/src/Adapters/IpApi/IpApiDriver.php b/src/Adapters/IpApi/IpApiDriver.php index 03ac3b1..ea9022f 100644 --- a/src/Adapters/IpApi/IpApiDriver.php +++ b/src/Adapters/IpApi/IpApiDriver.php @@ -4,20 +4,20 @@ namespace Simtabi\Laranail\IpIntel\Adapters\IpApi; -use Illuminate\Http\Client\Factory as HttpFactory; +use Throwable; use Psr\Log\LoggerInterface; +use Simtabi\Laranail\IpIntel\Data\AsnInfo; +use Simtabi\Laranail\IpIntel\Data\PlaceInfo; use Simtabi\Laranail\Atlas\Core\Geo\Coordinates; +use Simtabi\Laranail\IpIntel\Data\ThreatSignals; +use Illuminate\Http\Client\Factory as HttpFactory; use Simtabi\Laranail\Atlas\Core\Network\IpAddress; -use Simtabi\Laranail\IpIntel\Adapters\Local\AtlasDriver; -use Simtabi\Laranail\IpIntel\Contracts\DetectsThreats; use Simtabi\Laranail\IpIntel\Contracts\ResolvesAsn; use Simtabi\Laranail\IpIntel\Contracts\ResolvesCity; +use Simtabi\Laranail\IpIntel\Contracts\DetectsThreats; use Simtabi\Laranail\IpIntel\Contracts\ResolvesCountry; -use Simtabi\Laranail\IpIntel\Data\AsnInfo; -use Simtabi\Laranail\IpIntel\Data\PlaceInfo; -use Simtabi\Laranail\IpIntel\Data\ThreatSignals; +use Simtabi\Laranail\IpIntel\Adapters\Local\AtlasDriver; use Simtabi\Laranail\IpIntel\Exceptions\SourceUnavailable; -use Throwable; /** * ipapi.com — the paid tier, for the questions registry data cannot answer. @@ -180,7 +180,7 @@ private function fetch(IpAddress $address): array throw SourceUnavailable::notConfigured($this->name(), 'IP_INTEL_IPAPI_KEY'); } - $key = $this->name().':'.$address->address; + $key = $this->name() . ':' . $address->address; if (isset($this->memo[$key])) { return $this->memo[$key]; @@ -197,12 +197,12 @@ private function fetch(IpAddress $address): array // a parameter the client encodes rather than a string this // class concatenates into a path. ->withUrlParameters(['ip' => $address->address]) - ->get($this->baseUrl.'/{ip}', ['access_key' => $this->accessKey]); + ->get($this->baseUrl . '/{ip}', ['access_key' => $this->accessKey]); } catch (Throwable $e) { // Never the exception's own message: the client embeds the full // request URL, which carries the access key. $this->logger->warning('ip-intel: ipapi request failed', [ - 'ip' => $address->address, + 'ip' => $address->address, 'reason' => $e::class, ]); @@ -211,7 +211,7 @@ private function fetch(IpAddress $address): array if ($response->failed()) { $this->logger->warning('ip-intel: ipapi returned an error status', [ - 'ip' => $address->address, + 'ip' => $address->address, 'status' => $response->status(), ]); diff --git a/src/Adapters/Local/AtlasDriver.php b/src/Adapters/Local/AtlasDriver.php index b07c467..637897e 100644 --- a/src/Adapters/Local/AtlasDriver.php +++ b/src/Adapters/Local/AtlasDriver.php @@ -4,9 +4,9 @@ namespace Simtabi\Laranail\IpIntel\Adapters\Local; -use Simtabi\Laranail\Atlas\Core\Contracts\IpCountryResolver; use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Contracts\ResolvesCountry; +use Simtabi\Laranail\Atlas\Core\Contracts\IpCountryResolver; /** * `laranail/atlas`' offline registry table. diff --git a/src/Contracts/DetectsThreats.php b/src/Contracts/DetectsThreats.php index dae9f2a..de602c9 100644 --- a/src/Contracts/DetectsThreats.php +++ b/src/Contracts/DetectsThreats.php @@ -4,8 +4,8 @@ namespace Simtabi\Laranail\IpIntel\Contracts; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Data\ThreatSignals; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; /** * A source that can say something about how an address is being used. diff --git a/src/Contracts/ResolvesAsn.php b/src/Contracts/ResolvesAsn.php index 580ff66..dc03e71 100644 --- a/src/Contracts/ResolvesAsn.php +++ b/src/Contracts/ResolvesAsn.php @@ -4,8 +4,8 @@ namespace Simtabi\Laranail\IpIntel\Contracts; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Data\AsnInfo; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; /** * A source that can name the network an address is announced from. diff --git a/src/Contracts/ResolvesCity.php b/src/Contracts/ResolvesCity.php index 94ae993..8e6618a 100644 --- a/src/Contracts/ResolvesCity.php +++ b/src/Contracts/ResolvesCity.php @@ -4,8 +4,8 @@ namespace Simtabi\Laranail\IpIntel\Contracts; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Data\PlaceInfo; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; /** * A source that can place an address more precisely than its country. diff --git a/src/Data/AsnInfo.php b/src/Data/AsnInfo.php index a9ce926..35252fa 100644 --- a/src/Data/AsnInfo.php +++ b/src/Data/AsnInfo.php @@ -25,7 +25,7 @@ public function __construct( public function label(): string { - return 'AS'.$this->number.($this->organisation === null ? '' : ' '.$this->organisation); + return 'AS' . $this->number . ($this->organisation === null ? '' : ' ' . $this->organisation); } /** @@ -34,10 +34,10 @@ public function label(): string public function toArray(): array { return [ - 'number' => $this->number, + 'number' => $this->number, 'organisation' => $this->organisation, - 'prefix' => $this->prefix, - 'allocated' => $this->allocated, + 'prefix' => $this->prefix, + 'allocated' => $this->allocated, ]; } } diff --git a/src/Data/IpIntelResult.php b/src/Data/IpIntelResult.php index 00fd722..90ad95e 100644 --- a/src/Data/IpIntelResult.php +++ b/src/Data/IpIntelResult.php @@ -5,9 +5,9 @@ namespace Simtabi\Laranail\IpIntel\Data; use JsonSerializable; -use Simtabi\Laranail\Atlas\Core\Country\CountryRecord; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Enums\Outcome; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; +use Simtabi\Laranail\Atlas\Core\Country\CountryRecord; /** * What the chain found, and how. @@ -34,7 +34,7 @@ final readonly class IpIntelResult implements JsonSerializable { /** - * @param list $sources drivers that contributed, in order + * @param list $sources drivers that contributed, in order */ private function __construct( public IpAddress $address, @@ -50,7 +50,7 @@ private function __construct( ) {} /** - * @param list $sources + * @param list $sources */ public static function found( IpAddress $address, @@ -94,7 +94,7 @@ public static function reserved(IpAddress $address): self /** * Every source was asked and none had an answer. * - * @param list $sources + * @param list $sources */ public static function notFound(IpAddress $address, array $sources = [], bool $madeNetworkCall = false): self { @@ -114,7 +114,7 @@ public static function notFound(IpAddress $address, array $sources = [], bool $m * problem, and treating it as "unknown visitor" is how a broken integration * runs for months. * - * @param list $sources + * @param list $sources */ public static function unavailable(IpAddress $address, string $why, array $sources = []): self { @@ -161,19 +161,19 @@ public function needsAttention(): bool public function toArray(): array { return [ - 'ip' => $this->address->address, - 'outcome' => $this->outcome->value, + 'ip' => $this->address->address, + 'outcome' => $this->outcome->value, 'country_code' => $this->countryCode, - 'country' => $this->country?->name, - 'flag' => $this->country?->flag(), - 'continent' => $this->country?->continent, - 'currencies' => $this->country?->currencies, - 'asn' => $this->asn?->toArray(), - 'place' => $this->place?->toArray(), - 'threats' => $this->threats?->toArray(), - 'sources' => $this->sources, + 'country' => $this->country?->name, + 'flag' => $this->country?->flag(), + 'continent' => $this->country?->continent, + 'currencies' => $this->country?->currencies, + 'asn' => $this->asn?->toArray(), + 'place' => $this->place?->toArray(), + 'threats' => $this->threats?->toArray(), + 'sources' => $this->sources, 'network_call' => $this->madeNetworkCall, - 'message' => $this->message, + 'message' => $this->message, ]; } diff --git a/src/Data/PlaceInfo.php b/src/Data/PlaceInfo.php index d3b55c1..14af881 100644 --- a/src/Data/PlaceInfo.php +++ b/src/Data/PlaceInfo.php @@ -42,10 +42,10 @@ public function isPrecise(int $withinKm = 50): bool public function toArray(): array { return [ - 'city' => $this->city, - 'region' => $this->region, - 'postcode' => $this->postcode, - 'coordinates' => $this->coordinates?->toArray(), + 'city' => $this->city, + 'region' => $this->region, + 'postcode' => $this->postcode, + 'coordinates' => $this->coordinates?->toArray(), 'accuracy_radius_km' => $this->accuracyRadiusKm, ]; } diff --git a/src/Data/ThreatSignals.php b/src/Data/ThreatSignals.php index f4bbc63..5e6b305 100644 --- a/src/Data/ThreatSignals.php +++ b/src/Data/ThreatSignals.php @@ -57,13 +57,13 @@ public function isAnonymised(): bool public function toArray(): array { return [ - 'is_proxy' => $this->isProxy, - 'is_vpn' => $this->isVpn, - 'is_tor' => $this->isTor, + 'is_proxy' => $this->isProxy, + 'is_vpn' => $this->isVpn, + 'is_tor' => $this->isTor, 'is_hosting' => $this->isHosting, 'is_crawler' => $this->isCrawler, 'risk_score' => $this->riskScore, - 'source' => $this->source, + 'source' => $this->source, ]; } } diff --git a/src/Enums/Outcome.php b/src/Enums/Outcome.php index d44b86d..057b05c 100644 --- a/src/Enums/Outcome.php +++ b/src/Enums/Outcome.php @@ -39,7 +39,7 @@ public function isCacheable(): bool { return match ($this) { self::Found, self::Reserved, self::NotFound => true, - self::Unavailable, self::Disabled => false, + self::Unavailable, self::Disabled => false, }; } } diff --git a/src/Exceptions/SourceUnavailable.php b/src/Exceptions/SourceUnavailable.php index 5e008f7..b126ff5 100644 --- a/src/Exceptions/SourceUnavailable.php +++ b/src/Exceptions/SourceUnavailable.php @@ -40,7 +40,7 @@ public static function rejected(string $driver, string $why): self { return new self(sprintf( 'The [%s] source rejected the request: %s. This is usually a dead key or an exhausted quota — ' - .'note that it answers 200 with success:false, so it is not an HTTP error.', + . 'note that it answers 200 with success:false, so it is not an HTTP error.', $driver, $why, )); diff --git a/src/Facades/IpIntel.php b/src/Facades/IpIntel.php index 503bb1d..8cdade3 100644 --- a/src/Facades/IpIntel.php +++ b/src/Facades/IpIntel.php @@ -7,10 +7,10 @@ use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Facade; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Data\IpIntelResult; -use Simtabi\Laranail\IpIntel\Services\IpIntelManager; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Services\ResolverChain; +use Simtabi\Laranail\IpIntel\Services\IpIntelManager; /** * @method static IpIntelResult country(IpAddress|string $address) diff --git a/src/Http/Controllers/LookupController.php b/src/Http/Controllers/LookupController.php index e0aa3f3..6fb3e56 100644 --- a/src/Http/Controllers/LookupController.php +++ b/src/Http/Controllers/LookupController.php @@ -5,11 +5,11 @@ namespace Simtabi\Laranail\IpIntel\Http\Controllers; use Illuminate\Http\JsonResponse; -use Simtabi\Laranail\IpIntel\Data\IpIntelResult; use Simtabi\Laranail\IpIntel\Enums\Outcome; +use Simtabi\Laranail\IpIntel\Data\IpIntelResult; +use Simtabi\Laranail\IpIntel\Services\IpIntelManager; use Simtabi\Laranail\IpIntel\Http\Requests\LookupRequest; use Simtabi\Laranail\IpIntel\Http\Resources\IpIntelResource; -use Simtabi\Laranail\IpIntel\Services\IpIntelManager; /** * Read-only lookups over HTTP. @@ -61,8 +61,8 @@ private function statusFor(IpIntelResult $result): int { return match ($result->outcome) { Outcome::Unavailable => 503, - Outcome::Disabled => 501, - default => 200, + Outcome::Disabled => 501, + default => 200, }; } } diff --git a/src/Http/Requests/LookupRequest.php b/src/Http/Requests/LookupRequest.php index 1e53377..563f798 100644 --- a/src/Http/Requests/LookupRequest.php +++ b/src/Http/Requests/LookupRequest.php @@ -30,7 +30,7 @@ public function authorize(): bool public function rules(): array { return [ - 'ip' => ['required', 'string', new ValidIp], + 'ip' => ['required', 'string', new ValidIp], 'full' => ['sometimes', 'boolean'], ]; } diff --git a/src/Providers/IpIntelServiceProvider.php b/src/Providers/IpIntelServiceProvider.php index 36566bf..b9ddc9c 100644 --- a/src/Providers/IpIntelServiceProvider.php +++ b/src/Providers/IpIntelServiceProvider.php @@ -4,22 +4,22 @@ namespace Simtabi\Laranail\IpIntel\Providers; -use Illuminate\Contracts\Cache\Factory as CacheFactory; -use Illuminate\Contracts\Config\Repository as ConfigRepository; -use Illuminate\Contracts\Foundation\Application; -use Illuminate\Http\Client\Factory as HttpFactory; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Route; use Override; +use Illuminate\Http\Request; use Psr\Log\LoggerInterface; -use Simtabi\Laranail\Atlas\Core\Contracts\IpCountryResolver; +use Illuminate\Support\Facades\Route; +use Simtabi\Laranail\Package\Tools\Package; +use Illuminate\Contracts\Foundation\Application; use Simtabi\Laranail\Atlas\Services\AtlasService; -use Simtabi\Laranail\IpIntel\Adapters\EdgeHeader\EdgeHeaderDriver; +use Illuminate\Http\Client\Factory as HttpFactory; +use Simtabi\Laranail\IpIntel\Support\IpIntelConfig; +use Simtabi\Laranail\IpIntel\Services\IpIntelManager; +use Illuminate\Contracts\Cache\Factory as CacheFactory; use Simtabi\Laranail\IpIntel\Adapters\IpApi\IpApiDriver; use Simtabi\Laranail\IpIntel\Adapters\Local\AtlasDriver; -use Simtabi\Laranail\IpIntel\Services\IpIntelManager; -use Simtabi\Laranail\IpIntel\Support\IpIntelConfig; -use Simtabi\Laranail\Package\Tools\Package; +use Simtabi\Laranail\Atlas\Core\Contracts\IpCountryResolver; +use Illuminate\Contracts\Config\Repository as ConfigRepository; +use Simtabi\Laranail\IpIntel\Adapters\EdgeHeader\EdgeHeaderDriver; use Simtabi\Laranail\Package\Tools\Providers\PackageServiceProvider; /** @@ -119,7 +119,7 @@ private function registerApiRoutes(): void Route::group([ 'prefix' => trim($config->string('api.prefix', 'api/ip-intel'), '/') - .'/'.trim($config->string('api.version', 'v1'), '/'), + . '/' . trim($config->string('api.version', 'v1'), '/'), 'middleware' => $middleware, ], function (): void { $this->loadRoutesFrom($this->packagePath('routes/api.php')); diff --git a/src/Rules/ValidIp.php b/src/Rules/ValidIp.php index 20707f9..897ca9c 100644 --- a/src/Rules/ValidIp.php +++ b/src/Rules/ValidIp.php @@ -5,8 +5,8 @@ namespace Simtabi\Laranail\IpIntel\Rules; use Closure; -use Illuminate\Contracts\Validation\ValidationRule; use Simtabi\Laranail\Atlas\Core\Network\IpAddress; +use Illuminate\Contracts\Validation\ValidationRule; /** * A parseable IP address. diff --git a/src/Services/IpIntelManager.php b/src/Services/IpIntelManager.php index 8eff5db..6800609 100644 --- a/src/Services/IpIntelManager.php +++ b/src/Services/IpIntelManager.php @@ -5,19 +5,19 @@ namespace Simtabi\Laranail\IpIntel\Services; use Closure; -use Illuminate\Contracts\Cache\Repository as CacheRepository; -use Illuminate\Contracts\Container\Container; -use Illuminate\Http\Request; use LogicException; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; +use Illuminate\Http\Request; +use Simtabi\Laranail\IpIntel\Enums\Provider; +use Illuminate\Contracts\Container\Container; +use Simtabi\Laranail\IpIntel\Data\IpIntelResult; use Simtabi\Laranail\Atlas\Services\AtlasService; -use Simtabi\Laranail\IpIntel\Adapters\EdgeHeader\EdgeHeaderDriver; -use Simtabi\Laranail\IpIntel\Adapters\IpApi\IpApiDriver; -use Simtabi\Laranail\IpIntel\Adapters\Local\AtlasDriver; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Contracts\IntelDriver; -use Simtabi\Laranail\IpIntel\Data\IpIntelResult; -use Simtabi\Laranail\IpIntel\Enums\Provider; use Simtabi\Laranail\IpIntel\Support\IpIntelConfig; +use Simtabi\Laranail\IpIntel\Adapters\IpApi\IpApiDriver; +use Simtabi\Laranail\IpIntel\Adapters\Local\AtlasDriver; +use Illuminate\Contracts\Cache\Repository as CacheRepository; +use Simtabi\Laranail\IpIntel\Adapters\EdgeHeader\EdgeHeaderDriver; /** * The entry point: builds the chain, caches what is worth caching, and hands @@ -44,7 +44,7 @@ public function __construct( ) {} /** - * @param Closure(Container): IntelDriver $factory + * @param Closure(Container): IntelDriver $factory */ public function extend(string $name, Closure $factory): self { @@ -121,8 +121,8 @@ private function lookup(IpAddress|string $address, bool $full): IpIntelResult } $key = $this->config->string('cache.prefix', 'laranail.ip-intel') - .':'.($full ? 'full' : 'country') - .':'.$parsed->address; + . ':' . ($full ? 'full' : 'country') + . ':' . $parsed->address; $cached = $this->cache->get($key); @@ -164,7 +164,7 @@ private function parse(IpAddress|string $address): IpAddress // bad input, and silently continuing with a wrong address would be // worse than saying so. return $parsed ?? throw new LogicException( - 'atlas could not parse '.self::UNSPECIFIED.', which every IPv4 parser accepts.', + 'atlas could not parse ' . self::UNSPECIFIED . ', which every IPv4 parser accepts.', ); } @@ -182,8 +182,8 @@ private function driver(string $name): ?IntelDriver return match ($provider) { Provider::EdgeHeader => $this->container->make(EdgeHeaderDriver::class), - Provider::Local => $this->container->make(AtlasDriver::class), - Provider::IpApi => $this->container->make(IpApiDriver::class), + Provider::Local => $this->container->make(AtlasDriver::class), + Provider::IpApi => $this->container->make(IpApiDriver::class), }; } } diff --git a/src/Services/ResolverChain.php b/src/Services/ResolverChain.php index 60e76b8..ea8498e 100644 --- a/src/Services/ResolverChain.php +++ b/src/Services/ResolverChain.php @@ -4,17 +4,17 @@ namespace Simtabi\Laranail\IpIntel\Services; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; +use Simtabi\Laranail\IpIntel\Data\AsnInfo; +use Simtabi\Laranail\IpIntel\Data\PlaceInfo; +use Simtabi\Laranail\IpIntel\Data\IpIntelResult; +use Simtabi\Laranail\IpIntel\Data\ThreatSignals; use Simtabi\Laranail\Atlas\Services\AtlasService; -use Simtabi\Laranail\IpIntel\Contracts\DetectsThreats; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; use Simtabi\Laranail\IpIntel\Contracts\IntelDriver; use Simtabi\Laranail\IpIntel\Contracts\ResolvesAsn; use Simtabi\Laranail\IpIntel\Contracts\ResolvesCity; +use Simtabi\Laranail\IpIntel\Contracts\DetectsThreats; use Simtabi\Laranail\IpIntel\Contracts\ResolvesCountry; -use Simtabi\Laranail\IpIntel\Data\AsnInfo; -use Simtabi\Laranail\IpIntel\Data\IpIntelResult; -use Simtabi\Laranail\IpIntel\Data\PlaceInfo; -use Simtabi\Laranail\IpIntel\Data\ThreatSignals; use Simtabi\Laranail\IpIntel\Exceptions\SourceUnavailable; /** @@ -50,7 +50,7 @@ final readonly class ResolverChain { /** - * @param list $drivers in priority order + * @param list $drivers in priority order */ public function __construct( private array $drivers, diff --git a/src/Support/IpIntelConfig.php b/src/Support/IpIntelConfig.php index 427b420..3c38fbe 100644 --- a/src/Support/IpIntelConfig.php +++ b/src/Support/IpIntelConfig.php @@ -46,7 +46,8 @@ public function bool(string $key, bool $default = false): bool } /** - * @param array $default + * @param array $default + * * @return array */ public function array(string $key, array $default = []): array @@ -71,6 +72,6 @@ public function chain(): array private function raw(string $key): mixed { - return $this->config->get(self::PREFIX.'.'.$key); + return $this->config->get(self::PREFIX . '.' . $key); } } diff --git a/tests/Feature/ApiTest.php b/tests/Feature/ApiTest.php index 8c45c0d..2db3774 100644 --- a/tests/Feature/ApiTest.php +++ b/tests/Feature/ApiTest.php @@ -3,10 +3,10 @@ declare(strict_types=1); use Simtabi\Laranail\Atlas\Core\Network\IpAddress; +use Simtabi\Laranail\IpIntel\Services\IpIntelManager; use Simtabi\Laranail\IpIntel\Contracts\ResolvesCountry; use Simtabi\Laranail\IpIntel\Exceptions\SourceUnavailable; use Simtabi\Laranail\IpIntel\Providers\IpIntelServiceProvider; -use Simtabi\Laranail\IpIntel\Services\IpIntelManager; function apiSource(?string $answer = 'KE'): ResolvesCountry { @@ -72,7 +72,7 @@ public function country(IpAddress $address): ?string it('rejects an address that is not one', function (string $ip): void { // A 422 naming the field, not a 500 from somewhere inside a driver. - $this->getJson('api/ip-intel/v1/lookup?ip='.urlencode($ip)) + $this->getJson('api/ip-intel/v1/lookup?ip=' . urlencode($ip)) ->assertStatus(422) ->assertJsonValidationErrorFor('ip'); })->with(['not-an-ip', '01.02.03.04', '256.1.1.1', '']); diff --git a/tests/Feature/ResolverChainTest.php b/tests/Feature/ResolverChainTest.php index bafdfd2..b66f690 100644 --- a/tests/Feature/ResolverChainTest.php +++ b/tests/Feature/ResolverChainTest.php @@ -3,16 +3,16 @@ declare(strict_types=1); use Illuminate\Http\Request; -use Simtabi\Laranail\Atlas\Core\Network\IpAddress; -use Simtabi\Laranail\IpIntel\Contracts\DetectsThreats; -use Simtabi\Laranail\IpIntel\Contracts\ResolvesAsn; -use Simtabi\Laranail\IpIntel\Contracts\ResolvesCountry; use Simtabi\Laranail\IpIntel\Data\AsnInfo; -use Simtabi\Laranail\IpIntel\Data\ThreatSignals; use Simtabi\Laranail\IpIntel\Enums\Outcome; -use Simtabi\Laranail\IpIntel\Exceptions\SourceUnavailable; use Simtabi\Laranail\IpIntel\Facades\IpIntel; +use Simtabi\Laranail\IpIntel\Data\ThreatSignals; +use Simtabi\Laranail\Atlas\Core\Network\IpAddress; +use Simtabi\Laranail\IpIntel\Contracts\ResolvesAsn; use Simtabi\Laranail\IpIntel\Services\IpIntelManager; +use Simtabi\Laranail\IpIntel\Contracts\DetectsThreats; +use Simtabi\Laranail\IpIntel\Contracts\ResolvesCountry; +use Simtabi\Laranail\IpIntel\Exceptions\SourceUnavailable; /** * A country-only source that never leaves the machine. @@ -308,7 +308,7 @@ public function country(IpAddress $address): ?string // ----------------------------------------------------------------------- it('reads the country the reverse proxy supplied', function (string $header): void { - $request = Request::create('/', 'GET', server: ['REMOTE_ADDR' => '8.8.8.8', 'HTTP_'.strtoupper(str_replace('-', '_', $header)) => 'KE']); + $request = Request::create('/', 'GET', server: ['REMOTE_ADDR' => '8.8.8.8', 'HTTP_' . strtoupper(str_replace('-', '_', $header)) => 'KE']); app()->instance('request', $request); config()->set('laranail.ip-intel.chain', ['edge']); diff --git a/tests/TestCase.php b/tests/TestCase.php index feb91fa..1ac219e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,8 +5,8 @@ namespace Simtabi\Laranail\IpIntel\Tests; use Simtabi\Laranail\Atlas\Providers\AtlasServiceProvider; -use Simtabi\Laranail\IpIntel\Providers\IpIntelServiceProvider; use Simtabi\Laranail\Package\Tools\Testing\IsolatedTestCase; +use Simtabi\Laranail\IpIntel\Providers\IpIntelServiceProvider; abstract class TestCase extends IsolatedTestCase {