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
18 changes: 9 additions & 9 deletions config/ip-intel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],

],
Expand All @@ -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',
],

/*
Expand All @@ -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'],
],

Expand Down
6 changes: 3 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/EdgeHeader/EdgeHeaderDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
final readonly class EdgeHeaderDriver implements ResolvesCountry
{
/**
* @param list<string> $headers in priority order
* @param list<string> $headers in priority order
*/
public function __construct(
private ?Request $request,
Expand Down
22 changes: 11 additions & 11 deletions src/Adapters/IpApi/IpApiDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

namespace Simtabi\Laranail\IpIntel\Adapters\IpApi;

use Throwable;
use Illuminate\Http\Client\Factory as HttpFactory;
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\Adapters\Local\AtlasDriver;
use Simtabi\Laranail\IpIntel\Data\AsnInfo;
use Simtabi\Laranail\IpIntel\Data\PlaceInfo;
use Simtabi\Laranail\IpIntel\Data\ThreatSignals;
use Simtabi\Laranail\IpIntel\Exceptions\SourceUnavailable;
use Throwable;

/**
* ipapi.com — the paid tier, for the questions registry data cannot answer.
Expand Down Expand Up @@ -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];
Expand All @@ -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,
]);

Expand All @@ -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(),
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Local/AtlasDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/DetectsThreats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Simtabi\Laranail\IpIntel\Contracts;

use Simtabi\Laranail\IpIntel\Data\ThreatSignals;
use Simtabi\Laranail\Atlas\Core\Network\IpAddress;
use Simtabi\Laranail\IpIntel\Data\ThreatSignals;

/**
* A source that can say something about how an address is being used.
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ResolvesAsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Simtabi\Laranail\IpIntel\Contracts;

use Simtabi\Laranail\IpIntel\Data\AsnInfo;
use Simtabi\Laranail\Atlas\Core\Network\IpAddress;
use Simtabi\Laranail\IpIntel\Data\AsnInfo;

/**
* A source that can name the network an address is announced from.
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ResolvesCity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Simtabi\Laranail\IpIntel\Contracts;

use Simtabi\Laranail\IpIntel\Data\PlaceInfo;
use Simtabi\Laranail\Atlas\Core\Network\IpAddress;
use Simtabi\Laranail\IpIntel\Data\PlaceInfo;

/**
* A source that can place an address more precisely than its country.
Expand Down
8 changes: 4 additions & 4 deletions src/Data/AsnInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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,
];
}
}
34 changes: 17 additions & 17 deletions src/Data/IpIntelResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Simtabi\Laranail\IpIntel\Data;

use JsonSerializable;
use Simtabi\Laranail\IpIntel\Enums\Outcome;
use Simtabi\Laranail\Atlas\Core\Network\IpAddress;
use Simtabi\Laranail\Atlas\Core\Country\CountryRecord;
use Simtabi\Laranail\Atlas\Core\Network\IpAddress;
use Simtabi\Laranail\IpIntel\Enums\Outcome;

/**
* What the chain found, and how.
Expand All @@ -34,7 +34,7 @@
final readonly class IpIntelResult implements JsonSerializable
{
/**
* @param list<string> $sources drivers that contributed, in order
* @param list<string> $sources drivers that contributed, in order
*/
private function __construct(
public IpAddress $address,
Expand All @@ -50,7 +50,7 @@ private function __construct(
) {}

/**
* @param list<string> $sources
* @param list<string> $sources
*/
public static function found(
IpAddress $address,
Expand Down Expand Up @@ -94,7 +94,7 @@ public static function reserved(IpAddress $address): self
/**
* Every source was asked and none had an answer.
*
* @param list<string> $sources
* @param list<string> $sources
*/
public static function notFound(IpAddress $address, array $sources = [], bool $madeNetworkCall = false): self
{
Expand All @@ -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<string> $sources
* @param list<string> $sources
*/
public static function unavailable(IpAddress $address, string $why, array $sources = []): self
{
Expand Down Expand Up @@ -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,
];
}

Expand Down
8 changes: 4 additions & 4 deletions src/Data/PlaceInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
Expand Down
8 changes: 4 additions & 4 deletions src/Data/ThreatSignals.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
2 changes: 1 addition & 1 deletion src/Enums/Outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/SourceUnavailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
Expand Down
4 changes: 2 additions & 2 deletions src/Facades/IpIntel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Facade;
use Simtabi\Laranail\IpIntel\Data\IpIntelResult;
use Simtabi\Laranail\Atlas\Core\Network\IpAddress;
use Simtabi\Laranail\IpIntel\Services\ResolverChain;
use Simtabi\Laranail\IpIntel\Data\IpIntelResult;
use Simtabi\Laranail\IpIntel\Services\IpIntelManager;
use Simtabi\Laranail\IpIntel\Services\ResolverChain;

/**
* @method static IpIntelResult country(IpAddress|string $address)
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Controllers/LookupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Simtabi\Laranail\IpIntel\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Simtabi\Laranail\IpIntel\Enums\Outcome;
use Simtabi\Laranail\IpIntel\Data\IpIntelResult;
use Simtabi\Laranail\IpIntel\Services\IpIntelManager;
use Simtabi\Laranail\IpIntel\Enums\Outcome;
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.
Expand Down Expand Up @@ -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,
};
}
}
2 changes: 1 addition & 1 deletion src/Http/Requests/LookupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
Expand Down
Loading
Loading