MessageValidatorTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateMessage() 0 11 4
1
<?php
2
3
namespace SubjectivePHP\Psr\Log;
4
5
use Psr\Log\InvalidArgumentException;
6
7
/**
8
 * Trait for validating PSR-3 log messages.
9
 */
10
trait MessageValidatorTrait
11
{
12
    /**
13
     * Determines if the specified message is legal under PSR-3.
14
     *
15
     * @param mixed $message The message to validate.
16
     *
17
     * @return void
18
     *
19
     * @throws InvalidArgumentException Throw if $message is not a know RFC-5424 message.
20
     */
21
    protected function validateMessage($message)
22
    {
23
        if (is_scalar($message)) {
24
            return;
25
        }
26
27
        if (is_object($message) && method_exists($message, '__toString')) {
28
            return;
29
        }
30
31
        throw new InvalidArgumentException('Given $message was a valid string value');
32
    }
33
}
34