Completed
Push — master ( 4568c2...6bb1b7 )
by Théo
03:18
created

Reflector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isClassInternal() 0 8 2
A isFunctionInternal() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper;
16
17
use ReflectionException;
18
use ReflectionFunction;
19
use Roave\BetterReflection\Reflector\ClassReflector;
20
use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound;
21
use Roave\BetterReflection\Reflector\FunctionReflector;
22
23
final class Reflector
24
{
25
    private $classReflector;
26
    private $functionReflector;
27
28 346
    public function __construct(ClassReflector $classReflector, FunctionReflector $functionReflector)
29
    {
30 346
        $this->classReflector = $classReflector;
31 346
        $this->functionReflector = $functionReflector;
32
    }
33
34 200
    public function isClassInternal(string $name): bool
35
    {
36
        try {
37 200
            return $this->classReflector->reflect($name)->isInternal();
38 3
        } catch (IdentifierNotFound $exception) {
39 3
            return false;
40
        }
41
    }
42
43 92
    public function isFunctionInternal(string $name): bool
44
    {
45
        try {
46 92
            return (new ReflectionFunction($name))->isInternal();
47
48
            // TODO: leverage Better Reflection instead
49
            return $this->functionReflector->reflect($name)->isInternal();
0 ignored issues
show
Unused Code introduced by
return $this->functionRe...t($name)->isInternal(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
50 30
        } catch (ReflectionException $exception) {
51 30
            return false;
52
        }
53
    }
54
}
55