chore: Apply inspection fixes

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2022-11-19 11:24:35 +01:00
parent 055a1bd4b5
commit 295d6c6ca9
3 changed files with 17 additions and 67 deletions

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2020, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -19,7 +19,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
use SP\Core\Exceptions\SPException;
@@ -45,9 +45,9 @@ const LOG_FORMAT_OWN = '[%s] syspass.%s: logger {"message":"%s","caller":"%s"}'.
* @param mixed $data
* @param string $type
*/
function logger($data, string $type = 'DEBUG')
function logger(mixed $data, string $type = 'DEBUG'): void
{
if (!DEBUG && $type === 'DEBUG') {
if (defined('DEBUG') && !DEBUG && ($type === 'DEBUG')) {
return;
}
@@ -77,14 +77,6 @@ function logger($data, string $type = 'DEBUG')
}
}
/**
* Print last callers from backtrace
*/
function printLastCallers()
{
logger(formatTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
}
/**
* Print last caller from backtrace
*/
@@ -155,7 +147,7 @@ function formatStackTrace(Throwable $e): string
*
* @param \Exception $exception
*/
function processException(Exception $exception)
function processException(Exception $exception): void
{
logger(
sprintf(
@@ -178,35 +170,13 @@ function processException(Exception $exception)
}
}
function formatTrace(array $trace): string
{
$btLine = [];
$i = 0;
foreach ($trace as $caller) {
$class = $caller['class'] ?? '';
$file = $caller['file'] ?? '';
$line = $caller['line'] ?? 0;
$btLine[] = sprintf(
'Caller %d: %s\%s (%s:%d)',
$i,
$class,
$caller['function'],
$file,
$line
);
$i++;
}
return implode(PHP_EOL, $btLine);
}
/**
* Alias gettext function
*
* @param string $message
* @param bool $translate Si es necesario traducir
*
* @return string
*/
function __(string $message, bool $translate = true): string
{
@@ -268,6 +238,10 @@ function getElapsedTime(float $from): float
*/
function initModule(string $module): array
{
if (!defined('MODULES_PATH')) {
return [];
}
logger(sprintf('Initializing module: %s', $module));
$moduleFile = MODULES_PATH.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'module.php';
@@ -286,27 +260,3 @@ function initModule(string $module): array
return [];
}
/**
* @return bool|string
*/
function nDirname($dir, $levels)
{
if (version_compare(PHP_VERSION, '7.0') === -1) {
logger(realpath(dirname($dir).str_repeat('../', $levels)));
return realpath(dirname($dir).str_repeat('../', $levels));
}
return dirname($dir, $levels);
}
/**
* Prints a fancy trace info using Xdebug extension
*/
function printTraceInfo()
{
if (DEBUG && extension_loaded('xdebug')) {
xdebug_print_function_stack();
}
}

View File

@@ -24,7 +24,6 @@
namespace SP\Core\Bootstrap;
use Closure;
use Exception;
use Psr\Container\ContainerExceptionInterface;
@@ -71,6 +70,7 @@ final class BootstrapWeb extends BootstrapBase
$this->router->respond(['GET', 'POST'], '@(?!/api\.php)', $this->manageWebRequest());
}
/** @noinspection PhpInconsistentReturnPointsInspection */
private function manageWebRequest(): Closure
{
return function ($request, $response, $service) {

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -156,10 +156,10 @@ final class LogMessage extends MessageBase
$formatter = new HtmlFormatter();
$message = '<div class="log-message">';
$message .= '<h1>' . $this->action . '</h1>';
$message .= '<div class="log-description">' . $this->getDescription($formatter, true) . '</div>';
$message .= '<div class="log-details">' . $this->getDetails($formatter, true) . '</div>';
$message .= '<footer>' . $this->footer . '</footer>';
$message .= '<h1>'.$this->action.'</h1>';
$message .= '<div class="log-description">'.$this->getDescription($formatter, true).'</div>';
$message .= '<div class="log-details">'.$this->getDetails($formatter, true).'</div>';
$message .= '<footer>'.join('<br/>', $this->footer).'</footer>';
$message .= '</div>';
return $message;