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

ClassMapHandlerTrait::resolveValue()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.0488

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 8.8571
cc 5
eloc 7
nc 4
nop 2
crap 5.0488
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