Completed
Push — master ( 7949ab...b0b972 )
by Tomáš
02:22
created

Progression::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TournamentGenerator;
4
5
/**
6
 *
7
 */
8
class Progression
9
{
10
11
	private $from;
12
	private $to;
13
	private $start = 0;
14
	private $len = null;
15
	private $filters = [];
16
	private $progressed = false;
17
18 34
	public function __construct(Group $from, Group $to, int $start = 0, int $len = null) {
19 34
		$this->from = $from;
20 34
		$this->to = $to;
21 34
		$this->start = $start;
22 34
		$this->len = $len;
23 34
	}
24
25 17
	public function __toString() {
26 17
		return 'Team from '.$this->from;
27
	}
28
29 1
	public function setFilters(array $filters) {
30 1
		$this->filters = $filters;
31 1
		return $this;
32
	}
33 7
	public function addFilter(TeamFilter ...$filters) {
34 7
		foreach ($filters as $filter) {
35 7
			$this->filters[] = $filter;
36
		}
37 7
		return $this;
38
	}
39
40 33
	public function progress(bool $blank = false) {
41 33
		if ($this->progressed) return $this;
42 33
		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
43 16
		else $teams = $this->from->sortTeams(null, $this->filters);
44
45 33
		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
46 5
		else $next = $teams;
47
48 33
		$i = 1;
49
50 33
		foreach ($next as $team) {
51 33
			if ($blank) {
52 17
				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team, $this->from, $this));
53 17
				$i++;
54
			}
55 33
			else $team->sumPoints += $this->from->progressPoints;
56
		}
57
58 33
		$this->from->addProgressed($next);
59 33
		if (!$blank) $this->to->addTeam($next);
60 33
		$this->progressed = true;
61 33
		return $this;
62
	}
63 1
	public function reset() {
64 1
		$this->progressed = false;
65 1
		return $this;
66
	}
67
68
}
69