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