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

PrioritisedTrait::setPriority()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 2
nop 1
crap 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