Skip to content

Commit

Permalink
[#431] Fix PHP warnings.
Browse files Browse the repository at this point in the history
* Undefined index: format
* Undefined index: pid
* Undefined index: sid (twice)
* Undefined index: PHP_AUTH_USER
* Undefined offset: 0 (twice)
* Undefined variable: results (twice)
* Undefined variable: records (twice)
* Undefined variable: rows
* Undefined variable: stories
* Undefined variable: userLogin
* Undefined variable: userPassword

And other warnings derived from the above.
  • Loading branch information
jaragunde committed Apr 19, 2022
1 parent a4bf9d4 commit a15e88c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 33 deletions.
3 changes: 3 additions & 0 deletions model/dao/ProjectDAO/PostgreSQLProjectDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ public function getById($projectId) {
FROM project LEFT JOIN customer ON project.customerid=customer.id
WHERE project.id={$projectId}";
$result = $this->execute($sql);

if (empty($result))
return NULL;
return $result[0];
}

Expand Down
21 changes: 9 additions & 12 deletions model/dao/TaskDAO/PostgreSQLTaskDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,13 @@ public function getGlobalTaskReport(DateTime $initDate = NULL, DateTime $endDate

if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());

if(pg_num_rows($res) > 0) {
for($i = 0; $i < pg_num_rows($res); $i++)
{
$rows[$i] = @pg_fetch_array($res);
}
$rows = array();
for($i = 0; $i < pg_num_rows($res); $i++)
{
$rows[$i] = @pg_fetch_array($res);
}

return $rows;

return $rows;
}

/** Weekly hours worked on project by users for PostgreSQL
Expand Down Expand Up @@ -496,11 +494,10 @@ public function getProjectUserWeeklyWorkingHours(ProjectVO $projectVO, DateTime

if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());

if(pg_num_rows($res) > 0) {
for($i = 0; $i < pg_num_rows($res); $i++)
{
$rows[$i] = @pg_fetch_array($res);
}
$rows = array();
for($i = 0; $i < pg_num_rows($res); $i++)
{
$rows[$i] = @pg_fetch_array($res);
}

return $rows;
Expand Down
2 changes: 1 addition & 1 deletion model/dao/UserDAO/PostgreSQLUserDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function login($userLogin, $userPassword) {

$result = $this->execute($sql);

if (!is_null($result[0]))
if (isset($result[0]))
{
// We normally won't want to retrieve md5 password
$result[0]->setPassword($userPassword);
Expand Down
7 changes: 1 addition & 6 deletions model/facade/action/GetProjectUserCustomerReportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,19 @@ public function __construct(ProjectVO $projectVO, DateTime $init = NULL, DateTim
* as second level one.
*/
protected function doExecute() {
$results = array();

$dao = DAOFactory::getTaskDAO();

$dao2 = DAOFactory::getUserDAO();

$doubleResults = $dao->getTaskReport($this->projectVO, $this->init, $this->end, "USER");

foreach ($doubleResults as $doubleResult)
{

$user = $dao2->getById($doubleResult['usrid']);

$results[$user->getLogin()] = $doubleResult['add_hours'];

}

return $results;

}

}
Expand Down
7 changes: 1 addition & 6 deletions model/facade/action/GetProjectUserStoryReportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,19 @@ public function __construct(ProjectVO $projectVO, DateTime $init = NULL, DateTim
* as second level one.
*/
protected function doExecute() {
$results = array();

$dao = DAOFactory::getTaskDAO();

$dao2 = DAOFactory::getUserDAO();

$doubleResults = $dao->getTaskReport($this->projectVO, $this->init, $this->end, "STORY", "USER");

foreach ($doubleResults as $doubleResult)
{

$user = $dao2->getById($doubleResult['usrid']);

$results[$user->getLogin()][$doubleResult['story']] = $doubleResult['add_hours'];

}

return $results;

}

}
Expand Down
2 changes: 1 addition & 1 deletion web/projectsEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

define('PHPREPORT_ROOT', __DIR__ . '/../');

$sid = $_GET["sid"];
$sid = $_GET["sid"] ?? NULL;

/* We check authentication and authorization */
require_once(PHPREPORT_ROOT . '/web/auth.php');
Expand Down
4 changes: 2 additions & 2 deletions web/services/getProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
include_once(PHPREPORT_ROOT . '/web/services/WebServicesFunctions.php');
include_once(PHPREPORT_ROOT . '/model/facade/ProjectsFacade.php');

$projectId = $_GET['pid'];
$projectId = $_GET['pid'] ?? NULL;

$sid = $_GET['sid'];
$sid = $_GET['sid'] ?? NULL;

do {
/* We check authentication and authorization */
Expand Down
2 changes: 2 additions & 0 deletions web/services/getProjectUserCustomerReportJsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@

$totalHours['total'] = 0;

$records = array();

foreach((array) $report as $login => $hours)
{
$record = array();
Expand Down
5 changes: 4 additions & 1 deletion web/services/getProjectUserStoryReportJsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@

$totalHours['total'] = 0;

$records = array();
$stories = array();

foreach((array) $report as $login => $report2)
{
$count += count($report2);
Expand Down Expand Up @@ -176,7 +179,7 @@

$field['type'] = "float";

foreach((array)$stories as $name => $dumber)
foreach($stories as $name => $dumber)
{
$field['name'] = str_replace('.', ',', $name);
$metaData['fields'][] = $field;
Expand Down
4 changes: 1 addition & 3 deletions web/services/getProjectUserWeeklyHoursReportJsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}

// CSV formatter
if($_GET["format"] && $_GET["format"] == "csv")
if(isset($_GET["format"]) && $_GET["format"] == "csv")
{
// output headers so that the file is downloaded rather than displayed
header('Content-type: text/csv');
Expand Down Expand Up @@ -214,5 +214,3 @@

// output correctly formatted Json
echo $json;


4 changes: 3 additions & 1 deletion web/services/loginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
include_once(PHPREPORT_ROOT . '/model/vo/UserVO.php');

/* Allow login only via HTTP Authentication data only if both username and password are not empty*/
if (!$_SERVER['PHP_AUTH_USER'] || !$_SERVER['PHP_AUTH_PW']) {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="phpeport Authentication"');
header('HTTP/1.0 401 Unauthorized');
http_response_code(401);
$userLogin = false;
$userPassword = false;
} else {
$userLogin = $_SERVER['PHP_AUTH_USER'];
$userPassword = $_SERVER['PHP_AUTH_PW'];
Expand Down

0 comments on commit a15e88c

Please sign in to comment.