Reset   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 6 1
A reset() 0 4 1
A cleanupMatches() 0 4 1
1
<?php
2
3
namespace App\Listeners\Tournament;
4
5
use App\Match;
6
use App\Tournament as TournamentModel;
7
use App\Events\Tournament\TournamentWasReset;
8
9
/**
10
 * Class Reset
11
 * @package App\Listeners\Tournament
12
 */
13
class Reset
14
{
15
    /**
16
     * @var TournamentModel
17
     */
18
    protected $tournament;
19
20
    /**
21
     * Create the event listener.
22
     * Reset constructor.
23
     */
24
    public function __construct()
25
    {
26
        //
27
    }
28
29
    /**
30
     * Handle the event.
31
     *
32
     * @param  TournamentWasReset $event
33
     * @return void
34
     */
35
    public function handle(TournamentWasReset $event)
36
    {
37
        $this->tournament = $event->tournament;
38
39
        $this->reset();
40
    }
41
42
    protected function reset()
43
    {
44
        $this->cleanupMatches();
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50
    protected function cleanupMatches()
51
    {
52
        return Match::where(['tournamentId' => $this->tournament->id])->delete();
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Tournament>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
53
    }
54
}
55