UserInvitationObserver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 28.07 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 57
rs 10
wmc 5
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A deleted() 16 16 2
A __construct() 0 4 1
A created() 0 4 1
A deleting() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Acacha\Users\Observers;
4
5
use Acacha\Users\Models\UserInvitation;
6
use Acacha\Users\Services\UserInvitations;
7
use Venturecraft\Revisionable\Revision;
8
9
/**
10
 * Class UserInvitationObserver.
11
 */
12
class UserInvitationObserver
13
{
14
15
    public $service;
16
17
    /**
18
     * UserInvitationObserver constructor.
19
     *
20
     * @param $service
21
     */
22
    public function __construct(UserInvitations $service)
23
    {
24
        $this->service = $service;
25
    }
26
27
    /**
28
     * Listen to the UserInvitation created event.
29
     *
30
     * @param  UserInvitation  $invitation
31
     * @return void
32
     */
33
    public function created(UserInvitation $invitation)
34
    {
35
        $this->service->send($invitation);
36
    }
37
38
    /**
39
     * Listen to the UserInvitation deleting event.
40
     *
41
     * @param  UserInvitation  $invitation
42
     * @return void
43
     */
44
    public function deleting(UserInvitation $invitation)
0 ignored issues
show
Unused Code introduced by
The parameter $invitation is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        //
47
    }
48
49
    /**
50
     * Listen to the UserInvitation deleted event.
51
     */
52 View Code Duplication
    public function deleted(UserInvitation $invitation)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        // Insert into 'revisions' (calling getTable probably not necessary, but to be safe).
55
        \DB::table((new Revision())->getTable())->insert([
56
            [
57
                'revisionable_type' => $invitation->getMorphClass(),
58
                'revisionable_id' => $invitation->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Acacha\Users\Models\UserInvitation>. 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...
59
                'key' => 'deleted_at',
60
                'old_value' => null,
61
                'new_value' => new \DateTime(),
62
                'user_id' => (\Auth::check() ? \Auth::user()->id : null),
63
                'created_at' => new \DateTime(),
64
                'updated_at' => new \DateTime(),
65
            ]
66
        ]);
67
    }
68
}