Skip to content

Commit

Permalink
add phpstan tests as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Mitterhauser committed Mar 20, 2024
1 parent 0100be7 commit 111b2ea
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 74 deletions.
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 8
ignoreErrors:
#- message: '#Parameter \#1 \$data of static method kbATeam\\DataProtection\\SecureSearch::encrypt\(\) expects string, int given.#'
# path: tests/SecureSearchTest.php
paths:
- src/
- tests/
19 changes: 12 additions & 7 deletions src/Log/Engine/GraylogLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function __construct($config = [])
*
* @param mixed $level
* @param string $message
* @param array $context
* @param array<mixed> $context
*
* @return void
*
Expand Down Expand Up @@ -259,6 +259,7 @@ protected function createMessage(string $level, string $message): GelfMessage
/**
* Create a debug backtrace.
*/
$trace = null;
if ($add_file_and_line || $append_backtrace) {
$trace = new ClassicBacktrace(
$this->getConfig('trace_level_offset'),
Expand All @@ -270,7 +271,7 @@ protected function createMessage(string $level, string $message): GelfMessage
* In case the log didn't happen in memory (like with reflections), add
* the filename and line to the message.
*/
if ($add_file_and_line && $trace->lastStep('file') !== null) {
if ($add_file_and_line && is_object($trace) && $trace->lastStep('file') !== null) {
$gelfMessage->setAdditional('file', $trace->lastStep('file'));
$gelfMessage->setAdditional('line', $trace->lastStep('line'));
}
Expand All @@ -291,7 +292,7 @@ protected function createMessage(string $level, string $message): GelfMessage
/**
* Append backtrace in case it's not already in the message.
*/
if ($append_backtrace) {
if ($append_backtrace && is_object($trace)) {
/**
* Append backtrace to message.
*/
Expand All @@ -302,9 +303,13 @@ protected function createMessage(string $level, string $message): GelfMessage
/**
* Set function output as additional field.
*/
foreach ($this->getConfig('additional', []) as $key => $function) {
if (is_callable($function)) {
$gelfMessage->setAdditional($key, (string)$function());

$configStack = $this->getConfig('additional', []);
if (is_array($configStack)) {
foreach ($configStack as $key => $function) {
if (is_callable($function) && is_string($key)) {
$gelfMessage->setAdditional($key, (string)$function());
}
}
}

Expand All @@ -321,7 +326,7 @@ protected function createMessage(string $level, string $message): GelfMessage
return $gelfMessage->setShortMessage($shortMessage);
}
return $gelfMessage
->setShortMessage($shortMessage)
->setShortMessage((string)$shortMessage)
->setFullMessage($message);
}
}
Loading

0 comments on commit 111b2ea

Please sign in to comment.