Completed
Pull Request — master (#1358)
by Guilh
07:06
created

ClassMapHandlerTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 25
ccs 7
cts 8
cp 0.875
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B resolveValue() 0 14 5
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Util;
13
14
/**
15
 * @author Ener-Getick <[email protected]>
16
 *
17
 * @internal do not use this trait or its functions in your code.
18
 */
19
trait ClassMapHandlerTrait
20
{
21
    /**
22
     * Resolves the value corresponding to a class from an array.
23
     *
24
     * @param string $class
25
     * @param array  $map
26
     *
27
     * @return mixed|false if not found
28
     */
29 4
    public function resolveValue($class, array $map)
30
    {
31 4
        foreach ($map as $mapClass => $value) {
32 4
            if (!$value) {
33
                continue;
34
            }
35
36 4
            if ($class === $mapClass || is_subclass_of($class, $mapClass)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $mapClass can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
37 4
                return $value;
38
            }
39 4
        }
40
41 4
        return false;
42
    }
43
}
44