From 2a512ce5452e27dbf5d541d9630b8ed02e624e79 Mon Sep 17 00:00:00 2001 From: Dmytro Lytvynchuk Date: Fri, 13 Mar 2026 16:30:27 +0200 Subject: [PATCH 1/3] Add PaginatedResult class and getProjectsPaginated method --- src/Project/PaginatedResult.php | 166 ++++++++++++++++++++++++++++++++ src/Project/ProjectService.php | 29 ++++++ tests/ProjectTest.php | 26 +++++ 3 files changed, 221 insertions(+) create mode 100644 src/Project/PaginatedResult.php diff --git a/src/Project/PaginatedResult.php b/src/Project/PaginatedResult.php new file mode 100644 index 0000000..5adb8d9 --- /dev/null +++ b/src/Project/PaginatedResult.php @@ -0,0 +1,166 @@ +startAt; + } + + /** + * @param int $startAt + */ + public function setStartAt($startAt) + { + $this->startAt = $startAt; + } + + /** + * @return int + */ + public function getMaxResults() + { + return $this->maxResults; + } + + /** + * @param int $maxResults + */ + public function setMaxResults($maxResults) + { + $this->maxResults = $maxResults; + } + + /** + * @return string + */ + public function getNextPage() + { + return $this->nextPage; + } + + /** + * @param string $nextPage + */ + public function setNextPage($nextPage) + { + $this->nextPage = $nextPage; + } + + /** + * @return string + */ + public function getSelf() + { + return $this->self; + } + + /** + * @param int $nextPage + */ + public function setSelf($self) + { + $this->self = $self; + } + + /** + * @return int + */ + public function getTotal() + { + return $this->total; + } + + /** + * @param int $total + */ + public function setTotal($total) + { + $this->total = $total; + } + + /** + * @return array + */ + public function getValues() + { + return $this->values; + } + + /** + * @param array $values + */ + public function setValues($values) + { + $this->values = $values; + } + + /** + * @param int $index + * + * @return mixed + */ + public function getValue($index) + { + return $this->values[$index]; + } + + /** + * @param bool $isLast + */ + public function setIsLast($isLast) + { + $this->isLast = $isLast; + } + + /** + * @return bool + */ + public function getIsLast() + { + return $this->isLast; + } +} diff --git a/src/Project/ProjectService.php b/src/Project/ProjectService.php index c385dbd..c437436 100644 --- a/src/Project/ProjectService.php +++ b/src/Project/ProjectService.php @@ -35,6 +35,35 @@ public function getAllProjects($paramArray = []) return $prjs; } + /** + * get a paginated list of projects. + * + * @param array $paramArray + * + * @throws \JiraCloud\JiraException + * + * @return PaginatedResult + */ + public function getProjectsPaginated($paramArray = []): PaginatedResult + { + $ret = $this->exec($this->uri . '/search' . $this->toHttpQueryParameter($paramArray), null); + + $decodedRet = json_decode($ret, false); + + $decodedRet->values = $this->json_mapper->mapArray( + $decodedRet->values, + new \ArrayObject(), + Project::class + ); + + $prjsPag = $this->json_mapper->map( + $decodedRet, + new PaginatedResult + ); + + return $prjsPag; + } + /** * get Project id By Project Key. * throws HTTPException if the project is not found, or the calling user does not have permission or view it. diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php index 0cf2203..6bc744e 100644 --- a/tests/ProjectTest.php +++ b/tests/ProjectTest.php @@ -39,6 +39,32 @@ public function get_project_lists() : string return $projKey; } + + /** + * @test + * + */ + public function get_project_paginated_lists() : string + { + $projKey = 'TEST'; + try { + $proj = new ProjectService(); + + $prjsPag = $proj->getProjectsPaginated(); + + foreach ($prjsPag->values as $p) { + $this->assertTrue($p instanceof Project); + $this->assertTrue(strlen($p->key) > 0); + $this->assertTrue(!empty($p->id)); + $this->assertTrue(strlen($p->name) > 0); + } + } catch (\Exception $e) { + $this->fail('get_project_paginated_lists ' . $e->getMessage()); + } + + return $projKey; + } + /** * @test * @depends get_project_lists From a3f1b68f827b89ef43663277ed6713f48e4e371c Mon Sep 17 00:00:00 2001 From: Dmytro Lytvynchuk Date: Fri, 13 Mar 2026 16:37:23 +0200 Subject: [PATCH 2/3] Improve code formatting in ProjectService.php --- src/Project/ProjectService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Project/ProjectService.php b/src/Project/ProjectService.php index c437436..6d0cdfe 100644 --- a/src/Project/ProjectService.php +++ b/src/Project/ProjectService.php @@ -46,7 +46,7 @@ public function getAllProjects($paramArray = []) */ public function getProjectsPaginated($paramArray = []): PaginatedResult { - $ret = $this->exec($this->uri . '/search' . $this->toHttpQueryParameter($paramArray), null); + $ret = $this->exec($this->uri.'/search'.$this->toHttpQueryParameter($paramArray), null); $decodedRet = json_decode($ret, false); @@ -58,7 +58,7 @@ public function getProjectsPaginated($paramArray = []): PaginatedResult $prjsPag = $this->json_mapper->map( $decodedRet, - new PaginatedResult + new PaginatedResult() ); return $prjsPag; From 3b34dcf1206acb9b19bf36fb8bad81a2bc415c60 Mon Sep 17 00:00:00 2001 From: Dmytro Lytvynchuk Date: Fri, 13 Mar 2026 16:52:48 +0200 Subject: [PATCH 3/3] Update setSelf method parameter to string type --- src/Project/PaginatedResult.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Project/PaginatedResult.php b/src/Project/PaginatedResult.php index 5adb8d9..602bf0a 100644 --- a/src/Project/PaginatedResult.php +++ b/src/Project/PaginatedResult.php @@ -99,7 +99,7 @@ public function getSelf() } /** - * @param int $nextPage + * @param string $self */ public function setSelf($self) {