1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
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
|
|
|
namespace Gitamin\Handlers\Events\Project; |
13
|
|
|
|
14
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
15
|
|
|
use Gitamin\Events\Project\ProjectEventInterface; |
16
|
|
|
use Gitamin\Events\Project\ProjectWasAddedEvent; |
17
|
|
|
use Gitamin\Events\Project\ProjectWasUpdatedEvent; |
18
|
|
|
use Gitamin\Events\Project\ProjectWasRemovedEvent; |
19
|
|
|
use Gitamin\Handlers\Commands\Moment\AddMomentCommandHandler; |
20
|
|
|
use Gitamin\Commands\Moment\AddMomentCommand; |
21
|
|
|
use Gitamin\Models\Project; |
22
|
|
|
use Gitamin\Models\Moment; |
23
|
|
|
|
24
|
|
|
class SendProjectMomentHandler |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
use DispatchesJobs; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Handle the project updated moment. |
31
|
|
|
*/ |
32
|
|
|
public function handle(ProjectEventInterface $event) |
33
|
|
|
{ |
34
|
|
|
if($event instanceof ProjectWasUpdateEvent) { |
|
|
|
|
35
|
|
|
$action = Moment::UPDATED; |
|
|
|
|
36
|
|
|
} else if ($event instanceof ProjectWasRemovedEvent) { |
37
|
|
|
$action = Moment::CLOSED; |
|
|
|
|
38
|
|
|
} else { |
39
|
|
|
$action = Moment::CREATED; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->trigger($event->project, Moment::CREATED); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Trigger the moment. |
47
|
|
|
* |
48
|
|
|
* @param \Gitamin\Models\Project $project |
49
|
|
|
* @param int $action |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
|
|
protected function trigger(Project &$project, $action) |
53
|
|
|
{ |
54
|
|
|
$data = [ |
55
|
|
|
'target_type' => 'Project', |
56
|
|
|
'target_id' => $project->id, |
|
|
|
|
57
|
|
|
'action' => $action, |
58
|
|
|
'author_id' => $project->creator_id, |
|
|
|
|
59
|
|
|
'project_id' => $project->id, |
|
|
|
|
60
|
|
|
]; |
61
|
|
|
$moment = Moment::create($data); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.