Suites::findByName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
nop 2
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
}