diff --git a/.travis.yml b/.travis.yml index 00c80c5..c3427c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,20 @@ language: php -sudo: false -dist: trusty +os: linux +dist: bionic matrix: fast_finish: true include: - php: 7.2 env: LARAVEL=5.8.* ORCHESTRA=3.8.* - - php: 7.2 - env: LARAVEL=^6.0 ORCHESTRA=^4.0 COVERAGE=1 - php: 7.3 env: LARAVEL=^6.0 ORCHESTRA=^4.0 + - php: 7.4 + env: LARAVEL=^6.0 ORCHESTRA=^4.0 + - php: 7.3 + env: LARAVEL=^7.0 ORCHESTRA=^5.0 + - php: 7.4 + env: LARAVEL=^7.0 ORCHESTRA=^5.0 COVERAGE=1 allow_failures: - env: COVERAGE=1 diff --git a/composer.json b/composer.json index adfd3e7..f3801b3 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/richan-fongdasen/laravel-varnishable", "keywords": [ "laravel", - "laravel-5-package", + "laravel-package", "varnish", "varnish-cache" ], @@ -23,19 +23,19 @@ "require": { "php": "^7.2", "guzzlehttp/guzzle": "~6.0", - "illuminate/database": "5.8.*|^6.0", - "illuminate/support": "5.8.*|^6.0" + "illuminate/database": "5.8.*|^6.0|^7.0", + "illuminate/support": "5.8.*|^6.0|^7.0" }, "require-dev": { "mockery/mockery": "~1.0", - "orchestra/database": "~3.8|~4.0", - "orchestra/testbench": "~3.8|~4.0", - "phpmd/phpmd": "^2.6", - "phpstan/phpstan": "^0.11.15", - "phpstan/phpstan-deprecation-rules": "^0.11.2", - "phpstan/phpstan-strict-rules": "^0.11.1", - "phpunit/phpunit": "^7.5|^8.0", - "sebastian/phpcpd": "^4.1" + "orchestra/database": "~3.8|~4.0|~5.0", + "orchestra/testbench": "~3.8|~4.0|~5.0", + "phpmd/phpmd": "^2.8", + "phpstan/phpstan": "^0.11|^0.12", + "phpstan/phpstan-deprecation-rules": "^0.11|^0.12", + "phpstan/phpstan-strict-rules": "^0.11|^0.12", + "phpunit/phpunit": "^7.5|^8.0|^9.0", + "sebastian/phpcpd": "^4.0|^5.0" }, "config": { "sort-packages": true diff --git a/phpstan.neon b/phpstan.neon index b8481cf..a45bc3e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ includes: - vendor/phpstan/phpstan-deprecation-rules/rules.neon parameters: - level: 7 + level: 5 ignoreErrors: - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder::withTrashed().#' diff --git a/src/Concerns/InvalidateVarnishCache.php b/src/Concerns/InvalidateVarnishCache.php index 9499993..76d6a43 100644 --- a/src/Concerns/InvalidateVarnishCache.php +++ b/src/Concerns/InvalidateVarnishCache.php @@ -16,7 +16,7 @@ trait InvalidateVarnishCache * * @return void */ - public function flush(string $hostname) :void + public function flush(string $hostname): void { $this->sendBanRequest([ 'X-Ban-Host' => $hostname, @@ -34,7 +34,7 @@ public function flush(string $hostname) :void * * @return void */ - public function banByPattern(string $hostname, string $pattern) :void + public function banByPattern(string $hostname, string $pattern): void { $this->sendBanRequest([ 'X-Ban-Host' => $hostname, @@ -53,7 +53,7 @@ public function banByPattern(string $hostname, string $pattern) :void * * @return void */ - public function banByPatterns(string $hostname, array $patterns) :void + public function banByPatterns(string $hostname, array $patterns): void { foreach ($patterns as $pattern) { $this->banByPattern($hostname, $pattern); @@ -71,7 +71,7 @@ public function banByPatterns(string $hostname, array $patterns) :void * * @return void */ - public function banByUrl(string $hostname, string $url) :void + public function banByUrl(string $hostname, string $url): void { $this->sendBanRequest([ 'X-Ban-Host' => $hostname, @@ -90,7 +90,7 @@ public function banByUrl(string $hostname, string $url) :void * * @return void */ - public function banByUrls(string $hostname, array $urls) :void + public function banByUrls(string $hostname, array $urls): void { foreach ($urls as $url) { $this->banByUrl($hostname, $url); @@ -105,7 +105,7 @@ public function banByUrls(string $hostname, array $urls) :void * * @return string */ - protected function getVarnishUrl(string $varnishHost) :string + protected function getVarnishUrl(string $varnishHost): string { return 'http://'.$varnishHost.':'.$this->getConfig('varnish_port').'/'; } @@ -120,7 +120,7 @@ protected function getVarnishUrl(string $varnishHost) :string * * @return void */ - protected function sendBanRequest(array $headers, string $method = 'BAN') :void + protected function sendBanRequest(array $headers, string $method = 'BAN'): void { $guzzle = $this->getGuzzle(); @@ -145,5 +145,5 @@ abstract public function getConfig($key); * * @return \GuzzleHttp\Client */ - abstract public function getGuzzle() :Client; + abstract public function getGuzzle(): Client; } diff --git a/src/Concerns/ManageEtagHeader.php b/src/Concerns/ManageEtagHeader.php index ffc5258..53dab7a 100644 --- a/src/Concerns/ManageEtagHeader.php +++ b/src/Concerns/ManageEtagHeader.php @@ -13,7 +13,7 @@ trait ManageEtagHeader * * @return void */ - protected function addEtagHeader(Response $response) :void + protected function addEtagHeader(Response $response): void { $useEtag = (bool) $this->getConfig('use_etag'); $content = $response->getContent(); @@ -28,7 +28,7 @@ protected function addEtagHeader(Response $response) :void * * @return void */ - public function disableEtag() :void + public function disableEtag(): void { $this->setConfig('use_etag', false); } @@ -38,7 +38,7 @@ public function disableEtag() :void * * @return void */ - public function enableEtag() :void + public function enableEtag(): void { $this->setConfig('use_etag', true); } @@ -60,5 +60,5 @@ abstract public function getConfig($key); * * @return void */ - abstract public function setConfig($key, $value) :void; + abstract public function setConfig($key, $value): void; } diff --git a/src/Concerns/ManageLastModifiedHeader.php b/src/Concerns/ManageLastModifiedHeader.php index 71f9b28..eae7391 100644 --- a/src/Concerns/ManageLastModifiedHeader.php +++ b/src/Concerns/ManageLastModifiedHeader.php @@ -22,7 +22,7 @@ trait ManageLastModifiedHeader * * @return void */ - protected function addLastModifiedHeader(Response $response) :void + protected function addLastModifiedHeader(Response $response): void { $lastModified = $this->getLastModifiedHeader(); @@ -36,7 +36,7 @@ protected function addLastModifiedHeader(Response $response) :void * * @return void */ - public function disableLastModified() :void + public function disableLastModified(): void { $this->setConfig('use_last_modified', false); } @@ -46,7 +46,7 @@ public function disableLastModified() :void * * @return void */ - public function enableLastModified() :void + public function enableLastModified(): void { $this->setConfig('use_last_modified', true); } @@ -56,7 +56,7 @@ public function enableLastModified() :void * * @return \Carbon\Carbon|null */ - public function getLastModifiedHeader() :?Carbon + public function getLastModifiedHeader(): ?Carbon { return $this->lastModified; } @@ -70,7 +70,7 @@ public function getLastModifiedHeader() :?Carbon * * @return void */ - public function setLastModifiedHeader($current) :void + public function setLastModifiedHeader($current): void { if (!($current instanceof Carbon)) { $current = new Carbon($current); @@ -98,5 +98,5 @@ abstract public function getConfig($key); * * @return void */ - abstract public function setConfig($key, $value) :void; + abstract public function setConfig($key, $value): void; } diff --git a/src/Concerns/ManipulateHttpResponse.php b/src/Concerns/ManipulateHttpResponse.php index c35c978..67896d9 100644 --- a/src/Concerns/ManipulateHttpResponse.php +++ b/src/Concerns/ManipulateHttpResponse.php @@ -22,7 +22,7 @@ trait ManipulateHttpResponse * * @return void */ - protected function acknowledgeEsiSupport(Response $response) :void + protected function acknowledgeEsiSupport(Response $response): void { $esiHeader = $this->requestHeaders->get($this->getConfig('esi_capability_header')); @@ -39,7 +39,7 @@ protected function acknowledgeEsiSupport(Response $response) :void * * @return \Symfony\Component\HttpFoundation\Response */ - protected function addCacheableHeader(Response $response) :Response + protected function addCacheableHeader(Response $response): Response { $duration = $this->getCacheDuration(); @@ -57,7 +57,7 @@ protected function addCacheableHeader(Response $response) :Response * * @return void */ - public function addUncacheableHeader(Response $response) :void + public function addUncacheableHeader(Response $response): void { $response->headers->set($this->getConfig('uncacheable_header'), '1'); } @@ -80,7 +80,7 @@ protected function getCacheDuration() * * @return \Symfony\Component\HttpFoundation\Response */ - public function manipulate(Response $response) :Response + public function manipulate(Response $response): Response { $this->acknowledgeEsiSupport($response); @@ -103,7 +103,7 @@ public function manipulate(Response $response) :Response * * @return void */ - public function setCacheDuration(int $duration) :void + public function setCacheDuration(int $duration): void { $this->setConfig('cache_duration', $duration); } @@ -115,7 +115,7 @@ public function setCacheDuration(int $duration) :void * * @return void */ - public function setRequestHeaders(HeaderBag $headers) :void + public function setRequestHeaders(HeaderBag $headers): void { $this->requestHeaders = $headers; } @@ -127,7 +127,7 @@ public function setRequestHeaders(HeaderBag $headers) :void * * @return bool */ - protected function shouldNotCache(Response $response) :bool + protected function shouldNotCache(Response $response): bool { $headers = (array) $response->headers->get($this->getConfig('uncacheable_header')); @@ -141,7 +141,7 @@ protected function shouldNotCache(Response $response) :bool * * @return void */ - abstract protected function addEtagHeader(Response $response) :void; + abstract protected function addEtagHeader(Response $response): void; /** * Add Last-Modified header to the current response. @@ -150,7 +150,7 @@ abstract protected function addEtagHeader(Response $response) :void; * * @return void */ - abstract protected function addLastModifiedHeader(Response $response) :void; + abstract protected function addLastModifiedHeader(Response $response): void; /** * Get configuration value for a specific key. @@ -169,5 +169,5 @@ abstract public function getConfig($key); * * @return void */ - abstract public function setConfig($key, $value) :void; + abstract public function setConfig($key, $value): void; } diff --git a/src/Events/ModelHasUpdated.php b/src/Events/ModelHasUpdated.php index ee97689..36839f5 100644 --- a/src/Events/ModelHasUpdated.php +++ b/src/Events/ModelHasUpdated.php @@ -50,7 +50,7 @@ public function __construct(Model $model) * * @return \Illuminate\Database\Eloquent\Model */ - protected function createDirtyModel() :Model + protected function createDirtyModel(): Model { $this->model = app($this->modelClass); $this->model->fill($this->data); @@ -69,7 +69,7 @@ protected function createDirtyModel() :Model * * @return \Illuminate\Database\Eloquent\Builder */ - protected function getQuery(Model $model) :Builder + protected function getQuery(Model $model): Builder { $query = $model->newQuery(); @@ -87,7 +87,7 @@ protected function getQuery(Model $model) :Builder * * @return \Illuminate\Database\Eloquent\Model */ - public function model() :Model + public function model(): Model { return $this->retrieveModel() ?? $this->createDirtyModel(); } @@ -98,7 +98,7 @@ public function model() :Model * * @return \Illuminate\Database\Eloquent\Model|null */ - protected function retrieveModel() :?Model + protected function retrieveModel(): ?Model { if ($this->model !== null) { return $this->model; diff --git a/src/Facade.php b/src/Facade.php index 95012e3..bf937cd 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -11,7 +11,7 @@ class Facade extends BaseFacade * * @return string */ - protected static function getFacadeAccessor() :string + protected static function getFacadeAccessor(): string { return VarnishableService::class; } diff --git a/src/Model/Concerns/Varnishable.php b/src/Model/Concerns/Varnishable.php index 57cc6e9..9c36503 100644 --- a/src/Model/Concerns/Varnishable.php +++ b/src/Model/Concerns/Varnishable.php @@ -12,7 +12,7 @@ trait Varnishable * * @return void */ - public static function bootVarnishable() :void + public static function bootVarnishable(): void { static::observe(app(VarnishableObserver::class)); } @@ -22,7 +22,7 @@ public static function bootVarnishable() :void * * @return void */ - public function __wakeup() :void + public function __wakeup(): void { parent::__wakeup(); diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index ba38894..c0b5cd8 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -12,7 +12,7 @@ class ServiceProvider extends Provider * * @return void */ - public function boot() :void + public function boot(): void { $this->publishes([ realpath(dirname(__DIR__).'/config/varnishable.php') => config_path('varnishable.php'), @@ -24,7 +24,7 @@ public function boot() :void * * @return void */ - public function register() :void + public function register(): void { $configPath = realpath(dirname(__DIR__).'/config/varnishable.php'); @@ -32,11 +32,11 @@ public function register() :void $this->mergeConfigFrom($configPath, 'varnishable'); } - $this->app->singleton(VarnishableService::class, function () { + $this->app->singleton(VarnishableService::class, function (): VarnishableService { return new VarnishableService(new Client()); }); - $this->app->singleton(VarnishableObserver::class, function () { + $this->app->singleton(VarnishableObserver::class, function (): VarnishableObserver { return new VarnishableObserver(); }); } diff --git a/src/VarnishableObserver.php b/src/VarnishableObserver.php index dd500ff..02f1247 100644 --- a/src/VarnishableObserver.php +++ b/src/VarnishableObserver.php @@ -30,7 +30,7 @@ public function __construct() * * @return void */ - public function deleted(Model $model) :void + public function deleted(Model $model): void { $this->handleModelUpdates($model); } @@ -45,7 +45,7 @@ public function deleted(Model $model) :void * * @return void */ - protected function handleModelInitialization(Model $model) :void + protected function handleModelInitialization(Model $model): void { $updatedAt = $model->getAttribute('updated_at'); @@ -61,7 +61,7 @@ protected function handleModelInitialization(Model $model) :void * * @return void */ - protected function handleModelUpdates(Model $model) :void + protected function handleModelUpdates(Model $model): void { event(new ModelHasUpdated($model)); } @@ -73,7 +73,7 @@ protected function handleModelUpdates(Model $model) :void * * @return void */ - public function restored(Model $model) :void + public function restored(Model $model): void { $this->handleModelUpdates($model); } @@ -85,7 +85,7 @@ public function restored(Model $model) :void * * @return void */ - public function retrieved(Model $model) :void + public function retrieved(Model $model): void { $this->handleModelInitialization($model); } @@ -97,7 +97,7 @@ public function retrieved(Model $model) :void * * @return void */ - public function saved(Model $model) :void + public function saved(Model $model): void { $this->handleModelUpdates($model); } @@ -109,7 +109,7 @@ public function saved(Model $model) :void * * @return void */ - public function wakeup(Model $model) :void + public function wakeup(Model $model): void { $this->handleModelInitialization($model); } diff --git a/src/VarnishableService.php b/src/VarnishableService.php index cc7d725..3b16275 100644 --- a/src/VarnishableService.php +++ b/src/VarnishableService.php @@ -61,7 +61,7 @@ public function getConfig($key = null) * * @return \GuzzleHttp\Client */ - public function getGuzzle() :Client + public function getGuzzle(): Client { return $this->guzzle; } @@ -71,7 +71,7 @@ public function getGuzzle() :Client * * @return void */ - public function loadConfig() :void + public function loadConfig(): void { $this->config = app('config')->get('varnishable'); } @@ -84,7 +84,7 @@ public function loadConfig() :void * * @return void */ - public function setConfig($key, $value) :void + public function setConfig($key, $value): void { $this->config[$key] = $value; } @@ -97,7 +97,7 @@ public function setConfig($key, $value) :void * * @return void */ - public function setGuzzle(Client $guzzle) :void + public function setGuzzle(Client $guzzle): void { $this->guzzle = $guzzle; }