Skip to content

Commit fe5044c

Browse files
committed
Avoid PHP notice when searching for a project name that does not exist
Fixes kanboard#5383
1 parent 61144fd commit fe5044c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

app/Api/Procedure/ProjectProcedure.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,35 @@ public function getProjectById($project_id)
2222
public function getProjectByName($name)
2323
{
2424
$project = $this->projectModel->getByName($name);
25+
26+
if (empty($project)) {
27+
return false;
28+
}
29+
2530
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByName', $project['id']);
2631
return $this->projectApiFormatter->withProject($project)->format();
2732
}
2833

2934
public function getProjectByIdentifier($identifier)
3035
{
3136
$project = $this->projectModel->getByIdentifier($identifier);
37+
38+
if (empty($project)) {
39+
return false;
40+
}
41+
3242
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByIdentifier', $project['id']);
3343
return $this->projectApiFormatter->withProject($project)->format();
3444
}
3545

3646
public function getProjectByEmail($email)
3747
{
3848
$project = $this->projectModel->getByEmail($email);
49+
50+
if (empty($project)) {
51+
return false;
52+
}
53+
3954
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByEmail', $project['id']);
4055
return $this->projectApiFormatter->withProject($project)->format();
4156
}

tests/integration/ProjectProcedureTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function testAll()
1111
$this->assertCreateTeamProject();
1212
$this->assertGetProjectById();
1313
$this->assertGetProjectByName();
14+
$this->assertGetInexistingProjectByName();
1415
$this->assertGetAllProjects();
1516
$this->assertUpdateProject();
1617
$this->assertUpdateProjectIdentifier();
@@ -42,6 +43,12 @@ public function assertGetProjectByName()
4243
$this->assertEquals('Description', $project['description']);
4344
}
4445

46+
public function assertGetInexistingProjectByName()
47+
{
48+
$project = $this->app->getProjectByName('inexisting project');
49+
$this->assertFalse($project);
50+
}
51+
4552
public function assertGetAllProjects()
4653
{
4754
$projects = $this->app->getAllProjects();

0 commit comments

Comments
 (0)