22
33namespace LaravelJira \Responses ;
44
5+ use ArrayObject ;
56use Carbon \Carbon ;
67use Illuminate \Support \Collection ;
78use Illuminate \Support \Facades \Log ;
8- use JiraRestApi \Issue \IssueService ;
9- use JiraRestApi \Issue \Version ;
9+ use JiraCloud \Issue \IssueService ;
10+ use JiraCloud \Issue \Version ;
1011use Khill \Duration \Duration ;
1112use Symfony \Component \Console \Output \OutputInterface ;
1213
2122 */
2223class Versions
2324{
24- public $ versions ;
25-
2625 /** @var Collection */
27- private $ filteredVersions ;
26+ private Collection $ filteredVersions ;
2827
29- public function __construct ($ versions )
30- {
31- $ this -> versions = $ versions ;
28+ public function __construct (
29+ public ArrayObject $ versions
30+ ) {
3231 $ this ->filteredVersions = collect ($ versions );
3332 }
3433
35- public function get ()
34+ public function get (): Collection
3635 {
3736 return $ this ->filteredVersions ;
3837 }
3938
40- public function orderByReleaseDate ()
39+ public function orderByReleaseDate (): static
4140 {
4241 $ this ->filteredVersions = $ this ->filteredVersions ->sort (function (Version $ versionA , Version $ versionB ) {
4342 if (!$ versionA ->releaseDate ) {
@@ -57,61 +56,91 @@ public function orderByReleaseDate()
5756 return $ this ;
5857 }
5958
60- public function released ()
59+ public function released (): static
6160 {
6261 $ this ->filterVersions (true , null , null );
6362
6463 return $ this ;
6564 }
6665
67- public function unreleased ()
66+ private function filterVersions ($ released , $ archived , $ overdue ): static
67+ {
68+ $ this ->filteredVersions = $ this ->filteredVersions ->reject (function (Version $ version ) use (
69+ $ released ,
70+ $ archived ,
71+ $ overdue
72+ ) {
73+ if (!is_null ($ released ) && $ version ->released != $ released ) {
74+ return true ;
75+ }
76+
77+ if (!is_null ($ archived ) && $ version ->archived != $ archived ) {
78+ return true ;
79+ }
80+
81+ if (!is_null ($ overdue ) && $ version ->overdue != $ overdue ) {
82+ return true ;
83+ }
84+
85+ // if (!$version->releaseDate) {
86+ // return true;
87+ // }
88+ //
89+ // return Carbon::now()->gt(Carbon::instance($version->releaseDate));
90+ return false ;
91+ });
92+
93+ return $ this ;
94+ }
95+
96+ public function unreleased (): static
6897 {
6998 $ this ->filterVersions (false , null , null );
7099
71100 return $ this ;
72101 }
73102
74- public function archived ()
103+ public function archived (): static
75104 {
76105 $ this ->filterVersions (null , true , null );
77106
78107 return $ this ;
79108 }
80109
81- public function unarchived ()
110+ public function unarchived (): static
82111 {
83112 $ this ->filterVersions (null , false , null );
84113
85114 return $ this ;
86115 }
87116
88- public function overdue ()
117+ public function overdue (): static
89118 {
90119 $ this ->filterVersions (null , true , true );
91120
92121 return $ this ;
93122 }
94123
95- public function notOverdue ()
124+ public function notOverdue (): static
96125 {
97126 $ this ->filterVersions (null , false , false );
98127
99128 return $ this ;
100129 }
101130
102- public function withTicketInformation (int $ verbosityLevel = OutputInterface::VERBOSITY_NORMAL )
131+ public function withTicketInformation (int $ verbosityLevel = OutputInterface::VERBOSITY_NORMAL ): static
103132 {
104- $ issueService = new IssueService ();
133+ $ this ->filteredVersions ->transform (function ($ version ) use ($ verbosityLevel ) {
134+ $ issueService = new IssueService ();
105135
106- $ this ->filteredVersions ->transform (function ($ version ) use ($ issueService , $ verbosityLevel ) {
107136 if ($ verbosityLevel >= OutputInterface::VERBOSITY_VERY_VERBOSE ) {
108137 if ($ version ->archived ) {
109- Log::debug ("- Skipping ticket informations for milestone { $ version ->name } # $ version ->id " );
138+ Log::debug ("- Skipping ticket informations for milestone $ version ->name # $ version ->id " );
110139
111140 return $ version ;
112141 }
113142
114- Log::debug ("- Updating milestone { $ version ->name } # $ version ->id " );
143+ Log::debug ("- Updating milestone $ version ->name # $ version ->id " );
115144 }
116145
117146 $ searchResult = $ issueService ->search ('fixVersion = ' .$ version ->id , 0 , 500 );
@@ -164,8 +193,8 @@ public function withTicketInformation(int $verbosityLevel = OutputInterface::VER
164193 ] : null ,
165194 'created ' => $ issue ->fields ->created ? Carbon::instance ($ issue ->fields ->created ) : null ,
166195 'updated ' => $ issue ->fields ->updated ? Carbon::instance ($ issue ->fields ->updated ) : null ,
167- 'description ' => $ issue ->fields ->description ,
168- 'priority ' => $ issue ->fields ->priority ? $ issue -> fields -> priority -> name : null ,
196+ 'description ' => $ issue ->fields ->description ?? null ,
197+ 'priority ' => $ issue ->fields ->priority ?-> name,
169198 'assignee ' => $ issue ->fields ->assignee ? [
170199 'id ' => $ issue ->fields ->assignee ->accountId ,
171200 'display_name ' => $ issue ->fields ->assignee ->displayName ,
@@ -197,31 +226,4 @@ public function withTicketInformation(int $verbosityLevel = OutputInterface::VER
197226
198227 return $ this ;
199228 }
200-
201- private function filterVersions ($ released , $ archived , $ overdue )
202- {
203- $ this ->filteredVersions = $ this ->filteredVersions ->reject (function (Version $ version ) use (
204- $ released ,
205- $ archived ,
206- $ overdue
207- ) {
208- if (!is_null ($ released ) && $ version ->released != $ released ) {
209- return true ;
210- }
211-
212- if (!is_null ($ archived ) && $ version ->archived != $ archived ) {
213- return true ;
214- }
215-
216- if (!is_null ($ overdue ) && $ version ->overdue != $ overdue ) {
217- return true ;
218- }
219-
220- // if (!$version->releaseDate) {
221- // return true;
222- // }
223- //
224- // return Carbon::now()->gt(Carbon::instance($version->releaseDate));
225- });
226- }
227229}
0 commit comments