Test Failed
Pull Request — master (#10)
by Alice
04:15
created

EventPoolFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 1
1
<?php
2
3
namespace Wonderland\Thread\Factory;
4
5
use Wonderland\Thread\AbstractThreadPoolMediator;
6
use Wonderland\Thread\Event\PoolEvent;
7
use Wonderland\Thread\AbstractThread;
8
use Wonderland\Thread\ThreadPool;
9
10
class EventPoolFactory
11
{
12
	/**
13
	 * @param string                                $eventName
14
	 * @param ThreadPool|AbstractThreadPoolMediator $pool
15
	 * @param AbstractThread|null                   $thread
16
	 * @return PoolEvent
17
	 */
18
	public static function create(string $eventName, AbstractThreadPoolMediator $pool, ?AbstractThread $thread = null): PoolEvent
19
	{
20
		$event = new PoolEvent($eventName);
21
		$event->setThreadNb(count($pool->getThreads()));
0 ignored issues
show
Bug introduced by
The method getThreads() does not exist on Wonderland\Thread\AbstractThreadPoolMediator. Since it exists in all sub-types, consider adding an abstract or default implementation to Wonderland\Thread\AbstractThreadPoolMediator. ( Ignorable by Annotation )

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

21
		$event->setThreadNb(count($pool->/** @scrutinizer ignore-call */ getThreads()));
Loading history...
22
		$event->setThreadDoneNb(count($pool->getThreads()) - count($pool->getToRunThreads()));
0 ignored issues
show
Bug introduced by
The method getToRunThreads() does not exist on Wonderland\Thread\AbstractThreadPoolMediator. Since it exists in all sub-types, consider adding an abstract or default implementation to Wonderland\Thread\AbstractThreadPoolMediator. ( Ignorable by Annotation )

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

22
		$event->setThreadDoneNb(count($pool->getThreads()) - count($pool->/** @scrutinizer ignore-call */ getToRunThreads()));
Loading history...
23
		$event->setMaxRunningThreadNb($pool->getMaxRunningThreadNb());
0 ignored issues
show
Bug introduced by
The method getMaxRunningThreadNb() does not exist on Wonderland\Thread\AbstractThreadPoolMediator. Since it exists in all sub-types, consider adding an abstract or default implementation to Wonderland\Thread\AbstractThreadPoolMediator. ( Ignorable by Annotation )

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

23
		$event->setMaxRunningThreadNb($pool->/** @scrutinizer ignore-call */ getMaxRunningThreadNb());
Loading history...
24
		$event->setThreadLeftNb(count($pool->getToRunThreads()));
25
		$event->setRunningThreadNb(count($pool->getRunningThreads()));
0 ignored issues
show
Bug introduced by
The method getRunningThreads() does not exist on Wonderland\Thread\AbstractThreadPoolMediator. Since it exists in all sub-types, consider adding an abstract or default implementation to Wonderland\Thread\AbstractThreadPoolMediator. ( Ignorable by Annotation )

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

25
		$event->setRunningThreadNb(count($pool->/** @scrutinizer ignore-call */ getRunningThreads()));
Loading history...
26
		$event->setThread($thread);
27
28
		return $event;
29
	}
30
}
31