diff --git a/src/Behaviours/CachedOnCDN.php b/src/Behaviours/CachedOnCDN.php index e96baea..7a34e10 100644 --- a/src/Behaviours/CachedOnCDN.php +++ b/src/Behaviours/CachedOnCDN.php @@ -62,7 +62,7 @@ public function edgeFlushIsEnabled(): bool return Helpers::configBool('edge-flush.enabled.package', false); } - public function invalidationsAreEnabled() + public function invalidationsAreEnabled(): bool { return Helpers::configBool('edge-flush.enabled.services.invalidation', false); } diff --git a/src/Behaviours/CastObject.php b/src/Behaviours/CastObject.php index 1ed0e23..d793a2c 100644 --- a/src/Behaviours/CastObject.php +++ b/src/Behaviours/CastObject.php @@ -9,7 +9,7 @@ trait CastObject { public function getInternalModel(Model $model): Model { - $internal = config('edge-flush.tags.external-models.'.get_class($model)); + $internal = Helpers::configString('edge-flush.tags.external-models.'.get_class($model)); if (blank($internal)) { return $model; diff --git a/src/Behaviours/MakeTag.php b/src/Behaviours/MakeTag.php index 3b4f33a..aa04db8 100644 --- a/src/Behaviours/MakeTag.php +++ b/src/Behaviours/MakeTag.php @@ -2,6 +2,7 @@ namespace A17\EdgeFlush\Behaviours; +use Illuminate\Support\Str; use A17\EdgeFlush\EdgeFlush; use A17\EdgeFlush\Services\Entity; use A17\EdgeFlush\Support\Helpers; @@ -52,6 +53,7 @@ public function getCDNCacheTagFromModel(mixed $model, string $key = null, string return null; } + /** @phpstan-ignore-next-line */ return $model->getCDNCacheTag($key, $type); } @@ -77,18 +79,25 @@ public function encodeValueForComparison(mixed $value, string|null $type = null) } if ($type === 'boolean' || is_bool($value)) { - return !!$value ? 'true' : 'false'; + return (bool) $value ? 'true' : 'false'; } - if ($type === 'string' || is_string($value)) { - return "'$value'"; - } + if ($type === 'string' || $type === 'array' || $type === 'object') { + if (is_string($value)) { + return "'$value'"; + } + + if (is_array($value) || is_object($value)) { + $value = json_encode($value); - if ($type === 'array' || is_array($value)) { - return json_encode($value); + if (is_string($value)) { + return $value; + } + } } - return (string) $value; + /// FIXME: we cannot cast this value to a string, so we are generating a random string that will not match anything else, fow now + return '--- cannot cast to string --- ' . Str::random(16); } public function granularPropertyIsAllowed(string $name, Model|string $model): bool diff --git a/src/Console/Commands/ConfigMergeSection.php b/src/Console/Commands/ConfigMergeSection.php index 03b2e76..bb161b3 100644 --- a/src/Console/Commands/ConfigMergeSection.php +++ b/src/Console/Commands/ConfigMergeSection.php @@ -171,7 +171,7 @@ public function extractInternalArray(string|false|null $content): string|null return null; } - $lines = is_string($content) ? explode("\n", $content) : []; + $lines = explode("\n", $content); $result = []; diff --git a/src/Contracts/CDNService.php b/src/Contracts/CDNService.php index 395cffb..eeb513d 100644 --- a/src/Contracts/CDNService.php +++ b/src/Contracts/CDNService.php @@ -18,4 +18,6 @@ public function maxUrls(): int; public function invalidationIsCompleted(string $invalidationId): bool; public function enabled(): bool; + + public function canInvalidateAll(): bool; } diff --git a/src/EdgeFlush.php b/src/EdgeFlush.php index 73085f7..c5c8614 100644 --- a/src/EdgeFlush.php +++ b/src/EdgeFlush.php @@ -24,6 +24,7 @@ * @method static bool storeTagsServiceIsEnabled() * @method static bool warmerServiceIsEnabled() * @method static string packageName() + * @method static bool match(string $patten, string $string) **/ class EdgeFlush extends Facade { @@ -31,7 +32,9 @@ protected static function getFacadeAccessor(): string { $accessor = \A17\EdgeFlush\Services\EdgeFlush::class; - static::$app->afterResolving($accessor, fn() => app($accessor)->boot()); + if (filled(static::$app)) { + static::$app->afterResolving($accessor, fn() => app($accessor)->boot()); + } return $accessor; } diff --git a/src/Jobs/InvalidateModel.php b/src/Jobs/InvalidateModel.php index e5ff47b..385bbfb 100644 --- a/src/Jobs/InvalidateModel.php +++ b/src/Jobs/InvalidateModel.php @@ -30,8 +30,10 @@ public function __construct(Entity $entity) * * @return void */ - public function handle() + public function handle(): void { - EdgeFlush::tags()->dispatchInvalidationsForModel($this->entity); + if (filled($this->entity)) { + EdgeFlush::tags()->dispatchInvalidationsForModel($this->entity); + } } } diff --git a/src/Listeners/EloquentObserver.php b/src/Listeners/EloquentObserver.php index 3df96bc..1aa4d0c 100644 --- a/src/Listeners/EloquentObserver.php +++ b/src/Listeners/EloquentObserver.php @@ -47,7 +47,7 @@ public function forceDeleted(Model $model): void $this->invalidate($model, 'deleted'); } - public function pivotSynced($observed, $model, $relationName, $changes) + public function pivotSynced(mixed $observed, Model $model, string $relationName, array $changes): void { $this->invalidate($model, 'pivot-synced', ['name' => $relationName, 'changes' => $changes]); } @@ -58,7 +58,13 @@ public function invalidate(Model $model, string $event, array $relation = []): v return; } - if ($this->dispatchedEvents->alreadyDispatched($event.'-'.$this->makeModelName($model))) { + if (blank($this->dispatchedEvents)) { + return; + } + + $dispatched = $this->dispatchedEvents->alreadyDispatched($event.'-'.$this->makeModelName($model)); + + if (filled($dispatched) && $dispatched !== false) { return; } @@ -76,7 +82,7 @@ public function invalidate(Model $model, string $event, array $relation = []): v } } - public function boot() + public function boot(): void { $this->dispatchedEvents = app('a17.edgeflush.dispatchedEvents'); } diff --git a/src/Middleware.php b/src/Middleware.php index 31e1164..2637290 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -3,6 +3,7 @@ namespace A17\EdgeFlush; use Closure; +use A17\EdgeFlush\Support\Helpers; class Middleware { @@ -17,7 +18,7 @@ public function handle($request, Closure $next) { $response = $next($request); - if (config('edge-flush.enabled.package')) { + if (Helpers::configBool('edge-flush.enabled.package')) { return EdgeFlush::setRequest($request)->makeResponse($response); } diff --git a/src/Models/Url.php b/src/Models/Url.php index 54d84b0..e638763 100644 --- a/src/Models/Url.php +++ b/src/Models/Url.php @@ -10,8 +10,9 @@ * @property string $url * @property string $url_hash * @property int $hits - * @property bool $was_purged_at + * @property \Illuminate\Support\Carbon $was_purged_at * @property string $invalidation_id + * @property bool $canBeSaved */ class Url extends Model { diff --git a/src/Services/Akamai/Service.php b/src/Services/Akamai/Service.php index 391b702..b858eea 100644 --- a/src/Services/Akamai/Service.php +++ b/src/Services/Akamai/Service.php @@ -54,9 +54,9 @@ public function getAuthHeaders(mixed $body): string $auth->setHttpMethod('POST'); $auth->setAuth( - $this->getClientToken(), - $this->getClientSecret(), - $this->getAccessToken(), + (string) $this->getClientToken(), + (string) $this->getClientSecret(), + (string) $this->getAccessToken(), ); $auth->setPath($this->getApiPath()); @@ -64,20 +64,15 @@ public function getAuthHeaders(mixed $body): string return $auth->createAuthHeader(); } - public function maxUrls(): int - { - return Helpers::configInt('edge-flush.services.akamai.max_urls') ?? 300; - } - public function invalidationIsCompleted(string $invalidationId): bool { /** * Fast purge is supposed to be completed in seconds, so no need to do a request * to check if it's completed. */ - $url = Url::where('invalidation_id', $invalidationId)->take(1)->get()->first(); + $url = Url::where('invalidation_id', $invalidationId)->first(); - if (empty($url)) { + if (blank($url)) { return true; } @@ -86,6 +81,14 @@ public function invalidationIsCompleted(string $invalidationId): bool public function createInvalidationRequest(Invalidation|array $invalidation = null): Invalidation { + if (blank($invalidation)) { + return new Invalidation(); + } + + if (is_array($invalidation)) { + $invalidation = (new Invalidation())->setUrls($invalidation); + } + $urls = $invalidation->urls() ->map(function ($item) { return $item instanceof Url ? $item->url_hash : $item; @@ -116,7 +119,7 @@ public function createInvalidationRequest(Invalidation|array $invalidation = nul Helpers::debug('[AKAMAI] Invalidation completed in ' . $duration . ' seconds'); if ($response->failed()) { - Helpers::error('Error invalidating akamai tags: ' . $response->getBody()); + Helpers::error('Error invalidating akamai tags: ' . $response->body()); $invalidation->setSuccess(false); @@ -125,9 +128,15 @@ public function createInvalidationRequest(Invalidation|array $invalidation = nul $invalidation->setSuccess(true); - $invalidation->setId($response->json('purgeId')); + $json = $response->json(); + + if (!is_array($json)) { + $json = []; + } + + $invalidation->setId($json['purgeId'] ?? null); - $invalidation->setInvalidationResponse($response->json()); + $invalidation->setInvalidationResponse($json); return $invalidation; } diff --git a/src/Services/BaseService.php b/src/Services/BaseService.php index 1c73158..a7db10b 100644 --- a/src/Services/BaseService.php +++ b/src/Services/BaseService.php @@ -18,6 +18,10 @@ abstract class BaseService implements ServiceContract protected bool|null $enabled = null; + protected function instantiate(): void + { + } + public function addHeadersToResponse(Response $response, string $service, string $tag): Response { if (!$this->enabled()) { @@ -135,4 +139,9 @@ public function createInvalidation(Invalidation|array $invalidation = null): Inv return $invalidation; } + + public function canInvalidateAll(): bool + { + return true; + } } diff --git a/src/Services/CacheControl.php b/src/Services/CacheControl.php index c75e32e..20daccc 100644 --- a/src/Services/CacheControl.php +++ b/src/Services/CacheControl.php @@ -50,7 +50,7 @@ public function isCachable(Response $response): bool } if (filled($this->_isCachable)) { - return (bool) $this->_isCachable; + return $this->_isCachable; } return $this->_isCachable = !$this->getCachableMatrix($response)->contains(false); @@ -199,7 +199,7 @@ protected function middlewaresAllowCaching(): bool ? ['no-middleware'] : $route->action['middleware'] ?? null; - if (blank($middleware) || is_null($middleware)) { + if (blank($middleware)) { return false; } @@ -452,7 +452,7 @@ public function willBeCached(Response $response, string|null $strategy = null): public function strategyDoesntContainsNoStoreDirectives(string $strategy): bool { - return !!Helpers::collect(explode(',', $strategy))->reduce(function ($willCache, $element) { + return Helpers::collect(explode(',', $strategy))->reduce(function (bool $willCache, mixed $element) { if (!is_string($element)) { return $willCache; } diff --git a/src/Services/CdnBaseService.php b/src/Services/CdnBaseService.php index 5811a00..52a9765 100644 --- a/src/Services/CdnBaseService.php +++ b/src/Services/CdnBaseService.php @@ -10,6 +10,8 @@ abstract class CdnBaseService extends BaseService implements CDNService { + protected static string $serviceName = 'not-assigned'; + public function __construct() { if ($this->enabled()) { @@ -80,7 +82,7 @@ public function invalidatePaths(Invalidation $invalidation): Invalidation { return $this->createInvalidationRequest($invalidation); } - + public function maxUrls(): int { return Helpers::configInt('edge-flush.services.'.static::$serviceName.'.max_urls') ?? 300; @@ -93,39 +95,25 @@ public function enabled(): bool $this->isProperlyConfigured(); } - public function invalidationIsCompleted(string $invalidationId): bool - { - $response = $this->getInvalidation($invalidationId); - - if (blank($response)) { - return false; - } - - return Invalidation::factory($response)->isCompleted(); - } - - public function getInvalidation(string $invalidationId): AwsResult - { - return $this->client->getInvalidation([ - 'DistributionId' => $this->getDistributionId(), - 'Id' => $invalidationId, - ]); - } - public function serviceIsEnabled(): bool { return Helpers::configBool('edge-flush.services.'.static::$serviceName.'.enabled', true); } - public function getMaxUrls(): int - { - return Helpers::configInt('edge-flush.services.'.static::$serviceName.'.max_urls', 300); - } - public function canInvalidateAll(): bool { return collect( Helpers::configString('edge-flush.services.'.static::$serviceName.'.invalidate_all_paths') ?? [] )->filter()->isNotEmpty(); } + + public function createInvalidationRequest(Invalidation|array $invalidation = null): Invalidation + { + return new Invalidation(); + } + + public function isProperlyConfigured(): bool + { + return true; + } } diff --git a/src/Services/CloudFront/Service.php b/src/Services/CloudFront/Service.php index 8a1ff58..100a234 100644 --- a/src/Services/CloudFront/Service.php +++ b/src/Services/CloudFront/Service.php @@ -22,7 +22,7 @@ class Service extends CdnBaseService { protected static string $serviceName = 'cloud_front'; - + protected CloudFrontClient $client; protected function instantiate(): void @@ -36,19 +36,19 @@ protected function instantiate(): void protected function getDistributionId(): string|null { - return Helpers::configString('edge-flush.services.'.$this->serviceId.'.distribution_id'); + return Helpers::configString('edge-flush.services.'.$this->serviceName.'.distribution_id'); } public function getClient(): CloudFrontClient|null { $config = [ - 'region' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.region'), + 'region' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.region'), - 'version' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.sdk_version'), + 'version' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.sdk_version'), 'credentials' => [ - 'key' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.key'), - 'secret' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.secret'), + 'key' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.key'), + 'secret' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.secret'), ], ]; @@ -57,13 +57,13 @@ public function getClient(): CloudFrontClient|null } return new CloudFrontClient([ - 'region' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.region'), + 'region' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.region'), - 'version' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.sdk_version'), + 'version' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.sdk_version'), 'credentials' => [ - 'key' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.key'), - 'secret' => Helpers::configString('edge-flush.services.'.$this->serviceId.'.secret'), + 'key' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.key'), + 'secret' => Helpers::configString('edge-flush.services.'.$this->serviceName.'.secret'), ], ]); } @@ -136,4 +136,23 @@ public function isProperlyConfigured(): bool { return filled($this->client); } + + public function invalidationIsCompleted(string $invalidationId): bool + { + $response = $this->getInvalidation($invalidationId); + + if (blank($response)) { + return false; + } + + return Invalidation::factory($response)->isCompleted(); + } + + public function getInvalidation(string $invalidationId): AwsResult + { + return $this->client->getInvalidation([ + 'DistributionId' => $this->getDistributionId(), + 'Id' => $invalidationId, + ]); + } } diff --git a/src/Services/DispatchedEvents.php b/src/Services/DispatchedEvents.php index e600dcc..33d7df9 100644 --- a/src/Services/DispatchedEvents.php +++ b/src/Services/DispatchedEvents.php @@ -2,16 +2,18 @@ namespace A17\EdgeFlush\Services; +use Illuminate\Database\Eloquent\Model; + class DispatchedEvents { - protected $dispatched = []; + protected array $dispatched = []; - public function register($model) + public function register(string $model): void { $this->dispatched[$model] = true; } - public function alreadyDispatched($model) + public function alreadyDispatched(string $model): mixed { $dispatched = $this->dispatched[$model] ?? false; diff --git a/src/Services/DummyCDN.php b/src/Services/DummyCDN.php index 5d6ffb7..283007f 100644 --- a/src/Services/DummyCDN.php +++ b/src/Services/DummyCDN.php @@ -7,7 +7,7 @@ /** * Let's just simulate a real CDN with this dummy */ -class DummyCDN extends BaseService implements CDNService +class DummyCDN extends CdnBaseService implements CDNService { public function invalidate(Invalidation $invalidation): Invalidation { @@ -19,11 +19,6 @@ public function invalidateAll(): Invalidation return $this->successfulInvalidation(); } - public function maxUrls(): int - { - return 500; - } - public function invalidationIsCompleted(string $invalidationId): bool { return true; diff --git a/src/Services/FrontendChecker.php b/src/Services/FrontendChecker.php index ef30664..8807347 100644 --- a/src/Services/FrontendChecker.php +++ b/src/Services/FrontendChecker.php @@ -15,6 +15,6 @@ public function runningOnFrontend(): bool return false; } - return Str::startsWith((string) $name, ['front.', 'api.']); + return Str::startsWith($name, ['front.', 'api.']); } } diff --git a/src/Services/Invalidation.php b/src/Services/Invalidation.php index f87ff1a..8a4ae62 100644 --- a/src/Services/Invalidation.php +++ b/src/Services/Invalidation.php @@ -320,11 +320,11 @@ public function getInvalidationPaths(): Collection return EdgeFlush::cdn()->getInvalidationPathsForTags($this); } - public function setUrls(Collection $urls): self + public function setUrls(Collection|array $urls): self { $this->type = 'url'; - $this->urls = $urls; + $this->urls = is_array($urls) ? new Collection($urls) : $urls; return $this; } @@ -400,7 +400,7 @@ public function __wakeup(): void $this->instantiate(); } - private function instantiate(): void + protected function instantiate(): void { $this->tags ??= new Collection(); diff --git a/src/Services/MissingCDN.php b/src/Services/MissingCDN.php index 67dfbb7..f87190f 100644 --- a/src/Services/MissingCDN.php +++ b/src/Services/MissingCDN.php @@ -4,7 +4,7 @@ use A17\EdgeFlush\Contracts\CDNService; -class MissingCDN extends BaseService implements CDNService +class MissingCDN extends CdnBaseService implements CDNService { protected bool|null $enabled = false; @@ -18,11 +18,6 @@ public function invalidateAll(): Invalidation return $this->unsuccessfulInvalidation(); } - public function maxUrls(): int - { - return 0; - } - public function invalidationIsCompleted(string $invalidationId): bool { return false; diff --git a/src/Services/Tags.php b/src/Services/Tags.php index d92b564..cc6e20c 100644 --- a/src/Services/Tags.php +++ b/src/Services/Tags.php @@ -47,13 +47,13 @@ public function __construct(Request|null $request = null) $this->request = $request ?? request(); } - public function addTag(Model $model, string $key = null, array $allowedKeys = []): void + public function addTag(Model $model, string|null $key = null, array $allowedKeys = []): void { if (!EdgeFlush::enabled()) { return; } - if ($this->attributeMustBeIgnored($model, $key) || !$this->attributeExists($model, $key)) { + if (blank($key) || $this->attributeMustBeIgnored($model, $key) || !$this->attributeExists($model, $key)) { return; } @@ -68,14 +68,16 @@ public function addTag(Model $model, string $key = null, array $allowedKeys = [] // $tags[] = $this->makeModelName($model, Constants::ANY_TAG, $allowedKeys), // TODO: do we need the ANY_TAG? foreach ($this->getAlwaysAddAttributes($model) as $attribute) { - if ($model->hasAttribute($attribute)) { + if (isset($model->$attribute)) { $tags[] = $this->makeModelName($model, $attribute, $allowedKeys); } } - foreach ($tags as $tag) { - if (blank($this->tags[$tag] ?? null)) { - $this->tags[$tag] = $tag; + $this->tags ??= collect(); + + foreach ($tags as $_tag) { + if (blank($this->tags[$_tag] ?? null)) { + $this->tags->put((string) $_tag, $_tag); } } } @@ -153,12 +155,16 @@ public function storeCacheTags(Collection $models, string $url): void ->map(function (mixed $model) use ($now) { $model = Helpers::toString($model); + if (!filled($this->url)) { + return null; + } + $index = $this->makeTagIndex($this->url, $model); $this->dbStatement($this->getStoreCacheTagsInsertSql($index, $this->url, $model, $now)); - + return $index; - }); + })->filter(); }, 5); if ($indexes->isNotEmpty()) { @@ -211,7 +217,7 @@ public function dispatchInvalidationsForModel(Entity $entity): void Helpers::debug('DISPATCHING for model: ' . $entity->modelName); - $strategy = $this->dispatchInvalidationsForCrud($entity); + $this->dispatchInvalidationsForCrud($entity); } protected function dispatchInvalidationsForCrud(Entity $entity): void @@ -318,7 +324,7 @@ protected function invalidateObsoleteTags(): void return; } - $maxUrls = EdgeFlush::cdn()->getMaxUrls(); + $maxUrls = EdgeFlush::cdn()->maxUrls(); $query = " from edge_flush_urls @@ -336,7 +342,7 @@ protected function invalidateObsoleteTags(): void {$query} "); - $total = empty($total[0] ?? null) ? 0 : $total[0]->total; + $total = blank($total[0] ?? null) ? 0 : $total[0]->total; if ($total === 0) { return; @@ -479,11 +485,13 @@ protected function alreadyProcessed(string $tag): bool { $this->boot(); + $this->processedTags ??= collect(); + if (($this->processedTags[$tag] ?? null) === true) { return true; } - $this->processedTags[$tag] = true; + $this->processedTags->put($tag, true); return false; } @@ -658,6 +666,10 @@ public function makeTagIndex(Url|string $url, string $model): string $this->url = $this->makeUrl($url); } + if (blank($this->url)) { + return ''; + } + return sha1("{$this->url->url}:{$model}"); } @@ -753,7 +765,7 @@ protected function invalidateAllUrlsSql(string $urlHashes, string $time, string select efu.id from edge_flush_urls efu where efu.is_valid = true - and efu.url in ({$list}) + and efu.url_hash in ({$urlHashes}) order by efu.id for update ) urls @@ -815,7 +827,9 @@ protected function markUrlsAsWarmedSql(string $list): string public function alreadyDispatched(Entity $entity): bool { foreach ($entity->getDirtyModelNames() as $modelName) { - if (!($this->invalidationDispatched[$modelName] ?? false)) { + $wasDispatched = $this->invalidationDispatched[$modelName] ?? false; + + if (!is_bool($wasDispatched) || $wasDispatched === false) { return false; } } @@ -831,7 +845,7 @@ public function canStoreCacheTags(string $url): bool EdgeFlush::cacheControl()->routeIsCachable(); } - protected function attributeMustBeIgnored(Model $model, $attribute): bool + protected function attributeMustBeIgnored(Model $model, string $attribute): bool { $attributes = Helpers::configArray("edge-flush.invalidations.attributes.ignore", []); @@ -847,7 +861,7 @@ protected function getAlwaysAddAttributes(Model $model): array return ($attributes[get_class($model)] ?? []) + ($attributes['*'] ?? []); } - protected function markUrlAsHit(Url $url) + protected function markUrlAsHit(Url $url): void { if ($url->canBeSaved ?? true) { $this->dbStatement($this->getUrlHitSql($url->id)); @@ -869,11 +883,15 @@ protected function getUrlHitSql(int $id): string protected function markAsDispatched(Entity $entity): void { foreach ($entity->getDirtyModelNames() as $modelName) { - $this->invalidationDispatched[$modelName] = true; + if (!is_string($modelName)) { + continue; + } + + $this->invalidationDispatched[] = true; } } - public function getEdgeCacheTag() + public function getEdgeCacheTag(): string { if (blank($this->url)) { $this->url = $this->makeUrl($this->getCurrentUrl(request())); @@ -903,7 +921,7 @@ public function bootIfNotBooted(Request|null $request = null): void } - public function instantiate(): void + protected function instantiate(): void { $this->tags = Helpers::collect(); diff --git a/src/Services/Warmer.php b/src/Services/Warmer.php index ef2b9dc..a33859a 100644 --- a/src/Services/Warmer.php +++ b/src/Services/Warmer.php @@ -38,7 +38,7 @@ public function warm(Collection $urls): void Helpers::debug('[WARMER] Warming up ' . $urls->count() . ' URLs using ' . $count . ' concurrent requests'); while ($urls->count() > 0) { - $chunk = $urls->splice(0, (int) $count); + $chunk = $urls->splice(0, $count); $this->dispatchWarmRequests($chunk); @@ -55,7 +55,7 @@ public function getColdUrls(): Collection { $max = Helpers::configInt('edge-flush.warmer.max_urls', 100); - $max = !is_numeric($max) ? 100 : (int) $max; + $max = !is_numeric($max) ? 100 : $max; return Url::whereNotNull('was_purged_at') ->take($max) @@ -195,7 +195,7 @@ public function getGuzzleConfiguration(): array { $config = [ - 'timeout' => Helpers::configInt('edge-flush.warmer.connection_timeout') / 1000, // Guzzle expects seconds + 'timeout' => (int) Helpers::configInt('edge-flush.warmer.connection_timeout') / 1000, // Guzzle expects seconds 'connect_timeout' => Helpers::configInt('edge-flush.warmer.connection_timeout', 1000),