Passed
Pull Request — master (#164)
by
unknown
04:42
created

VersionService::delete()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 9
nc 5
nop 3
dl 0
loc 22
rs 6.9811
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
        {
27
            $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...
28
        }
29
        $data = json_encode($version);
30
31
        $this->log->addInfo("Create Version=\n".$data);
32
33
        $ret = $this->exec($this->uri, $data, 'POST');
34
35
        return $this->json_mapper->map(
36
            json_decode($ret), new Version()
37
        );
38
    }
39
40
    /**
41
     * Modify a version's sequence within a project.
42
     *
43
     * @param $version
44
     *
45
     * @throws JiraException
46
     */
47
    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

47
    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...
48
    {
49
        throw new JiraException('move version not yet implemented');
50
    }
51
52
    /**
53
     * get project version.
54
     *
55
     * @param $id version id
56
     *
57
     * @return Version
58
     *
59
     * @see ProjectService::getVersions()
60
     */
61
    public function get($id)
62
    {
63
        $ret = $this->exec($this->uri.'/'.$id);
64
65
        $this->log->addInfo('Result='.$ret);
66
67
        $json = json_decode($ret);
68
        $results = array_map(function ($elem) {
69
            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...
70
        }, $json);
71
72
        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...
73
    }
74
75
    /**
76
     * @author Martijn Smidt <[email protected]>
77
     *
78
     * @param Version $version
79
     *
80
     * @return string
81
     * @throws JiraException
82
     *
83
     */
84
    public function update(Version $version)
85
    {
86
        if(!$version->id || !is_numeric($version->id))
87
        {
88
            throw new JiraException($version->id . ' is not a valid version id.');
89
        }
90
91
        if($version->releaseDate instanceof \DateTime)
92
        {
93
            $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...
94
        }
95
96
        $data = json_encode($version);
97
        $ret = $this->exec($this->uri . '/' . $version->id, $data, 'PUT');
98
99
        return $ret;
100
    }
101
102
    /**
103
     * @author Martijn Smidt <[email protected]>
104
     *
105
     * @param Version $version
106
     * @param Version|bool $moveAffectedIssuesTo
107
     * @param Version|bool $moveFixIssuesTo
108
     *
109
     * @return string
110
     * @throws JiraException
111
     */
112
113
    public function delete(Version $version, $moveAffectedIssuesTo = false, $moveFixIssuesTo = false)
114
    {
115
        if(!$version->id || !is_numeric($version->id))
116
        {
117
            throw new JiraException($version->id . ' is not a valid version id.');
118
        }
119
120
        $data = [];
121
122
        if($moveAffectedIssuesTo && $moveAffectedIssuesTo instanceof Version)
123
        {
124
            $data['moveAffectedIssuesTo'] = $moveAffectedIssuesTo->name;
125
        }
126
127
        if($moveFixIssuesTo && $moveFixIssuesTo instanceof Version)
128
        {
129
            $data['moveFixIssuesTo'] = $moveFixIssuesTo->name;
130
        }
131
132
        $ret = $this->exec($this->uri . '/' . $version->id, json_encode($data), 'DELETE');
133
134
        return $ret;
135
    }
136
137
    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

137
    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...
138
    {
139
        throw new JiraException('merge version not yet implemented');
140
    }
141
142
    /**
143
     * Returns a bean containing the number of fixed in and affected issues for the given version.
144
     *
145
     * @param $id int version id
146
     *
147
     * @throws JiraException
148
     *
149
     * @see https://docs.atlassian.com/jira/REST/server/#api/2/version-getVersionRelatedIssues
150
     */
151
    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

151
    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...
152
    {
153
        throw new JiraException('get version Related Issues not yet implemented');
154
    }
155
}
156