Passed
Push — master ( 656593...4e2bc2 )
by Php Easy Api
03:42
created

PhpUnitManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 29 6
1
<?php
2
3
namespace Resta\Support;
4
5
class PhpUnitManager
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $data;
11
12
    /**
13
     * PhpUnitManager constructor.
14
     * @param array $data
15
     */
16
    public function __construct($data=array())
17
    {
18
        $this->data = $data;
19
    }
20
21
    /**
22
     * add new element for phpunit.xml
23
     *
24
     * @param null|string $attribute
25
     * @param null|string $key
26
     * @param null|string $value
27
     * @return mixed
28
     */
29
    public function add($attribute=null,$key=null,$value=null)
30
    {
31
        $list = [];
32
33
        //all add method parameters must come full.
34
        if(!is_null($attribute) && !is_null($key) && !is_null($value)){
35
36
            // we do 0 key control for the testsuite data.
37
            // this phpunit has a multiple test suite data if 0 key is present.
38
            if(isset($this->data['testsuites']['testsuite'][0])){
39
                foreach ($this->data['testsuites']['testsuite'] as $key=>$item){
40
                    $list[$key] = $item;
41
                }
42
            }
43
            else{
44
                //only for a single test suite data
45
                $list[] = $this->data['testsuites']['testsuite'];
46
            }
47
48
            // the data to be added is started with
49
            // the number of pieces of the previous test suite.
50
            $newKey = count($list);
51
52
            //add new data
53
            $list[$newKey]['@attributes']['name'] = $attribute;
54
            $list[$newKey][$key] = $value;
55
        }
56
57
        return $list;
58
    }
59
}