Configurations   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 16
eloc 35
c 1
b 0
f 1
dl 0
loc 71
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 3 1
A all() 0 6 2
A updateGroup() 0 4 1
A createGroup() 0 6 1
A findByName() 0 12 5
A update() 0 4 1
A create() 0 6 1
A deleteGroup() 0 3 1
A findByGroupName() 0 8 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: aappen
5
 * Date: 04.10.18
6
 * Time: 11:49
7
 */
8
9
namespace seretos\testrail\api;
10
11
12
class Configurations extends AbstractApi
13
{
14
    private $cache = [];
15
    public function all(int $projectId)
16
    {
17
        if (!isset($this->cache[$projectId])) {
18
            $this->cache[$projectId] = $this->connector->send_get('get_configs/'.$this->encodePath($projectId));
19
        }
20
        return $this->cache[$projectId];
21
    }
22
23
    public function findByGroupName(int $projectId, string $name) {
24
        $configurations = $this->all($projectId);
25
        foreach ($configurations as $configuration) {
26
            if ($configuration['name'] === $name) {
27
                return $configuration;
28
            }
29
        }
30
        return [];
31
    }
32
33
    public function findByName(int $projectId, string $fieldName, string $name) {
34
        $configurations = $this->all($projectId);
35
        foreach ($configurations as $configuration) {
36
            if ($configuration['name'] == $fieldName) {
37
                foreach ($configuration['configs'] as $config) {
38
                    if ($config['name'] === $name) {
39
                        return $config;
40
                    }
41
                }
42
            }
43
        }
44
        return [];
45
    }
46
47
    public function createGroup(int $projectId, string $name)
48
    {
49
        $group = $this->connector->send_post('add_config_group/'.$this->encodePath($projectId),
50
            ['name' => $name]);
51
        unset($this->cache[$projectId]);
52
        return $group;
53
    }
54
55
    public function updateGroup(int $groupId, string $name) {
56
        $group = $this->connector->send_post('update_config_group/'.$this->encodePath($groupId), ['name' => $name]);
57
        $this->cache = [];
58
        return $group;
59
    }
60
61
    public function deleteGroup(int $groupId) {
62
        $this->connector->send_post('delete_config_group/'.$this->encodePath($groupId), []);
63
        $this->cache = [];
64
    }
65
66
    public function create(int $groupId, string $name)
67
    {
68
        $config = $this->connector->send_post('add_config/'.$this->encodePath($groupId),
69
            ['name' => $name]);
70
        $this->cache = [];
71
        return $config;
72
    }
73
74
    public function update(int $configId, string $name) {
75
        $this->connector->send_post('update_config/'.$this->encodePath($configId),
76
            ['name' => $name]);
77
        $this->cache = [];
78
    }
79
80
    public function delete(int $configId) {
81
        $this->connector->send_post('delete_config/'.$this->encodePath($configId), []);
82
        $this->cache = [];
83
    }
84
}