Completed
Pull Request — master (#10)
by Alice
03:35
created

EventPoolFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 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
	/**
14
	 * @param string                                $eventName
15
	 * @param ThreadPool|AbstractThreadPoolMediator $pool
16
	 * @param AbstractThread|null                   $thread
17
	 * @return PoolEvent
18
	 */
19 2
	public static function create(
20
		string $eventName,
21
		AbstractThreadPoolMediator $pool,
22
		?AbstractThread $thread = null
23
	): PoolEvent
24
	{
25 2
		$event = new PoolEvent($eventName);
26 2
		$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

26
		$event->setThreadNb(count($pool->/** @scrutinizer ignore-call */ getThreads()));
Loading history...
27 2
		$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

27
		$event->setThreadDoneNb(count($pool->getThreads()) - count($pool->/** @scrutinizer ignore-call */ getToRunThreads()));
Loading history...
28 2
		$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

28
		$event->setMaxRunningThreadNb($pool->/** @scrutinizer ignore-call */ getMaxRunningThreadNb());
Loading history...
29 2
		$event->setThreadLeftNb(count($pool->getToRunThreads()));
30 2
		$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

30
		$event->setRunningThreadNb(count($pool->/** @scrutinizer ignore-call */ getRunningThreads()));
Loading history...
31 2
		$event->setThread($thread);
32
33 2
		return $event;
34
	}
35
36
}
37