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

DispatchedEvents   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDispatchedEvents() 0 8 1
A getFirstDispatchedEvent() 0 6 2
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