Skip to content

Commit

Permalink
Add Support for Laravel 7 (#25)
Browse files Browse the repository at this point in the history
Add Support for Laravel 7
  • Loading branch information
richan-fongdasen authored Mar 8, 2020
2 parents aa0d43f + 913fe8d commit 26a14a1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 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
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
},
"require": {
"php": "^7.2",
"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": {
"orchestra/testbench": "~3.8|~4.0",
"orchestra/database": "~3.8|~4.0",
"mockery/mockery": "~1.0",
"orchestra/testbench": "~3.8|~4.0|~5.0",
"orchestra/database": "~3.8|~4.0|~5.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": "^8.0 || ~7.0 || ~6.0",
"sebastian/phpcpd": "^4.1 || ~3.0"
"phpstan/phpstan": "^0.11|^0.12",
"phpstan/phpstan-deprecation-rules": "^0.11|^0.12",
"phpstan/phpstan-strict-rules": "^0.11|^0.12",
"phpunit/phpunit": "^9.0 || ^8.0 || ~7.0 || ~6.0",
"sebastian/phpcpd": "^5.0 || ^4.1 || ~3.0"
},
"config": {
"sort-packages": true
Expand All @@ -59,7 +59,7 @@
}
},
"scripts": {
"analyse": [
"analyse": [
"! find src -type f -name '*.php' -exec php -l {} \\; | grep -v 'No syntax errors'",
"vendor/bin/phpmd src/ text codesize,controversial,design,naming,unusedcode,.phpmd.cleancode.xml",
"vendor/bin/phpcpd --min-lines=3 --min-tokens=36 -vn src/",
Expand Down
8 changes: 4 additions & 4 deletions src/BlameableObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BlameableObserver
*
* @return void
*/
public function creating(Model $model) :void
public function creating(Model $model): void
{
app(BlameableService::class)->setAttribute($model, 'createdBy', blameable_user($model));
}
Expand All @@ -25,7 +25,7 @@ public function creating(Model $model) :void
*
* @return void
*/
public function deleted(Model $model) :void
public function deleted(Model $model): void
{
app(BlameableService::class)->setAttribute($model, 'deletedBy', blameable_user($model));

Expand All @@ -44,7 +44,7 @@ public function deleted(Model $model) :void
*
* @return void
*/
public function restoring(Model $model) :void
public function restoring(Model $model): void
{
app(BlameableService::class)->setAttribute($model, 'deletedBy', null);
}
Expand All @@ -56,7 +56,7 @@ public function restoring(Model $model) :void
*
* @return void
*/
public function saving(Model $model) :void
public function saving(Model $model): void
{
app(BlameableService::class)->setAttribute($model, 'updatedBy', blameable_user($model));
}
Expand Down
10 changes: 5 additions & 5 deletions src/BlameableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BlameableService
/**
* Global configurations from config/blameable.php.
*
* @var array
* @var array<string>
*/
private $globalConfig;

Expand All @@ -26,9 +26,9 @@ public function __construct()
*
* @param \Illuminate\Database\Eloquent\Model $model
*
* @return array
* @return array<string>
*/
private function getConfigurations(Model $model) :array
private function getConfigurations(Model $model): array
{
$modelConfigurations = method_exists($model, 'blameable') ?
$model->blameable() : [];
Expand All @@ -54,7 +54,7 @@ public function getConfiguration(Model $model, string $key)
*
* @return void
*/
public function loadConfig() :void
public function loadConfig(): void
{
$this->globalConfig = app('config')->get('blameable');
}
Expand All @@ -68,7 +68,7 @@ public function loadConfig() :void
*
* @return bool
*/
public function setAttribute(Model $model, string $key, $userId) :bool
public function setAttribute(Model $model, string $key, $userId): bool
{
$attribute = $this->getConfiguration($model, $key);

Expand Down
18 changes: 9 additions & 9 deletions src/BlameableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait BlameableTrait
*
* @return array
*/
public function blameable() :array
public function blameable(): array
{
if (property_exists($this, 'blameable')) {
return (array) static::$blameable;
Expand All @@ -29,7 +29,7 @@ public function blameable() :array
*
* @return void
*/
public static function bootBlameableTrait() :void
public static function bootBlameableTrait(): void
{
static::observe(app(BlameableObserver::class));
}
Expand All @@ -43,7 +43,7 @@ public static function bootBlameableTrait() :void
*
* @return \Illuminate\Database\Eloquent\Builder
*/
private function buildBlameableScope(Builder $query, $userId, $key) :Builder
private function buildBlameableScope(Builder $query, $userId, $key): Builder
{
if ($userId instanceof Model) {
$userId = $userId->getKey();
Expand All @@ -57,7 +57,7 @@ private function buildBlameableScope(Builder $query, $userId, $key) :Builder
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function creator() :BelongsTo
public function creator(): BelongsTo
{
return $this->belongsTo(
app(BlameableService::class)->getConfiguration($this, 'user'),
Expand All @@ -70,7 +70,7 @@ public function creator() :BelongsTo
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function updater() :BelongsTo
public function updater(): BelongsTo
{
return $this->belongsTo(
app(BlameableService::class)->getConfiguration($this, 'user'),
Expand All @@ -86,7 +86,7 @@ public function updater() :BelongsTo
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCreatedBy(Builder $query, $userId) :Builder
public function scopeCreatedBy(Builder $query, $userId): Builder
{
return $this->buildBlameableScope($query, $userId, 'createdBy');
}
Expand All @@ -99,7 +99,7 @@ public function scopeCreatedBy(Builder $query, $userId) :Builder
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUpdatedBy(Builder $query, $userId) :Builder
public function scopeUpdatedBy(Builder $query, $userId): Builder
{
return $this->buildBlameableScope($query, $userId, 'updatedBy');
}
Expand All @@ -110,7 +110,7 @@ public function scopeUpdatedBy(Builder $query, $userId) :Builder
*
* @return int
*/
public function silentUpdate() :int
public function silentUpdate(): int
{
return $this->newQueryWithoutScopes()
->where($this->getKeyName(), $this->getKey())
Expand All @@ -123,7 +123,7 @@ public function silentUpdate() :int
*
* @return bool
*/
public function useSoftDeletes() :bool
public function useSoftDeletes(): bool
{
return in_array(SoftDeletes::class, class_uses_recursive($this), true);
}
Expand Down
10 changes: 5 additions & 5 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ServiceProvider extends Provider
*
* @return bool
*/
protected function isLumen() :bool
protected function isLumen(): bool
{
return strpos($this->app->version(), 'Lumen') !== false;
}
Expand All @@ -21,7 +21,7 @@ protected function isLumen() :bool
*
* @return void
*/
public function boot() :void
public function boot(): void
{
if (!$this->isLumen()) {
$this->publishes([
Expand All @@ -35,19 +35,19 @@ public function boot() :void
*
* @return void
*/
public function register() :void
public function register(): void
{
$configPath = realpath(dirname(__DIR__).'/config/blameable.php');

if ($configPath !== false) {
$this->mergeConfigFrom($configPath, 'blameable');
}

$this->app->singleton(BlameableObserver::class, function () {
$this->app->singleton(BlameableObserver::class, function (): BlameableObserver {
return new BlameableObserver();
});

$this->app->singleton(BlameableService::class, function () {
$this->app->singleton(BlameableService::class, function (): BlameableService {
return new BlameableService();
});
}
Expand Down

0 comments on commit 26a14a1

Please sign in to comment.