This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace PhpAbac\Manager; |
||
4 | |||
5 | use PhpAbac\Model\AbstractAttribute; |
||
6 | use PhpAbac\Model\Attribute; |
||
7 | use PhpAbac\Model\EnvironmentAttribute; |
||
8 | |||
9 | class AttributeManager |
||
10 | { |
||
11 | /** @var array **/ |
||
12 | private $attributes; |
||
13 | |||
14 | /** @var string Prefix to add before getter name (default)'get' */ |
||
15 | private $getter_prefix = 'get'; |
||
16 | /** @var string Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' */ |
||
17 | private $getter_name_transformation_function = 'ucfirst'; |
||
18 | |||
19 | |||
20 | /** |
||
21 | * @param array $attributes |
||
22 | * @param array $options A List of option to configure This Abac Instance |
||
23 | * Options list : |
||
24 | * 'getter_prefix' => Prefix to add before getter name (default)'get' |
||
25 | * 'getter_name_transformation_function' => Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' |
||
26 | */ |
||
27 | 28 | public function __construct($attributes, $options = []) |
|
28 | { |
||
29 | 28 | $this->attributes = $attributes; |
|
30 | |||
31 | 28 | $options = array_intersect_key( $options, array_flip( [ |
|
32 | 28 | 'getter_prefix', |
|
33 | 28 | 'getter_name_transformation_function', |
|
34 | 28 | ] ) ); |
|
35 | |||
36 | 28 | foreach($options as $name => $value) { |
|
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
37 | $this->$name = $value; |
||
38 | 28 | } |
|
39 | 28 | } |
|
40 | |||
41 | /** |
||
42 | * @param string $attributeId |
||
43 | * @return \PhpAbac\Model\AbstractAttribute |
||
44 | */ |
||
45 | 11 | public function getAttribute($attributeId) { |
|
46 | 11 | $attributeKeys = explode('.', $attributeId); |
|
47 | // The first element will be the attribute ID, then the field ID |
||
48 | 11 | $attributeId = array_shift($attributeKeys); |
|
49 | 11 | $attributeName = implode('.', $attributeKeys); |
|
50 | // The field ID is also the attribute object property |
||
51 | 11 | $attributeData = $this->attributes[$attributeId]; |
|
52 | return |
||
53 | 11 | ($attributeId === 'environment') |
|
54 | 11 | ? $this->getEnvironmentAttribute($attributeData, $attributeName) |
|
55 | 11 | : $this->getClassicAttribute($attributeData, $attributeName) |
|
56 | 11 | ; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param array $attributeData |
||
61 | * @param string $property |
||
62 | * @return \PhpAbac\Model\Attribute |
||
63 | */ |
||
64 | 9 | private function getClassicAttribute($attributeData, $property) { |
|
65 | return |
||
66 | 9 | (new Attribute()) |
|
67 | 9 | ->setName($attributeData['fields'][$property]['name']) |
|
68 | 9 | ->setType($attributeData['type']) |
|
69 | 9 | ->setProperty($property) |
|
70 | 9 | ->setSlug($this->slugify($attributeData['fields'][$property]['name'])) |
|
71 | 9 | ; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param array $attributeData |
||
76 | * @param string $key |
||
77 | * @return \PhpAbac\Model\EnvironmentAttribute |
||
78 | */ |
||
79 | 4 | private function getEnvironmentAttribute($attributeData, $key) { |
|
80 | return |
||
81 | 4 | (new EnvironmentAttribute()) |
|
82 | 4 | ->setName($attributeData[$key]['name']) |
|
83 | 4 | ->setType('environment') |
|
84 | 4 | ->setVariableName($attributeData[$key]['variable_name']) |
|
85 | 4 | ->setSlug($this->slugify($attributeData[$key]['name'])) |
|
86 | 4 | ; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param AbstractAttribute $attribute |
||
91 | * @param string $attributeType |
||
0 ignored issues
–
show
There is no parameter named
$attributeType . Did you maybe mean $attribute ?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit. Consider the following example. The parameter /**
* @param array $germany
* @param array $ireland
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was changed, but the annotation was not. ![]() |
|||
92 | * @param object $user |
||
93 | * @param object $object |
||
94 | * @return mixed |
||
95 | */ |
||
96 | 9 | public function retrieveAttribute(AbstractAttribute $attribute, $user = null, $object = null, $getter_params = []) |
|
97 | { |
||
98 | 9 | switch($attribute->getType()) { |
|
0 ignored issues
–
show
|
|||
99 | 9 | case 'user': |
|
100 | 6 | return $this->retrieveClassicAttribute($attribute, $user, $getter_params); |
|
0 ignored issues
–
show
$attribute of type object<PhpAbac\Model\AbstractAttribute> is not a sub-type of object<PhpAbac\Model\Attribute> . It seems like you assume a child class of the class PhpAbac\Model\AbstractAttribute to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() It seems like
$user defined by parameter $user on line 96 can also be of type null ; however, PhpAbac\Manager\Attribut...rieveClassicAttribute() does only seem to accept object , maybe add an additional type check?
This check looks at variables that have been passed in as parameters and are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
101 | 6 | case 'resource': |
|
102 | 5 | return $this->retrieveClassicAttribute($attribute, $object); |
|
0 ignored issues
–
show
$attribute of type object<PhpAbac\Model\AbstractAttribute> is not a sub-type of object<PhpAbac\Model\Attribute> . It seems like you assume a child class of the class PhpAbac\Model\AbstractAttribute to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() It seems like
$object defined by parameter $object on line 96 can also be of type null ; however, PhpAbac\Manager\Attribut...rieveClassicAttribute() does only seem to accept object , maybe add an additional type check?
This check looks at variables that have been passed in as parameters and are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
103 | 2 | case 'environment': |
|
104 | 2 | return $this->retrieveEnvironmentAttribute($attribute); |
|
0 ignored issues
–
show
$attribute of type object<PhpAbac\Model\AbstractAttribute> is not a sub-type of object<PhpAbac\Model\EnvironmentAttribute> . It seems like you assume a child class of the class PhpAbac\Model\AbstractAttribute to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
105 | } |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param Attribute $attribute |
||
110 | * @param object $object |
||
111 | * @return mixed |
||
112 | */ |
||
113 | 8 | private function retrieveClassicAttribute(Attribute $attribute, $object, $getter_params = []) |
|
114 | { |
||
115 | 8 | $propertyPath = explode('.', $attribute->getProperty()); |
|
116 | 8 | $propertyValue = $object; |
|
117 | 8 | foreach($propertyPath as $property) { |
|
0 ignored issues
–
show
|
|||
118 | |||
119 | |||
120 | 8 | $getter = $this->getter_prefix.call_user_func($this->getter_name_transformation_function,$property); |
|
121 | // Use is_callable, instead of method_exists, to deal with __call magic method |
||
122 | 8 | if(!is_callable([$propertyValue,$getter])) { |
|
0 ignored issues
–
show
|
|||
123 | throw new \InvalidArgumentException('There is no getter for the "'.$attribute->getProperty().'" attribute for object "'.get_class($propertyValue).'" with getter "'.$getter.'"'); |
||
124 | } |
||
125 | 8 | if ( ( $propertyValue = call_user_func_array( [ |
|
126 | 8 | $propertyValue, |
|
127 | 8 | $getter, |
|
128 | 8 | ], isset( $getter_params[ $property ] ) ? $getter_params[ $property ] : [] ) ) === null |
|
129 | 8 | ) { |
|
130 | 1 | return null; |
|
131 | } |
||
132 | 8 | } |
|
133 | 8 | return $propertyValue; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * |
||
138 | * @param \PhpAbac\Model\EnvironmentAttribute $attribute |
||
139 | * @return mixed |
||
140 | */ |
||
141 | 2 | private function retrieveEnvironmentAttribute(EnvironmentAttribute $attribute) { |
|
142 | 2 | return getenv($attribute->getVariableName()); |
|
143 | } |
||
144 | |||
145 | /* |
||
146 | * @param string $name |
||
147 | * @return string |
||
148 | */ |
||
149 | 11 | public function slugify($name) |
|
150 | { |
||
151 | // replace non letter or digits by - |
||
152 | 11 | $name = trim(preg_replace('~[^\\pL\d]+~u', '-', $name), '-'); |
|
153 | // transliterate |
||
154 | 11 | if (function_exists('iconv')) { |
|
155 | 11 | $name = iconv('utf-8', 'us-ascii//TRANSLIT', $name); |
|
156 | 11 | } |
|
157 | // remove unwanted characters |
||
158 | 11 | $name = preg_replace('~[^-\w]+~', '', strtolower($name)); |
|
159 | 11 | if (empty($name)) { |
|
160 | return 'n-a'; |
||
161 | } |
||
162 | 11 | return $name; |
|
163 | } |
||
164 | } |
||
165 |