LevelValidatorTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 3
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateLevel() 0 4 3
1
<?php
2
3
namespace SubjectivePHP\Psr\Log;
4
5
use Psr\Log\InvalidArgumentException;
6
7
/**
8
 * Trait for validating PSR-3 log levels.
9
 */
10
trait LevelValidatorTrait
11
{
12
    /**
13
     * Determines if the specified level is legal under PSR-3.
14
     *
15
     * @param mixed $level The level to validate.
16
     *
17
     * @return void
18
     *
19
     * @throws InvalidArgumentException Throw if $level is not a know RFC-5424 level.
20
     */
21
    protected function validateLevel($level)
22
    {
23
        if (!is_string($level) || !defined('\\Psr\\Log\\LogLevel::' . strtoupper($level))) {
24
            throw new InvalidArgumentException('Given $level was not a known LogLevel');
25
        }
26
    }
27
}
28