diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index e1313b47f8..6e592099a5 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -99,7 +99,7 @@ class Application exit; } - public function runEntryPoint($entryPoint, $data = array(), $final = false) + public function runEntryPoint($entryPoint, $data = [], $final = false) { if (empty($entryPoint)) { throw new \Error(); @@ -262,7 +262,7 @@ class Application } $routeOptions = call_user_func($route->getCallable()); - $routeKeys = is_array($routeOptions) ? array_keys($routeOptions) : array(); + $routeKeys = is_array($routeOptions) ? array_keys($routeOptions) : []; if (!in_array('controller', $routeKeys, true)) { return $container->get('output')->render($routeOptions); @@ -328,7 +328,7 @@ class Application continue; } - $currentRoute = $this->getSlim()->$method($route['route'], function() use ($route) { //todo change "use" for php 5.4 + $currentRoute = $this->getSlim()->$method($route['route'], function() use ($route) { return $route['params']; }); @@ -360,7 +360,9 @@ class Application return $_GET['portalId']; } if (!empty($_COOKIE['auth-token'])) { - $token = $this->getContainer()->get('entityManager')->getRepository('AuthToken')->where(array('token' => $_COOKIE['auth-token']))->findOne(); + $token = + $this->getContainer()->get('entityManager') + ->getRepository('AuthToken')->where(['token' => $_COOKIE['auth-token']])->findOne(); if ($token && $token->get('portalId')) { return $token->get('portalId'); diff --git a/application/Espo/Core/Exceptions/BadRequest.php b/application/Espo/Core/Exceptions/BadRequest.php index 0e561c1a44..144979ce75 100644 --- a/application/Espo/Core/Exceptions/BadRequest.php +++ b/application/Espo/Core/Exceptions/BadRequest.php @@ -25,14 +25,11 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Core\Exceptions; class BadRequest extends \Exception { protected $code = 400; - } - - diff --git a/application/Espo/Core/Exceptions/Conflict.php b/application/Espo/Core/Exceptions/Conflict.php index 5af929f76a..2faaf1a0f1 100644 --- a/application/Espo/Core/Exceptions/Conflict.php +++ b/application/Espo/Core/Exceptions/Conflict.php @@ -25,13 +25,11 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Core\Exceptions; class Conflict extends \Exception { protected $code = 409; - } - diff --git a/application/Espo/Core/Exceptions/Error.php b/application/Espo/Core/Exceptions/Error.php index aa5543e9f3..87d66fa9ac 100644 --- a/application/Espo/Core/Exceptions/Error.php +++ b/application/Espo/Core/Exceptions/Error.php @@ -25,7 +25,7 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Core\Exceptions; @@ -33,5 +33,3 @@ class Error extends InternalServerError { } - - diff --git a/application/Espo/Core/Exceptions/Forbidden.php b/application/Espo/Core/Exceptions/Forbidden.php index de39226ce5..6b033f60fe 100644 --- a/application/Espo/Core/Exceptions/Forbidden.php +++ b/application/Espo/Core/Exceptions/Forbidden.php @@ -25,7 +25,7 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Core\Exceptions; @@ -34,5 +34,3 @@ class Forbidden extends \Exception protected $code = 403; } - - diff --git a/application/Espo/Core/Exceptions/InternalServerError.php b/application/Espo/Core/Exceptions/InternalServerError.php index 4163e97c38..e4b2f84b91 100644 --- a/application/Espo/Core/Exceptions/InternalServerError.php +++ b/application/Espo/Core/Exceptions/InternalServerError.php @@ -25,12 +25,11 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Core\Exceptions; class InternalServerError extends \Exception { protected $code = 500; - } diff --git a/application/Espo/Core/Exceptions/NotFound.php b/application/Espo/Core/Exceptions/NotFound.php index 653240a500..79b30b619c 100644 --- a/application/Espo/Core/Exceptions/NotFound.php +++ b/application/Espo/Core/Exceptions/NotFound.php @@ -25,14 +25,11 @@ * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ + ************************************************************************/ namespace Espo\Core\Exceptions; class NotFound extends \Exception { protected $code = 404; - } - - diff --git a/application/Espo/Core/Utils/Api/Output.php b/application/Espo/Core/Utils/Api/Output.php index 36220bb1ab..d7564045b6 100644 --- a/application/Espo/Core/Utils/Api/Output.php +++ b/application/Espo/Core/Utils/Api/Output.php @@ -33,7 +33,7 @@ class Output { private $slim; - protected $errorDesc = [ + protected $errorDescriptions = [ 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', @@ -43,7 +43,7 @@ class Output ]; protected $allowedStatusCodeList = [ - 200, 400, 401, 403, 404, 409, 500 + 200, 201, 400, 401, 403, 404, 409, 500 ]; protected $ignorePrintXStatusReasonExceptionClassNameList = [ @@ -60,11 +60,6 @@ class Output return $this->slim; } - /** - * Output the result - * - * @param mixed $data - JSON - */ public function render($data = null) { if (is_array($data)) { @@ -76,7 +71,7 @@ class Output echo $data; } - public function processError($message = 'Error', $code = 500, $isPrint = false, $exception = null) + public function processError(string $message = 'Error', int $code = 500, bool $toPrint = false, $exception = null) { $currentRoute = $this->getSlim()->router()->getCurrentRoute(); @@ -86,24 +81,16 @@ class Output $GLOBALS['log']->error('API ['.$this->getSlim()->request()->getMethod().']:'.$currentRoute->getPattern().', Params:'.print_r($currentRoute->getParams(), true).', InputData: '.$inputData.' - '.$message); } - $this->displayError($message, $code, $isPrint, $exception); + $this->displayError($message, $code, $toPrint, $exception); } - /** - * Output the error and stop app execution - * - * @param string $text - * @param int $statusCode - * - * @return void - */ - public function displayError($text, $statusCode = 500, $isPrint = false, $exception = null) + public function displayError(string $text, int $statusCode = 500, bool $toPrint = false, $exception = null) { $GLOBALS['log']->error('Display Error: '.$text.', Code: '.$statusCode.' URL: '.$_SERVER['REQUEST_URI']); ob_clean(); - if (!empty( $this->slim)) { + if (!empty($this->slim)) { $toPrintXStatusReason = true; if ($exception && in_array(get_class($exception), $this->ignorePrintXStatusReasonExceptionClassNameList)) { $toPrintXStatusReason = false; @@ -118,8 +105,8 @@ class Output $this->getSlim()->response()->headers->set('X-Status-Reason', $text); } - if ($isPrint) { - $status = $this->getCodeDesc($statusCode); + if ($toPrint) { + $status = $this->getCodeDescription($statusCode); $status = isset($status) ? $statusCode.' '.$status : 'HTTP '.$statusCode; $this->getSlim()->printError($text, $status); } @@ -131,28 +118,15 @@ class Output } } - /** - * Get status code desription - * - * @param int $statusCode - * @return string | null - */ - protected function getCodeDesc($statusCode) + protected function getCodeDescription($statusCode) { - if (isset($this->errorDesc[$statusCode])) { - return $this->errorDesc[$statusCode]; + if (isset($this->errorDescriptions[$statusCode])) { + return $this->errorDescriptions[$statusCode]; } return null; } - /** - * Clear passwords for inputData - * - * @param string $inputData - * - * @return string - */ protected function clearPasswords($inputData) { return preg_replace('/"(.*?password.*?)":".*?"/i', '"$1":"*****"', $inputData);