Passed
Push — master ( b05304...84ccec )
by Harry
02:04
created

PrioritisedTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriority() 0 3 1
A setPriority() 0 10 5
1
<?php
2
3
namespace Graze\ParallelProcess;
4
5
use Graze\ParallelProcess\Event\DispatcherInterface;
6
use Graze\ParallelProcess\Event\PriorityChangedEvent;
7
8
trait PrioritisedTrait
9
{
10
    /** @var float */
11
    protected $priority;
12
13
    /**
14
     * @param float $priority
15
     *
16
     * @return $this
17
     */
18 4
    public function setPriority($priority)
19
    {
20 4
        $oldPriority = $this->priority;
21 4
        $this->priority = $priority;
22 4
        if (!($this instanceof RunInterface && $this->hasStarted())
23 4
            && method_exists($this, 'dispatch')
24 4
            && $this instanceof PrioritisedInterface) {
25 4
            $this->dispatch(PriorityChangedEvent::CHANGED, new PriorityChangedEvent($this, $priority, $oldPriority));
26
        }
27 4
        return $this;
28
    }
29
30
    /**
31
     * @return float
32
     */
33 42
    public function getPriority()
34
    {
35 42
        return $this->priority;
36
    }
37
}
38