Skip to content

Commit

Permalink
PHP Linting (Pint)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchev authored and github-actions[bot] committed Mar 2, 2023
1 parent 8ef9470 commit 5122a83
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion database/migrations/metas_field_to_bans_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
1 change: 0 additions & 1 deletion src/BanhammerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/Models/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Bannable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function isBanned(): bool
*/
public function isNotBanned(): bool
{
return !$this->isBanned();
return ! $this->isBanned();
}

public function ban(array $attributes = []): Ban
Expand Down Expand Up @@ -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();
});
}
}
7 changes: 2 additions & 5 deletions tests/Unit/IPBanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'));
Expand All @@ -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);
}

}

0 comments on commit 5122a83

Please sign in to comment.