InvalidTypeExceptionTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getException() 0 11 4
1
<?php
2
3
namespace ElasticsearchModule\Service;
4
5
use Exception;
6
7
/**
8
 * @author Pedro Alves <[email protected]>
9
 */
10
trait InvalidTypeExceptionTrait
11
{
12
    /**
13
     * @param string $name
14
     * @param string $classNameOrType
15
     * @param string $exceptionClass
16
     * @param mixed $var
17
     * @return Exception
18
     */
19 6
    private function getException($name, $classNameOrType, $exceptionClass, $var)
20
    {
21 6
        $message = (class_exists($classNameOrType) || interface_exists($classNameOrType)) ?
22 6
            "instance of %s" : "%s";
23 6
        return new $exceptionClass(sprintf(
24 6
            "The %s must be $message, %s given",
25 6
            $name,
26 6
            $classNameOrType,
27 6
            is_object($var) ? get_class($var) : gettype($var)
28 6
        ));
29
    }
30
}
31