Conditions | 21 |
Paths | 4 |
Total Lines | 110 |
Code Lines | 82 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
58 | public function validate($role, Constraint $constraint) |
||
59 | { |
||
60 | foreach ($role->getPermissions() as $service => $permissions) { |
||
61 | if (!$this->serviceCollection->containsKey($service.'.access')) { |
||
62 | $this->context |
||
63 | ->buildViolation($constraint->serviceUndefined) |
||
64 | ->setParameter('{{ service }}', '"' . $service . '"') |
||
65 | ->atPath('permissions.' . $service) |
||
66 | ->addViolation(); |
||
67 | |||
68 | continue; |
||
69 | } |
||
70 | |||
71 | if (!is_array($permissions)) { |
||
72 | $this->context |
||
73 | ->buildViolation($constraint->permissionsNotArray) |
||
74 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
75 | ->atPath('permissions.'.$service) |
||
76 | ->addViolation(); |
||
77 | |||
78 | continue; |
||
79 | } |
||
80 | |||
81 | foreach ($permissions as $index => $permission) { |
||
82 | if (!is_array($permission)) { |
||
83 | $this->context |
||
84 | ->buildViolation($constraint->permissionNotObject) |
||
85 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
86 | ->atPath('permissions.'.$service.'['.$index.']') |
||
87 | ->addViolation(); |
||
88 | |||
89 | continue; |
||
90 | } |
||
91 | |||
92 | foreach (['scope', 'permissions'] as $attribute) { |
||
93 | if (!array_key_exists($attribute, $permission)) { |
||
94 | $this->context |
||
95 | ->buildViolation($constraint->permissionAttributeMissing) |
||
96 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
97 | ->setParameter('{{ attribute }}', '"'.$attribute.'"') |
||
98 | ->atPath('permissions.'.$service.'['.$index.'].'.$attribute) |
||
99 | ->addViolation(); |
||
100 | } |
||
101 | |||
102 | if ('scope' === $attribute) { |
||
103 | if (!is_array($permission['scope'])) { |
||
104 | $this->context |
||
105 | ->buildViolation($constraint->subscopeNotArray) |
||
106 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
107 | ->atPath('scope.'.$service.'['.$index.'].permissions') |
||
108 | ->addViolation(); |
||
109 | |||
110 | continue; |
||
111 | } |
||
112 | |||
113 | foreach (['type', 'entity', 'entityUuid'] as $subattribute) { |
||
114 | if (!array_key_exists($subattribute, $permission['scope'])) { |
||
115 | $this->context |
||
116 | ->buildViolation($constraint->subscopeAttributeMissing) |
||
117 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
118 | ->setParameter('{{ attribute }}', '"'.$subattribute.'"') |
||
119 | ->atPath('permissions.'.$service.'['.$index.'].'.$attribute.'.'.$subattribute) |
||
120 | ->addViolation(); |
||
121 | |||
122 | continue; |
||
123 | } |
||
124 | } |
||
125 | } else if ('permissions' === $attribute) { |
||
126 | if (!is_array($permission['permissions'])) { |
||
127 | $this->context |
||
128 | ->buildViolation($constraint->subpermissionsNotArray) |
||
129 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
130 | ->atPath('permissions.'.$service.'['.$index.'].permissions') |
||
131 | ->addViolation(); |
||
132 | |||
133 | continue; |
||
134 | } |
||
135 | |||
136 | foreach ($permission['permissions'] as $subindex => $subpermission) { |
||
137 | if (!is_array($subpermission)) { |
||
138 | $this->context |
||
139 | ->buildViolation($constraint->subpermissionNotObject) |
||
140 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
141 | ->atPath('permissions.'.$service.'['.$index.'].permissions['.$subindex.']') |
||
142 | ->addViolation(); |
||
143 | |||
144 | continue; |
||
145 | } |
||
146 | |||
147 | foreach (['key', 'attributes'] as $subattribute) { |
||
148 | if (!array_key_exists($subattribute, $subpermission)) { |
||
149 | $this->context |
||
150 | ->buildViolation($constraint->subpermissionAttributeMissing) |
||
151 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
152 | ->setParameter('{{ attribute }}', '"'.$subattribute.'"') |
||
153 | ->atPath('permissions.'.$service.'['.$index.'].'.$attribute.'['.$subindex.'].'.$subattribute) |
||
154 | ->addViolation(); |
||
155 | |||
156 | continue; |
||
157 | } |
||
158 | |||
159 | if ('attributes' === $subattribute) { |
||
160 | foreach ($subpermission['attributes'] as $item) { |
||
161 | if (!in_array($item, [Permission::BROWSE, Permission::READ, Permission::EDIT, Permission::ADD, Permission::DELETE, Permission::EXECUTE])) { |
||
162 | $this->context |
||
163 | ->buildViolation($constraint->subpermissionUndefined) |
||
164 | ->setParameter('{{ service }}', '"'.$service.'"') |
||
165 | ->setParameter('{{ attribute }}', '"'.$item.'"') |
||
166 | ->atPath('permissions.'.$service.'['.$index.'].'.$attribute.'['.$subindex.'].attributes') |
||
167 | ->addViolation(); |
||
168 | } |
||
179 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths