Passed
Branch develop (640e78)
by Herberto
03:54
created

InstanceHelper::getReflectionProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Hgraca\Helper;
3
4
use Hgraca\Helper\Concept\ReflectionHelperAbstract;
5
use ReflectionProperty;
6
7
final class InstanceHelper extends ReflectionHelperAbstract
8
{
9
    /**
10
     * @param mixed $object
11
     *
12
     * @return ReflectionProperty[]
13
     */
14 8
    public static function getReflectionProperties($object): array
15
    {
16 8
        return ClassHelper::getReflectionProperties(get_class($object));
17
    }
18
19
    /**
20
     * @return mixed
21
     */
22 1
    public static function createInstance(string $fqcn, array $constructorArguments = [])
23
    {
24 1
        $reflectionClass = self::getReflectionClass($fqcn);
25
26 1
        return $reflectionClass->newInstanceArgs($constructorArguments);
27
    }
28
29
    /**
30
     * @return mixed
31
     */
32 3
    public static function createInstanceWithoutConstructor(string $fqcn)
33
    {
34 3
        $reflectionClass = self::getReflectionClass($fqcn);
35
36 3
        return $reflectionClass->newInstanceWithoutConstructor();
37
    }
38
39 3 View Code Duplication
    public static function setProtectedProperty($object, string $propertyName, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 3
        $class = self::getReflectionClass(get_class($object));
42
43 3
        $property = ClassHelper::getReflectionProperty($class, $propertyName);
44 2
        $property->setAccessible(true);
45 2
        $property->setValue($object, $value);
46 2
    }
47
48 3 View Code Duplication
    public static function getProtectedProperty($object, string $propertyName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50 3
        $class = self::getReflectionClass(get_class($object));
51
52 3
        $property = ClassHelper::getReflectionProperty($class, $propertyName);
53 2
        $property->setAccessible(true);
54
55 2
        return $property->getValue($object);
56
    }
57
}
58