Skip to content

Commit

Permalink
Merge pull request #14604 from jeabakker/features
Browse files Browse the repository at this point in the history
chore(core): scrutinizer issues
  • Loading branch information
jeabakker committed Apr 18, 2024
2 parents 932b9c3 + 94ba070 commit 2b18495
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/guides/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ You can add custom handlers (see Monolog_ documentation for a full list of handl
'admin@example.com',
'Critical error',
'no-reply@mysite.com',
\Monolog\Logger::CRITICAL
\Monolog\Level::Critical
)
);
12 changes: 6 additions & 6 deletions engine/classes/Elgg/Cli/ErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Elgg\Cli;

use Elgg\Logger\ElggLogFormatter;
use Monolog\Logger;
use Monolog\Level;
use Monolog\LogRecord;
use Symfony\Component\Console\Helper\FormatterHelper;

Expand All @@ -23,14 +23,14 @@ public function format(LogRecord $record): string {
$formatter = new FormatterHelper();

switch ($record->level->value) {
case Logger::EMERGENCY:
case Logger::CRITICAL:
case Logger::ALERT:
case Logger::ERROR:
case Level::Emergency:
case Level::Critical:
case Level::Alert:
case Level::Error:
$style = 'error';
break;

case Logger::WARNING:
case Level::Warning:
$style = 'comment';
break;

Expand Down
11 changes: 6 additions & 5 deletions engine/classes/Elgg/Cli/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Elgg\Logger;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Level;
use Monolog\LogRecord;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -19,10 +20,10 @@ class ErrorHandler extends AbstractProcessingHandler {

const VERBOSITY_LEVEL_MAP = [
OutputInterface::VERBOSITY_QUIET => Logger::OFF,
OutputInterface::VERBOSITY_NORMAL => Logger::WARNING,
OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE,
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
OutputInterface::VERBOSITY_NORMAL => Level::Warning,
OutputInterface::VERBOSITY_VERBOSE => Level::Notice,
OutputInterface::VERBOSITY_VERY_VERBOSE => Level::Info,
OutputInterface::VERBOSITY_DEBUG => Level::Debug,
];

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __construct(
* {@inheritdoc}
*/
public function write(LogRecord $record): void {
$stream = $record->level->value >= Logger::ERROR ? $this->stderr : $this->stdout;
$stream = $record->level->value >= Level::Error ? $this->stderr : $this->stdout;

$stream->write($record->formatted, true);

Expand Down
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function insertData(QueryBuilder $query): int {
*
* @return bool|int
*/
public function updateData(QueryBuilder $query, bool $get_num_rows = false) {
public function updateData(QueryBuilder $query, bool $get_num_rows = false): bool|int {
$params = $query->getParameters();
$sql = $query->getSQL();

Expand All @@ -271,7 +271,7 @@ public function updateData(QueryBuilder $query, bool $get_num_rows = false) {
return true;
}

return ($result instanceof Result) ? $result->rowCount() : $result;
return ($result instanceof Result) ? (int) $result->rowCount() : $result;
}

/**
Expand All @@ -292,7 +292,7 @@ public function deleteData(QueryBuilder $query): int {
$this->query_cache->clear();

$result = $this->executeQuery($query);
return ($result instanceof Result) ? $result->rowCount() : $result;
return ($result instanceof Result) ? (int) $result->rowCount() : $result;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion engine/classes/Elgg/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function prefix(string $table): string {
* @return string
*/
public function getTableName(): string {
return $this->table_name;
return (string) $this->table_name;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion engine/classes/Elgg/Di/InternalContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function initConfig(Config $config): Config {
* {@inheritDoc}
*/
public static function factory(array $options = []) {
$container = parent::factory($options);
$container = parent::factory();

if (isset($options['config'])) {
$config = $options['config'];
Expand Down
3 changes: 2 additions & 1 deletion engine/classes/Elgg/Logger/BacktraceProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Elgg\Logger;

use Elgg\Logger;
use Monolog\Level;
use Monolog\LogRecord;

/**
Expand All @@ -20,7 +21,7 @@ class BacktraceProcessor {
* @param int $level Logging level
* @param int $backtrace_level Backtrance level (-1 for all)
*/
public function __construct($level = Logger::WARNING, $backtrace_level = -1) {
public function __construct($level = Level::Warning, $backtrace_level = -1) {
$this->level = Logger::toMonologLevel($level);
$this->backtrace_level = $backtrace_level;
}
Expand Down
2 changes: 1 addition & 1 deletion mod/developers/classes/Elgg/Developers/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function processSettings(): void {
$handler = new \Monolog\Handler\RotatingFileHandler(
elgg_sanitize_path(elgg_get_data_path() . 'logs/html/errors.html', false),
elgg_extract('error_log_max_files', $settings, 60),
\Monolog\Logger::ERROR
\Monolog\Level::Error
);

$formatter = new \Elgg\Developers\ErrorLogHtmlFormatter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function tables(): array {
*/
protected function optimizeTable(string $table): int {
$result = $this->db->getConnection('write')->executeQuery("OPTIMIZE TABLE {$table}");
return $result->rowCount();
return (int) $result->rowCount();
}

/**
Expand Down

0 comments on commit 2b18495

Please sign in to comment.