Passed
Pull Request — master (#19)
by Harry
04:08 queued 12s
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
            && $this instanceof DispatcherInterface
24 4
            && $this instanceof PrioritisedInterface) {
25 4
            $this->dispatch(PriorityChangedEvent::CHANGED, new PriorityChangedEvent($this, $priority, $oldPriority));
0 ignored issues
show
Bug introduced by
It seems like dispatch() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            $this->/** @scrutinizer ignore-call */ 
26
                   dispatch(PriorityChangedEvent::CHANGED, new PriorityChangedEvent($this, $priority, $oldPriority));
Loading history...
Bug introduced by
The method dispatch() does not exist on Graze\ParallelProcess\Event\DispatcherInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Graze\ParallelProcess\RunInterface or Graze\ParallelProcess\PoolInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            $this->/** @scrutinizer ignore-call */ 
26
                   dispatch(PriorityChangedEvent::CHANGED, new PriorityChangedEvent($this, $priority, $oldPriority));
Loading history...
Bug introduced by
The method dispatch() does not exist on Graze\ParallelProcess\PrioritisedInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Graze\ParallelProcess\PrioritisedInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            $this->/** @scrutinizer ignore-call */ 
26
                   dispatch(PriorityChangedEvent::CHANGED, new PriorityChangedEvent($this, $priority, $oldPriority));
Loading history...
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