Completed
Push — master ( 38efb8...5cc558 )
by Ryan
05:49
created

EntryObserver::restoring()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Entry;
2
3
use Anomaly\Streams\Platform\Entry\Command\DeleteEntryTranslations;
4
use Anomaly\Streams\Platform\Entry\Command\SetMetaInformation;
5
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
6
use Anomaly\Streams\Platform\Entry\Event\EntryWasCreated;
7
use Anomaly\Streams\Platform\Entry\Event\EntryWasDeleted;
8
use Anomaly\Streams\Platform\Entry\Event\EntryWasRestored;
9
use Anomaly\Streams\Platform\Entry\Event\EntryWasSaved;
10
use Anomaly\Streams\Platform\Entry\Event\EntryWasUpdated;
11
use Anomaly\Streams\Platform\Model\Command\CascadeDelete;
12
use Anomaly\Streams\Platform\Model\Command\CascadeRestore;
13
use Anomaly\Streams\Platform\Model\EloquentModel;
14
use Anomaly\Streams\Platform\Model\Event\ModelsWereDeleted;
15
use Anomaly\Streams\Platform\Model\Event\ModelsWereUpdated;
16
use Anomaly\Streams\Platform\Support\Observer;
17
18
/**
19
 * Class EntryObserver
20
 *
21
 * @link    http://pyrocms.com/
22
 * @author  PyroCMS, Inc. <[email protected]>
23
 * @author  Ryan Thompson <[email protected]>
24
 *
25
 */
26
class EntryObserver extends Observer
27
{
28
29
    /**
30
     * Run before a record is created.
31
     *
32
     * @param EntryInterface $entry
33
     */
34
    public function creating(EntryInterface $entry)
35
    {
36
        $entry->fireFieldTypeEvents('entry_creating');
37
    }
38
39
    /**
40
     * Run after a record is created.
41
     *
42
     * @param EntryInterface $entry
43
     */
44
    public function created(EntryInterface $entry)
45
    {
46
        $entry->fireFieldTypeEvents('entry_created');
47
48
        $this->events->fire(new EntryWasCreated($entry));
49
    }
50
51
    /**
52
     * Run before a record is updated.
53
     *
54
     * @param EntryInterface $entry
55
     */
56
    public function updating(EntryInterface $entry)
0 ignored issues
show
Unused Code introduced by
The parameter $entry 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...
57
    {
58
        //
59
    }
60
61
    /**
62
     * Run after a record is updated.
63
     *
64
     * @param EntryInterface $entry
65
     */
66
    public function updated(EntryInterface $entry)
67
    {
68
        $entry->fireFieldTypeEvents('entry_updated');
69
70
        $this->events->fire(new EntryWasUpdated($entry));
71
    }
72
73
    /**
74
     * Run after multiple entries have been updated.
75
     *
76
     * @param EntryInterface $entry
77
     */
78
    public function updatedMultiple(EntryInterface $entry)
79
    {
80
        $entry->flushCache();
81
82
        $this->events->fire(new ModelsWereUpdated($entry));
0 ignored issues
show
Documentation introduced by
$entry is of type object<Anomaly\Streams\P...ontract\EntryInterface>, but the function expects a object<Anomaly\Streams\P...rm\Model\EloquentModel>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
    }
84
85
    /**
86
     * Before saving an entry touch the
87
     * meta information.
88
     *
89
     * @param  EntryInterface $entry
90
     * @return bool
91
     */
92
    public function saving(EntryInterface $entry)
93
    {
94
        //$entry->fireFieldTypeEvents('entry_saving');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
96
        $this->commands->dispatch(new SetMetaInformation($entry));
0 ignored issues
show
Documentation introduced by
$entry is of type object<Anomaly\Streams\P...ontract\EntryInterface>, but the function expects a object<Anomaly\Streams\P...rm\Model\EloquentModel>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
98
        return true;
99
    }
100
101
    /**
102
     * Run after saving a record.
103
     *
104
     * @param EntryInterface $entry
105
     */
106
    public function saved(EntryInterface $entry)
107
    {
108
        $entry->flushCache();
109
        $entry->fireFieldTypeEvents('entry_saved');
110
111
        $this->events->fire(new EntryWasSaved($entry));
112
    }
113
114
    /**
115
     * Run before a record is deleted.
116
     *
117
     * @param  EntryInterface|EloquentModel $entry
118
     * @return bool
119
     */
120
    public function deleting(EntryInterface $entry)
121
    {
122
        $this->dispatch(new CascadeDelete($entry));
0 ignored issues
show
Documentation introduced by
$entry is of type object<Anomaly\Streams\P...ontract\EntryInterface>, but the function expects a object<Anomaly\Streams\P...rm\Model\EloquentModel>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
124
        return true;
125
    }
126
127
    /**
128
     * Run after a record has been deleted.
129
     *
130
     * @param EntryInterface $entry
131
     */
132
    public function deleted(EntryInterface $entry)
133
    {
134
        $entry->flushCache();
135
        $entry->fireFieldTypeEvents('entry_deleted');
136
137
        $this->commands->dispatch(new DeleteEntryTranslations($entry));
138
139
        $this->events->fire(new EntryWasDeleted($entry));
140
    }
141
142
    /**
143
     * Run after entries records have been deleted.
144
     *
145
     * @param EntryInterface $entry
146
     */
147
    public function deletedMultiple(EntryInterface $entry)
148
    {
149
        $entry->flushCache();
150
151
        $this->events->fire(new ModelsWereDeleted($entry));
0 ignored issues
show
Documentation introduced by
$entry is of type object<Anomaly\Streams\P...ontract\EntryInterface>, but the function expects a object<Anomaly\Streams\P...rm\Model\EloquentModel>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
152
    }
153
154
    /**
155
     * Fired just before restoring.
156
     *
157
     * @param EntryInterface|EloquentModel $entry
158
     */
159
    public function restoring(EntryInterface $entry)
0 ignored issues
show
Unused Code introduced by
The parameter $entry 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...
160
    {
161
        //
162
    }
163
164
    /**
165
     * Run after a record has been restored.
166
     *
167
     * @param EntryInterface|EloquentModel $entry
168
     */
169
    public function restored(EntryInterface $entry)
170
    {
171
        $entry->flushCache();
172
        $entry->fireFieldTypeEvents('entry_restored');
173
174
        $this->dispatch(new CascadeRestore($entry));
0 ignored issues
show
Documentation introduced by
$entry is of type object<Anomaly\Streams\P...ontract\EntryInterface>, but the function expects a object<Anomaly\Streams\P...rm\Model\EloquentModel>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
176
        $this->events->fire(new EntryWasRestored($entry));
177
    }
178
}
179