Passed
Branch master (7949ab)
by Tomáš
02:07
created

Progression   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 47
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 14

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 2 1
A __construct() 0 5 1
A addFilter() 0 5 2
B progress() 0 20 10
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
17 32
	public function __construct(Group $from, Group $to, int $start = 0, int $len = null) {
18 32
		$this->from = $from;
19 32
		$this->to = $to;
20 32
		$this->start = $start;
21 32
		$this->len = $len;
22 32
	}
23
24 17
	public function __toString() {
25 17
		return 'Team from '.$this->from;
26
	}
27
28 7
	public function addFilter(TeamFilter ...$filters) {
29 7
		foreach ($filters as $filter) {
30 7
			$this->filters[] = $filter;
31
		}
32 7
		return $this;
33
	}
34
35 31
	public function progress(bool $blank = false) {
36 31
		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
37 14
		else $teams = $this->from->sortTeams(null, $this->filters);
38
39 31
		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
40 4
		else $next = $teams;
41
42 31
		$i = 1;
43
44 31
		foreach ($next as $team) {
45 31
			if ($blank) {
46 17
				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team));
47 17
				$i++;
48
			}
49 31
			else $team->sumPoints += $this->from->progressPoints;
50
		}
51
52 31
		$this->from->addProgressed($next);
53 31
		if (!$blank) $this->to->addTeam($next);
54 31
		return $this;
55
	}
56
57
}
58