Completed
Pull Request — master (#34)
by Fèvre
05:22 queued 02:35
created

FloodGate   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isFlooding() 0 13 1
1
<?php
2
namespace Xetaravel\Models\Gates;
3
4
use Carbon\Carbon;
5
use Illuminate\Support\Facades\Auth;
6
7
trait FloodGate
8
{
9
    /**
10
     * Check whatever the user is flooding or not.
11
     *
12
     * @param string $rule The configuration rule to use.
13
     *
14
     * @return bool
15
     */
16
    public static function isFlooding(string $rule = 'xetaravel.flood.general'): bool
17
    {
18
        $class = get_called_class();
19
        $user = Auth::user();
20
21
        return $class::where('user_id', $user->id)
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
22
            ->where(
23
                'created_at',
24
                '>=',
25
                Carbon::now()->subSeconds(config($rule))
26
            )
27
            ->exists();
28
    }
29
}
30