Skip to content

Commit

Permalink
Add type declarations to ErrorHandler
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed May 1, 2018
1 parent 7caf905 commit 8d74d36
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions libraries/classes/ErrorHandler.php
Expand Up @@ -97,7 +97,7 @@ public function __destruct()
*
* @return void
*/
public function setHideLocation($hide)
public function setHideLocation(bool $hide): void
{
$this->hide_location = $hide;
}
Expand All @@ -109,7 +109,7 @@ public function setHideLocation($hide)
*
* @return Error[]
*/
public function getErrors($check=true)
public function getErrors(bool $check = true): array
{
if ($check) {
$this->checkSavedErrors();
Expand All @@ -123,7 +123,7 @@ public function getErrors($check=true)
*
* @return Error[]
*/
public function getCurrentErrors()
public function getCurrentErrors(): array
{
return $this->errors;
}
Expand All @@ -135,7 +135,7 @@ public function getCurrentErrors()
*
* @return Error[]
*/
public function sliceErrors($count)
public function sliceErrors(int $count): array
{
$errors = $this->getErrors(false);
$this->errors = array_splice($errors, 0, $count);
Expand All @@ -155,8 +155,12 @@ public function sliceErrors($count)
*
* @return void
*/
public function handleError($errno, $errstr, $errfile, $errline)
{
public function handleError(
int $errno,
string $errstr,
string $errfile,
int $errline
): void {
/**
* Check if Error Control Operator (@) was used, but still show
* user errors even in this case.
Expand Down Expand Up @@ -189,8 +193,13 @@ public function handleError($errno, $errstr, $errfile, $errline)
*
* @return void
*/
public function addError($errstr, $errno, $errfile, $errline, $escape = true)
{
public function addError(
string $errstr,
int $errno,
string $errfile,
int $errline,
bool $escape = true
): void {
if ($escape) {
$errstr = htmlspecialchars($errstr);
}
Expand Down Expand Up @@ -242,7 +251,7 @@ public function addError($errstr, $errno, $errfile, $errline, $escape = true)
*
* @return void
*/
public function triggerError($errorInfo, $errorNumber = null)
public function triggerError(string $errorInfo, ?int $errorNumber = null): void
{
// we could also extract file and line from backtrace
// and call handleError() directly
Expand All @@ -256,7 +265,7 @@ public function triggerError($errorInfo, $errorNumber = null)
*
* @return void
*/
protected function dispFatalError($error)
protected function dispFatalError(Error $error): void
{
if (! headers_sent()) {
$this->dispPageStart($error);
Expand All @@ -271,7 +280,7 @@ protected function dispFatalError($error)
*
* @return void
*/
public function dispUserErrors()
public function dispUserErrors(): void
{
echo $this->getDispUserErrors();
}
Expand All @@ -281,7 +290,7 @@ public function dispUserErrors()
*
* @return string
*/
public function getDispUserErrors()
public function getDispUserErrors(): string
{
$retval = '';
foreach ($this->getErrors() as $error) {
Expand All @@ -299,7 +308,7 @@ public function getDispUserErrors()
*
* @return void
*/
protected function dispPageStart($error = null)
protected function dispPageStart(?Error $error = null): void
{
Response::getInstance()->disable();
echo '<html><head><title>';
Expand All @@ -316,7 +325,7 @@ protected function dispPageStart($error = null)
*
* @return void
*/
protected function dispPageEnd()
protected function dispPageEnd(): void
{
echo '</body></html>';
}
Expand All @@ -326,7 +335,7 @@ protected function dispPageEnd()
*
* @return string
*/
public function getDispErrors()
public function getDispErrors(): string
{
$retval = '';
// display errors if SendErrorReports is set to 'ask'.
Expand Down Expand Up @@ -384,7 +393,7 @@ public function getDispErrors()
*
* @return void
*/
public function dispErrors()
public function dispErrors(): void
{
echo $this->getDispErrors();
}
Expand All @@ -394,7 +403,7 @@ public function dispErrors()
*
* @return void
*/
protected function checkSavedErrors()
protected function checkSavedErrors(): void
{
if (isset($_SESSION['errors'])) {

Expand All @@ -418,7 +427,7 @@ protected function checkSavedErrors()
*
* @return integer number of errors occurred
*/
public function countErrors($check=true)
public function countErrors(bool $check = true): int
{
return count($this->getErrors($check));
}
Expand All @@ -428,7 +437,7 @@ public function countErrors($check=true)
*
* @return integer number of user errors occurred
*/
public function countUserErrors()
public function countUserErrors(): int
{
$count = 0;
if ($this->countErrors()) {
Expand All @@ -447,7 +456,7 @@ public function countUserErrors()
*
* @return boolean
*/
public function hasUserErrors()
public function hasUserErrors(): bool
{
return (bool) $this->countUserErrors();
}
Expand All @@ -457,7 +466,7 @@ public function hasUserErrors()
*
* @return boolean
*/
public function hasErrors()
public function hasErrors(): bool
{
return (bool) $this->countErrors();
}
Expand All @@ -467,7 +476,7 @@ public function hasErrors()
*
* @return integer number of errors to be displayed
*/
public function countDisplayErrors()
public function countDisplayErrors(): int
{
if ($GLOBALS['cfg']['SendErrorReports'] != 'never') {
return $this->countErrors();
Expand All @@ -481,7 +490,7 @@ public function countDisplayErrors()
*
* @return boolean
*/
public function hasDisplayErrors()
public function hasDisplayErrors(): bool
{
return (bool) $this->countDisplayErrors();
}
Expand All @@ -493,7 +502,7 @@ public function hasDisplayErrors()
*
* @return void
*/
public function savePreviousErrors()
public function savePreviousErrors(): void
{
unset($_SESSION['prev_errors']);
$_SESSION['prev_errors'] = $GLOBALS['error_handler']->getCurrentErrors();
Expand All @@ -508,7 +517,7 @@ public function savePreviousErrors()
*
*@return boolean true if there are errors to be "prompted", false otherwise
*/
public function hasErrorsForPrompt()
public function hasErrorsForPrompt(): bool
{
return (
$GLOBALS['cfg']['SendErrorReports'] != 'never'
Expand All @@ -523,7 +532,7 @@ public function hasErrorsForPrompt()
*
* @return void
*/
public function reportErrors()
public function reportErrors(): void
{
// if there're no actual errors,
if (!$this->hasErrors()
Expand Down

0 comments on commit 8d74d36

Please sign in to comment.