Passed
Push — master ( 590453...ad5a85 )
by Arthur
24:49
created

DispatchedEvents::getFirstDispatchedEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 11.03.19
6
 * Time: 17:08
7
 */
8
9
namespace Foundation\Traits;
10
11
use Foundation\Generator\Abstracts\ResourceGeneratedEvent;
12
use Foundation\Generator\Contracts\ResourceGenerationContract;
13
use Illuminate\Support\Facades\Event;
14
15
trait DispatchedEvents
16
{
17
18
    /**
19
     * @param string $class
20
     * @return ResourceGeneratedEvent[]
21
     */
22
    protected function getDispatchedEvents(?string $class): array
23
    {
24
        $events = [];
25
        Event::assertDispatched($class, function ($event) use (&$events) {
26
            $events[] = $event;
27
            return true;
28
        });
29
        return $events;
30
    }
31
32
    /**
33
     * @param string $class
34
     * @return ResourceGenerationContract
35
     */
36
    protected function getFirstDispatchedEvent(?string $class): ResourceGenerationContract
37
    {
38
        $events = $this->getDispatchedEvents($class);
39
        if (empty($events))
40
            return null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return null returns the type null which is incompatible with the type-hinted return Foundation\Generator\Con...ourceGenerationContract.
Loading history...
41
        return $events[0];
42
    }
43
}
44