Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
11 / 11 |
|
100.00% |
9 / 9 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
SingleInstance | |
100.00% |
14 / 14 |
|
100.00% |
11 / 11 |
|
100.00% |
9 / 9 |
|
100.00% |
8 / 8 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPreferred | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIterator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
details | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isPreferred | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
analisysExists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
addAnalysis | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
countAnalysis | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Dbmi\Webservice\Contributor; |
3 | |
4 | use ArrayIterator; |
5 | use IteratorAggregate; |
6 | use Traversable; |
7 | |
8 | use Dbmi\Webservice\Analysis\SingleInstance as Analysis_Single; |
9 | use Dbmi\Webservice\Contributor\Struct as DS_Contributor; |
10 | use Dbmi\Webservice\Quake\IdStruct as DS_QuakeId; |
11 | |
12 | /** |
13 | * Contributors descriptor |
14 | * |
15 | * @param Dbmi\Webservice\Contributor\Struct $details Contributor data structure |
16 | * @param Dbmi\Webservice\Quake\IdStruct $quakeId Quake ID in DBMI format |
17 | * @param bool $preferred True if this contributor is preferred, false otherwise |
18 | */ |
19 | class SingleInstance implements IteratorAggregate{ |
20 | private DS_Contributor $details; |
21 | private DS_QuakeId $quakeId; |
22 | private bool $preferred = false; |
23 | |
24 | private array $analysis = array(); |
25 | |
26 | private int $curlErrNum = 0; |
27 | private string $curlErrInfo = ''; |
28 | |
29 | public function __construct(DS_Contributor $details, DS_QuakeId $quakeId, bool $preferred = false){ |
30 | $this->details = $details; |
31 | $this->quakeId = $quakeId; |
32 | $this->preferred = $preferred; |
33 | } |
34 | |
35 | /** |
36 | * set this contributor as (not) preferred |
37 | * |
38 | * @param bool $status True if this contributor is preferred, false otherwise |
39 | */ |
40 | public function setPreferred(bool $status):void { $this->preferred = $status; } |
41 | |
42 | /** |
43 | * get all analysis |
44 | * |
45 | * @return array array of strings with the found contributors |
46 | */ |
47 | public function getIterator():Traversable{ return new ArrayIterator($this->analysis); } |
48 | |
49 | /** |
50 | * get contributor details |
51 | * |
52 | * @return Dbmi\Webservice\Contributor\Struct Contributor details |
53 | */ |
54 | public function details():DS_Contributor{ return $this->details; } |
55 | |
56 | /** |
57 | * get this contributor preferred status |
58 | * |
59 | * @return bool True if this contributor is preferred, false otherwise |
60 | */ |
61 | public function isPreferred():bool{ return $this->preferred; } |
62 | |
63 | /** |
64 | * check if an analysis exist for this contributor |
65 | * |
66 | * @param string $name name of the analysis to check ('MCS', 'EMS', ...) |
67 | * |
68 | * @return bool True if exists, false otherwise |
69 | */ |
70 | public function analisysExists(string $name):bool{ return array_key_exists($name, $this->analysis); } |
71 | |
72 | /** |
73 | * Add Analysys type, can be called multiple times, |
74 | * analysis with the same name are renamed in $name-$i++ (where $i >= 1) |
75 | * |
76 | * @param string type of analysis to search |
77 | */ |
78 | public function addAnalysis(string $name):void { |
79 | $i = 1; |
80 | $usableName = $name; |
81 | while( array_key_exists($usableName, $this->analysis) ) |
82 | $usableName = sprintf("%s-%d", $name, $i++); |
83 | |
84 | $this->analysis[$usableName] = new Analysis_Single($this->details, $this->quakeId); |
85 | } |
86 | |
87 | /** |
88 | * Get number of Analysys found |
89 | * |
90 | * @return int analysis found |
91 | */ |
92 | public function countAnalysis():int { return count($this->analysis); } |
93 | } |
94 | |
95 | ?> |
96 |