Completed
Push — master ( 1a6b57...4042aa )
by Alex
11:09
created

ReflectionAnnotatedClass::getProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 19.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Codeburner Framework.
5
 *
6
 * @author Alex Rohleder <[email protected]>
7
 * @copyright 2016 Alex Rohleder
8
 * @license http://opensource.org/licenses/MIT
9
 */
10
11
namespace Codeburner\Annotator\Reflection;
12
13
/**
14
 * Avoid the autoload by manually including the required files.
15
 * This bust significantly the performance.
16
 */
17
18
if (!trait_exists('Codeburner\Annotator\Reflection\AnnotationTrait', false)) {
19
	include __DIR__ . '/AnnotationTrait.php';
20
}
21
22
/**
23
 * Implements the annotation methods into the reflection.
24
 *
25
 * @author Alex Rohleder <[email protected]>
26
 */
27
28
class ReflectionAnnotatedClass extends \ReflectionClass
29
{
30
31
	use AnnotationTrait;
32
33
	/**
34
	 * {inheritDoc}
35
	 */
36
37
	public function getProperties($filter = null)
38
	{
39
		$properties = parent::getProperties($filter === null ? 
40
																\ReflectionProperty::IS_STATIC    | 
41
																\ReflectionProperty::IS_PUBLIC    | 
42
																\ReflectionProperty::IS_PROTECTED | 
43
																\ReflectionProperty::IS_PRIVATE 
44
																: $filter);
45
		$annotatedProperties = [];
46
47
		foreach ($properties as $property) {
48
			$annotatedProperties[] = new ReflectionAnnotatedProperty($this->name, $property->name);
49
		}
50
51
		return $annotatedProperties;
52
	}
53
54
	/**
55
	 * {inheritDoc}
56
	 */
57
58
	public function getProperty($name)
59
	{
60
		return new ReflectionAnnotatedProperty($this->name, $name);
61
	}
62
63
	/**
64
	 * {inheritDoc}
65
	 */
66
67
	public function getMethods($filter = null)
68
	{
69
		$methods = parent::getMethods($filter === null ? 
0 ignored issues
show
Unused Code introduced by
$methods is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
																\ReflectionMethod::IS_STATIC    | 
71
																\ReflectionMethod::IS_PUBLIC    | 
72
																\ReflectionMethod::IS_PROTECTED | 
73
																\ReflectionMethod::IS_PRIVATE   |
74
																\ReflectionMethod::IS_ABSTRACT  |
75
																\ReflectionMethod::IS_FINAL
76
																: $filter);
77
		$annotatedMethods = [];
78
79
		foreach ($Methods as $method) {
0 ignored issues
show
Bug introduced by
The variable $Methods does not exist. Did you mean $methods?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
80
			$annotatedMethods[] = new ReflectionAnnotatedMethod($this->name, $method->name);
81
		}
82
83
		return $annotatedMethods;
84
	}
85
86
	/**
87
	 * {inheritDoc}
88
	 */
89
90
	public function getMethod($name)
91
	{
92
		return new ReflectionAnnotatedMethod($this->name, $name);
93
	}
94
95
	/**
96
	 * {inheritDoc}
97
	 */
98
99
	public function getTraits($filter = null)
0 ignored issues
show
Unused Code introduced by
The parameter $filter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
	{
101
		$traits = parent::getTraits();
0 ignored issues
show
Unused Code introduced by
$traits is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
102
		$annotatedTraits = [];
103
104
		foreach ($Traits as $trait) {
0 ignored issues
show
Bug introduced by
The variable $Traits does not exist. Did you mean $traits?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
105
			$annotatedTraits[] = new ReflectionAnnotatedClass($trait->name);
106
		}
107
108
		return $annotatedTraits;
109
	}
110
111
}
112