1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016, 2015 Richard Klees <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This software is licensed under The MIT License. You should have received |
8
|
|
|
* a copy of the license along with the code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\Analysis; |
12
|
|
|
|
13
|
|
|
use Lechimp\Dicto\Rules\Ruleset; |
14
|
|
|
use Lechimp\Dicto\Rules\Rule; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Combines multiple listeners into one. |
18
|
|
|
*/ |
19
|
|
|
class CombinedListener implements Listener { |
20
|
|
|
/** |
21
|
|
|
* @var Listener[] |
22
|
|
|
*/ |
23
|
|
|
protected $listeners; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Listener[] $listeners |
27
|
|
|
*/ |
28
|
|
|
public function __construct(array $listeners) { |
29
|
|
|
$this->listeners = array_map(function(Listener $l) { |
30
|
|
|
return $l; |
31
|
|
|
}, $listeners); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return Listener[] |
36
|
|
|
*/ |
37
|
|
|
public function listeners() { |
38
|
|
|
return $this->listeners; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdocs |
43
|
|
|
*/ |
44
|
|
|
public function begin_run($commit_hash) { |
45
|
|
|
foreach ($this->listeners as $g) { |
46
|
|
|
$g->begin_run($commit_hash); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdocs |
52
|
|
|
*/ |
53
|
|
|
public function end_run() { |
54
|
|
|
foreach ($this->listeners as $g) { |
55
|
|
|
$g->end_run(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritdocs |
61
|
|
|
*/ |
62
|
|
|
public function begin_ruleset(Ruleset $ruleset) { |
63
|
|
|
foreach ($this->listeners as $g) { |
64
|
|
|
$g->begin_ruleset($ruleset); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritdocs |
70
|
|
|
*/ |
71
|
|
|
public function end_ruleset() { |
72
|
|
|
foreach ($this->listeners as $g) { |
73
|
|
|
$g->end_ruleset(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritdocs |
79
|
|
|
*/ |
80
|
|
|
public function begin_rule(Rule $rule) { |
81
|
|
|
foreach ($this->listeners as $g) { |
82
|
|
|
$g->begin_rule($rule); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdocs |
88
|
|
|
*/ |
89
|
|
|
public function end_rule() { |
90
|
|
|
foreach ($this->listeners as $g) { |
91
|
|
|
$g->end_rule(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @inheritdocs |
97
|
|
|
*/ |
98
|
|
|
public function report_violation(Violation $violation) { |
99
|
|
|
foreach ($this->listeners as $g) { |
100
|
|
|
$g->report_violation($violation); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|