1 | <?php |
||||
2 | |||||
3 | /* |
||||
4 | * This file is part of Laravel Ban. |
||||
5 | * |
||||
6 | * (c) Anton Komarev <[email protected]> |
||||
7 | * |
||||
8 | * For the full copyright and license information, please view the LICENSE |
||||
9 | * file that was distributed with this source code. |
||||
10 | */ |
||||
11 | |||||
12 | declare(strict_types=1); |
||||
13 | |||||
14 | namespace Cog\Laravel\Ban\Traits; |
||||
15 | |||||
16 | use Cog\Contracts\Ban\Ban as BanContract; |
||||
17 | use Cog\Contracts\Ban\BanService as BanServiceContract; |
||||
18 | use Illuminate\Support\Carbon; |
||||
19 | |||||
20 | trait HasBannedAtHelpers |
||||
21 | { |
||||
22 | /** |
||||
23 | * Set banned flag. |
||||
24 | * |
||||
25 | * @return $this |
||||
26 | */ |
||||
27 | public function setBannedFlag() |
||||
28 | { |
||||
29 | $this->setAttribute('banned_at', Carbon::now()); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
30 | |||||
31 | return $this; |
||||
32 | } |
||||
33 | |||||
34 | /** |
||||
35 | * Unset banned flag. |
||||
36 | * |
||||
37 | * @return $this |
||||
38 | */ |
||||
39 | public function unsetBannedFlag() |
||||
40 | { |
||||
41 | $this->setAttribute('banned_at', null); |
||||
42 | |||||
43 | return $this; |
||||
44 | } |
||||
45 | |||||
46 | /** |
||||
47 | * If model is banned. |
||||
48 | * |
||||
49 | * @return bool |
||||
50 | */ |
||||
51 | public function isBanned(): bool |
||||
52 | { |
||||
53 | return $this->getAttributeValue('banned_at') !== null; |
||||
0 ignored issues
–
show
It seems like
getAttributeValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
54 | } |
||||
55 | |||||
56 | /** |
||||
57 | * If model is not banned. |
||||
58 | * |
||||
59 | * @return bool |
||||
60 | */ |
||||
61 | public function isNotBanned(): bool |
||||
62 | { |
||||
63 | return !$this->isBanned(); |
||||
64 | } |
||||
65 | |||||
66 | /** |
||||
67 | * Ban model. |
||||
68 | * |
||||
69 | * @param null|array $attributes |
||||
70 | * @return \Cog\Contracts\Ban\Ban |
||||
71 | */ |
||||
72 | public function ban(array $attributes = []): BanContract |
||||
73 | { |
||||
74 | return app(BanServiceContract::class)->ban($this, $attributes); |
||||
0 ignored issues
–
show
$this of type Cog\Laravel\Ban\Traits\HasBannedAtHelpers is incompatible with the type Cog\Contracts\Ban\Bannable expected by parameter $bannable of Cog\Contracts\Ban\BanService::ban() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
75 | } |
||||
76 | |||||
77 | /** |
||||
78 | * Remove ban from model. |
||||
79 | * |
||||
80 | * @return void |
||||
81 | */ |
||||
82 | public function unban(): void |
||||
83 | { |
||||
84 | app(BanServiceContract::class)->unban($this); |
||||
0 ignored issues
–
show
$this of type Cog\Laravel\Ban\Traits\HasBannedAtHelpers is incompatible with the type Cog\Contracts\Ban\Bannable expected by parameter $bannable of Cog\Contracts\Ban\BanService::unban() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
85 | } |
||||
86 | } |
||||
87 |