Skip to content

Commit

Permalink
Add Support for Laravel 7 (#17)
Browse files Browse the repository at this point in the history
* Add Support for Laravel 7

* Apply fixes from StyleCI

* Fixes some code quality issues
  • Loading branch information
richan-fongdasen authored Mar 8, 2020
1 parent 59e5ac0 commit 38b0fa6
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 66 deletions.
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://github.com/richan-fongdasen/laravel-varnishable",
"keywords": [
"laravel",
"laravel-5-package",
"laravel-package",
"varnish",
"varnish-cache"
],
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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().#'

16 changes: 8 additions & 8 deletions src/Concerns/InvalidateVarnishCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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').'/';
}
Expand All @@ -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();

Expand All @@ -145,5 +145,5 @@ abstract public function getConfig($key);
*
* @return \GuzzleHttp\Client
*/
abstract public function getGuzzle() :Client;
abstract public function getGuzzle(): Client;
}
8 changes: 4 additions & 4 deletions src/Concerns/ManageEtagHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -38,7 +38,7 @@ public function disableEtag() :void
*
* @return void
*/
public function enableEtag() :void
public function enableEtag(): void
{
$this->setConfig('use_etag', true);
}
Expand All @@ -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;
}
12 changes: 6 additions & 6 deletions src/Concerns/ManageLastModifiedHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait ManageLastModifiedHeader
*
* @return void
*/
protected function addLastModifiedHeader(Response $response) :void
protected function addLastModifiedHeader(Response $response): void
{
$lastModified = $this->getLastModifiedHeader();

Expand All @@ -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);
}
Expand All @@ -46,7 +46,7 @@ public function disableLastModified() :void
*
* @return void
*/
public function enableLastModified() :void
public function enableLastModified(): void
{
$this->setConfig('use_last_modified', true);
}
Expand All @@ -56,7 +56,7 @@ public function enableLastModified() :void
*
* @return \Carbon\Carbon|null
*/
public function getLastModifiedHeader() :?Carbon
public function getLastModifiedHeader(): ?Carbon
{
return $this->lastModified;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
20 changes: 10 additions & 10 deletions src/Concerns/ManipulateHttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

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

Expand All @@ -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');
}
Expand All @@ -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);

Expand All @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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'));

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions src/Events/ModelHasUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -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();
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Facade extends BaseFacade
*
* @return string
*/
protected static function getFacadeAccessor() :string
protected static function getFacadeAccessor(): string
{
return VarnishableService::class;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Concerns/Varnishable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait Varnishable
*
* @return void
*/
public static function bootVarnishable() :void
public static function bootVarnishable(): void
{
static::observe(app(VarnishableObserver::class));
}
Expand All @@ -22,7 +22,7 @@ public static function bootVarnishable() :void
*
* @return void
*/
public function __wakeup() :void
public function __wakeup(): void
{
parent::__wakeup();

Expand Down
Loading

0 comments on commit 38b0fa6

Please sign in to comment.