diff --git a/database/migrations/metas_field_to_bans_table.php b/database/migrations/metas_field_to_bans_table.php index abae82b..67e9b8b 100644 --- a/database/migrations/metas_field_to_bans_table.php +++ b/database/migrations/metas_field_to_bans_table.php @@ -11,7 +11,7 @@ */ public function up(): void { - if (!Schema::hasColumn(config('ban.table'), 'metas')) { + if (! Schema::hasColumn(config('ban.table'), 'metas')) { Schema::table(config('ban.table'), function (Blueprint $table) { $table->json('metas')->nullable(); }); diff --git a/src/BanhammerServiceProvider.php b/src/BanhammerServiceProvider.php index ca36651..ca7afdf 100644 --- a/src/BanhammerServiceProvider.php +++ b/src/BanhammerServiceProvider.php @@ -30,7 +30,6 @@ public function boot(): void $router->aliasMiddleware('logout.banned', LogoutBanned::class); if ($this->app->runningInConsole()) { - // Publishing the config. $this->publishes([ __DIR__.'/../config/config.php' => config_path('ban.php'), diff --git a/src/IP.php b/src/IP.php index d913e2f..8cddb7e 100644 --- a/src/IP.php +++ b/src/IP.php @@ -13,10 +13,10 @@ public static function ban(string|array $ips, array $metas = []): void $bannedIps = self::getBannedIPsFromCache(); foreach ((array) $ips as $ip) { - if (!in_array($ip, $bannedIps)) { + if (! in_array($ip, $bannedIps)) { Ban::create([ 'ip' => $ip, - 'metas' => count($metas) ? $metas : null + 'metas' => count($metas) ? $metas : null, ]); } } diff --git a/src/Models/Ban.php b/src/Models/Ban.php index d3c56a8..063e180 100644 --- a/src/Models/Ban.php +++ b/src/Models/Ban.php @@ -20,18 +20,18 @@ class Ban extends Model 'comment', 'ip', 'expired_at', - 'metas' + 'metas', ]; protected $casts = [ 'expired_at' => 'datetime', - 'metas' => 'array' + 'metas' => 'array', ]; protected function expiredAt(): Attribute { return Attribute::make( - set: fn (null|string|Carbon $value) => (!is_null($value) && !$value instanceof Carbon) ? Carbon::parse($value) : $value, + set: fn (null|string|Carbon $value) => (! is_null($value) && ! $value instanceof Carbon) ? Carbon::parse($value) : $value, ); } @@ -74,7 +74,7 @@ public function scopeNotExpired(Builder $query): void public function scopeWhereMeta(Builder $query, string $name, $value): void { - $query->whereJsonContains('metas->' . $name, $value); + $query->whereJsonContains('metas->'.$name, $value); } public function hasMeta(string $propertyName): bool @@ -85,10 +85,7 @@ public function hasMeta(string $propertyName): bool /** * Get the value of meta with the given name. * - * @param string $propertyName - * @param mixed $default - * - * @return mixed + * @param mixed $default */ public function getMeta(string $propertyName, $default = null): mixed { @@ -97,8 +94,8 @@ public function getMeta(string $propertyName, $default = null): mixed /** * Set the value of meta with the given name. - * @param mixed $value * + * @param mixed $value * @return $this */ public function setMeta(string $name, $value): self @@ -112,8 +109,8 @@ public function setMeta(string $name, $value): self /** * Forget the value of meta with the given name. - * @param mixed $value * + * @param mixed $value * @return $this */ public function forgetMeta(string $name): self diff --git a/src/Traits/Bannable.php b/src/Traits/Bannable.php index dfdee76..dd7c3f1 100644 --- a/src/Traits/Bannable.php +++ b/src/Traits/Bannable.php @@ -31,7 +31,7 @@ public function isBanned(): bool */ public function isNotBanned(): bool { - return !$this->isBanned(); + return ! $this->isBanned(); } public function ban(array $attributes = []): Ban @@ -66,7 +66,7 @@ public function scopeNotBanned(Builder $query): void public function scopeWhereBansMeta(Builder $query, string $key, $value): void { $query->whereHas('bans', function ($query) use ($key, $value) { - $query->where('metas->' . $key, $value)->notExpired(); + $query->where('metas->'.$key, $value)->notExpired(); }); } } diff --git a/tests/Unit/IPBanTest.php b/tests/Unit/IPBanTest.php index b5bd4b7..19e1108 100644 --- a/tests/Unit/IPBanTest.php +++ b/tests/Unit/IPBanTest.php @@ -3,11 +3,9 @@ namespace Mchev\Banhammer\Tests\Unit; use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Http\Request; -use Mchev\Banhammer\Models\Ban; use Mchev\Banhammer\IP; +use Mchev\Banhammer\Models\Ban; use Mchev\Banhammer\Tests\TestCase; -use Symfony\Component\HttpKernel\Exception\HttpException; class IPBanTest extends TestCase { @@ -31,7 +29,7 @@ public function test_ip_is_banned(): void public function test_ip_ban_with_metas(): void { IP::ban($this->ip, [ - 'user_agent' => request()->header('user-agent') + 'user_agent' => request()->header('user-agent'), ]); $ban = Ban::where('ip', $this->ip)->first(); $this->assertTrue($ban->hasMeta('user_agent')); @@ -50,5 +48,4 @@ public function test_multiple_ip_are_banned(): void IP::ban([$this->ip, '8.8.8.8', '4.4.4.4']); $this->assertDatabaseCount(config('ban.table'), 3); } - }