Passed
Pull Request — master (#12)
by Pedro
02:48
created

InvalidTypeExceptionTrait::getException()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 1
nop 4
crap 2
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 $className
15
     * @param string $exceptionClass
16
     * @param mixed $var
17
     * @return Exception
18
     */
19 5
    private function getException($name, $className, $exceptionClass, $var)
20
    {
21 5
        return new $exceptionClass(sprintf(
22 5
            "The %s must be instance of %s, %s given",
23 5
            $name,
24 5
            $className,
25 5
            is_object($var) ? get_class($var) : gettype($var)
26 5
        ));
27
    }
28
}
29