Completed
Push — master ( c7b1f1...793ac0 )
by KwangSeob
05:03 queued 02:28
created

VersionService::delete()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 9
nc 5
nop 3
dl 0
loc 19
rs 8.2222
c 0
b 0
f 0
1
<?php
2
3
namespace JiraRestApi\Version;
4
5
use JiraRestApi\Issue\Version;
6
use JiraRestApi\JiraException;
7
use JiraRestApi\Project\ProjectService;
8
9
class VersionService extends \JiraRestApi\JiraClient
10
{
11
    private $uri = '/version';
12
13
    /**
14
     * Function to create a new project version.
15
     *
16
     * @param Version|array $version
17
     *
18
     * @throws \JiraRestApi\JiraException
19
     * @throws \JsonMapper_Exception
20
     *
21
     * @return Version|object Version class
22
     */
23
    public function create($version)
24
    {
25
        if ($version->releaseDate instanceof \DateTime) {
26
            $version->releaseDate = $version->releaseDate->format('Y-m-d');
0 ignored issues
show
Documentation Bug introduced by
It seems like $version->releaseDate->format('Y-m-d') of type string is incompatible with the declared type null|DateTime of property $releaseDate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
        }
28
        $data = json_encode($version);
29
30
        $this->log->addInfo("Create Version=\n".$data);
31
32
        $ret = $this->exec($this->uri, $data, 'POST');
33
34
        return $this->json_mapper->map(
35
            json_decode($ret), new Version()
36
        );
37
    }
38
39
    /**
40
     * Modify a version's sequence within a project.
41
     *
42
     * @param $version
43
     *
44
     * @throws JiraException
45
     */
46
    public function move($version)
0 ignored issues
show
Unused Code introduced by
The parameter $version is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    public function move(/** @scrutinizer ignore-unused */ $version)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        throw new JiraException('move version not yet implemented');
49
    }
50
51
    /**
52
     * get project version.
53
     *
54
     * @param $id version id
55
     *
56
     * @return Version
57
     *
58
     * @see ProjectService::getVersions()
59
     */
60
    public function get($id)
61
    {
62
        $ret = $this->exec($this->uri.'/'.$id);
63
64
        $this->log->addInfo('Result='.$ret);
65
66
        $json = json_decode($ret);
67
        $results = array_map(function ($elem) {
68
            return $this->json_mapper->map($elem, new ProjectType());
0 ignored issues
show
Bug introduced by
The type JiraRestApi\Version\ProjectType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
        }, $json);
70
71
        return $results;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $results returns the type array which is incompatible with the documented return type JiraRestApi\Issue\Version.
Loading history...
72
    }
73
74
    /**
75
     * @author Martijn Smidt <[email protected]>
76
     *
77
     * @param Version $version
78
     *
79
     * @throws JiraException
80
     *
81
     * @return string
82
     */
83
    public function update(Version $version)
84
    {
85
        if (!$version->id || !is_numeric($version->id)) {
86
            throw new JiraException($version->id.' is not a valid version id.');
87
        }
88
89
        if ($version->releaseDate instanceof \DateTime) {
90
            $version->releaseDate = $version->releaseDate->format('Y-m-d');
0 ignored issues
show
Documentation Bug introduced by
It seems like $version->releaseDate->format('Y-m-d') of type string is incompatible with the declared type null|DateTime of property $releaseDate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
91
        }
92
93
        $data = json_encode($version);
94
        $ret = $this->exec($this->uri.'/'.$version->id, $data, 'PUT');
95
96
        return $ret;
97
    }
98
99
    /**
100
     * @author Martijn Smidt <[email protected]>
101
     *
102
     * @param Version      $version
103
     * @param Version|bool $moveAffectedIssuesTo
104
     * @param Version|bool $moveFixIssuesTo
105
     *
106
     * @throws JiraException
107
     *
108
     * @return string
109
     */
110
    public function delete(Version $version, $moveAffectedIssuesTo = false, $moveFixIssuesTo = false)
111
    {
112
        if (!$version->id || !is_numeric($version->id)) {
113
            throw new JiraException($version->id.' is not a valid version id.');
114
        }
115
116
        $data = [];
117
118
        if ($moveAffectedIssuesTo && $moveAffectedIssuesTo instanceof Version) {
119
            $data['moveAffectedIssuesTo'] = $moveAffectedIssuesTo->name;
120
        }
121
122
        if ($moveFixIssuesTo && $moveFixIssuesTo instanceof Version) {
123
            $data['moveFixIssuesTo'] = $moveFixIssuesTo->name;
124
        }
125
126
        $ret = $this->exec($this->uri.'/'.$version->id, json_encode($data), 'DELETE');
127
128
        return $ret;
129
    }
130
131
    public function merge($ver)
0 ignored issues
show
Unused Code introduced by
The parameter $ver is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

131
    public function merge(/** @scrutinizer ignore-unused */ $ver)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
132
    {
133
        throw new JiraException('merge version not yet implemented');
134
    }
135
136
    /**
137
     * Returns a bean containing the number of fixed in and affected issues for the given version.
138
     *
139
     * @param $id int version id
140
     *
141
     * @throws JiraException
142
     *
143
     * @see https://docs.atlassian.com/jira/REST/server/#api/2/version-getVersionRelatedIssues
144
     */
145
    public function getRelatedIssues($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

145
    public function getRelatedIssues(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146
    {
147
        throw new JiraException('get version Related Issues not yet implemented');
148
    }
149
}
150