New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix warnings in case of incorrect data #482
Changes from all commits
5c35779
59ec3bb
5bd158f
e8dc0aa
aa680c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,10 @@ public function __construct($systemName = null, $extraPrefix = null, $contextPre | |
public function format(array $record) | ||
{ | ||
$record = parent::format($record); | ||
if (!$this->isInputValid($record)) | ||
{ | ||
throw new \InvalidArgumentException('Please check keys in input array'); | ||
} | ||
$message = new Message(); | ||
$message | ||
->setTimestamp($record['datetime']) | ||
|
@@ -98,4 +102,24 @@ public function format(array $record) | |
|
||
return $message; | ||
} | ||
|
||
/** | ||
* @param array $input | ||
* @return bool is input valid of not | ||
*/ | ||
private function isInputValid(array $input) | ||
{ | ||
return ( | ||
!empty($input) && | ||
isset($input['datetime']) && | ||
isset($input['message']) && | ||
isset($input['channel']) && | ||
isset($input['level']) && | ||
isset($this->logLevels[$input['level']]) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand the PHP documentation in the right way, this will cause a parse error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually not, at least build machine checks this code and reports that everything is ok. |
||
isset($input['extra']) && | ||
is_array($input['extra']) && | ||
isset($input['context']) && | ||
is_array($input['context']) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a DocBlock here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added