Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — live ( 4e4fab...8952b2 )
by Dan
05:48 queued 46s
created

RouteIterator::getCurrentRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Smr\Routes;
4
5
use ArrayIterator;
6
use InfiniteIterator;
7
8
/**
9
 * Cyclically iterate over actions on a trade route
10
 */
11
class RouteIterator {
12
13
	private InfiniteIterator $routeIterator;
14
	private string $transaction = TRADER_BUYS;
15
16
	public function __construct(
17
		private MultiplePortRoute $route
18
	) {
19
		$oneWayRoutes = $route->getOneWayRoutes();
20
		$this->routeIterator = new InfiniteIterator(new ArrayIterator($oneWayRoutes));
21
22
		// PHP bug prevents IteratorIterator cache from initializing properly.
23
		// Just rewind to force it to populate its cache.
24
		$this->routeIterator->rewind();
25
	}
26
27
	public function getEntireRoute(): MultiplePortRoute {
28
		return $this->route;
29
	}
30
31
	public function getCurrentRoute(): OneWayRoute {
32
		return $this->routeIterator->current();
33
	}
34
35
	public function getCurrentTransaction(): string {
36
		return $this->transaction;
37
	}
38
39
	public function getCurrentSectorID(): int {
40
		return match ($this->transaction) {
41
			TRADER_BUYS => $this->getCurrentRoute()->getBuySectorId(),
42
			TRADER_SELLS => $this->getCurrentRoute()->getSellSectorId(),
43
		};
44
	}
45
46
	/**
47
	 * Advance to the next action on the route
48
	 */
49
	public function next(): void {
50
		if ($this->transaction == TRADER_SELLS) {
51
			$this->routeIterator->next();
52
		}
53
		$this->transaction = match ($this->transaction) {
54
			TRADER_SELLS => TRADER_BUYS,
55
			TRADER_BUYS => TRADER_SELLS,
56
		};
57
	}
58
59
}
60