Suites   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 21
c 1
b 0
f 0
dl 0
loc 53
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 6 2
A create() 0 7 1
A get() 0 3 1
A update() 0 4 1
A findByName() 0 9 3
A delete() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: aappen
5
 * Date: 01.10.18
6
 * Time: 15:44
7
 */
8
9
namespace seretos\testrail\api;
10
11
12
class Suites 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_suites/'.$this->encodePath($projectId));
19
        }
20
        return $this->cache[$projectId];
21
    }
22
23
    public function get(int $suiteId)
24
    {
25
        return $this->connector->send_get('get_suite/'.$this->encodePath($suiteId));
26
    }
27
28
    public function findByName(int $projectId, string $name)
29
    {
30
        $allSuites = $this->all($projectId);
31
        foreach ($allSuites as $suite) {
32
            if ($suite['name'] === $name) {
33
                return $suite;
34
            }
35
        }
36
        return [];
37
    }
38
39
    public function create(int $projectId, string $name, string $description = null)
40
    {
41
        $suite = $this->connector->send_post('add_suite/'.$this->encodePath($projectId),
42
            ['name' => $name,
43
                'description' => $description]);
44
        unset($this->cache[$projectId]);
45
        return $suite;
46
    }
47
48
    /**
49
     * @param int $suiteId
50
     * @param array $parameters {
51
     * @var string $name
52
     * @var string $description
53
     * }
54
     * @return mixed
55
     */
56
    public function update(int $suiteId, array $parameters = []) {
57
        $suite = $this->connector->send_post('update_suite/'.$this->encodePath($suiteId), $parameters);
58
        $this->cache = [];
59
        return $suite;
60
    }
61
62
    public function delete(int $suiteId) {
63
        $this->connector->send_post('delete_suite/'.$this->encodePath($suiteId), []);
64
        $this->cache = [];
65
    }
66
}