Completed
Branch master (f8a0b6)
by Arnold
06:06
created

class_functions.php ➔ get_private_property()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 2
b 0
f 1
nc 2
nop 2
dl 11
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
1
<?php
2
3
namespace Jasny;
4
5
/**
6
 * Get the value of a private or protected property
7
 * 
8
 * @param object $object
9
 * @param string $property
10
 * @return mixed
11
 */
12 View Code Duplication
function get_private_property($object, $property)
1 ignored issue
show
Duplication introduced by
This function 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...
13
{
14 4
    $reflObj = is_object($object) ?
15 4
        new \ReflectionObject($object) :
16 4
        new \ReflectionClass($object);
17
18 4
    $reflProp = $reflObj->getProperty($property);
19 2
    $reflProp->setAccessible(true);
20
21 2
    return $reflProp->getValue(is_object($object) ? $object : null);
22
}
23
24
/**
25
 * Call a private or protected method
26
 * 
27
 * @param object $object
28
 * @param string $method
29
 * @param mixed  ...
30
 * @return mixed
31
 */
32
function call_private_method($object, $method)
33
{
34 6
    $args = array_slice(func_get_args(), 2);
35 6
    return call_private_method_array($object, $method, $args);
36
}
37
38
/**
39
 * Call a private or protected method, giving the arguments as array
40
 * 
41
 * @param object $object
42
 * @param string $method
43
 * @param array  $args
44
 * @return mixed
45
 */
46 View Code Duplication
function call_private_method_array($object, $method, array $args)
1 ignored issue
show
Duplication introduced by
This function 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...
47
{
48 8
    $reflObj = is_object($object) ?
49 8
        new \ReflectionObject($object) :
50 8
        new \ReflectionClass($object);
51
52 8
    $reflMethod = $reflObj->getMethod($method);
53 4
    $reflMethod->setAccessible(true);
54
55 4
    return $reflMethod->invokeArgs(is_object($object) ? $object : null, $args);
56
}
57