Code Duplication    Length = 21-26 lines in 2 locations

src/IPub/Permissions/Access/AnnotationChecker.php 1 location

@@ 156-181 (lines=26) @@
153
	 *
154
	 * @throws Exceptions\InvalidStateException
155
	 */
156
	private function checkPrivileges($element) : bool
157
	{
158
		// Check if element has @Secured\Privilege annotation & hasn't @Secured\Resource annotation
159
		if (!$element->hasAnnotation('Secured\Resource') && $element->hasAnnotation('Secured\Privilege')) {
160
			$privileges = UI\ComponentReflection::parseAnnotation($element, 'Secured\Privilege');
161
162
			if (count($privileges) != 1) {
163
				throw new Exceptions\InvalidStateException('Invalid privileges count in @Security\Privilege annotation!');
164
			}
165
166
			foreach ($privileges as $privilege) {
167
				// Check if privilege name is defined
168
				if ($privilege === TRUE) {
169
					continue;
170
				}
171
172
				if ($this->user->isAllowed(NS\IAuthorizator::ALL, $privilege)) {
173
					return TRUE;
174
				}
175
			}
176
177
			return FALSE;
178
		}
179
180
		return TRUE;
181
	}
182
183
	/**
184
	 * @param UI\ComponentReflection|UI\MethodReflection $element

src/IPub/Permissions/Access/LatteChecker.php 1 location

@@ 153-173 (lines=21) @@
150
	 *
151
	 * @throws Exceptions\InvalidStateException
152
	 */
153
	protected function checkPrivileges(Utils\ArrayHash $element) : bool
154
	{
155
		// Check if element has privilege parameter & hasn't resource parameter
156
		if (!$element->offsetExists('resource') && $element->offsetExists('privilege')) {
157
			$privileges = (array) $element->offsetGet('privilege');
158
159
			if (count($privileges) != 1) {
160
				throw new Exceptions\InvalidStateException('Invalid privileges count in \'privilege\' parameter!');
161
			}
162
163
			foreach ($privileges as $privilege) {
164
				if ($this->user->isAllowed(NS\IAuthorizator::ALL, $privilege)) {
165
					return TRUE;
166
				}
167
			}
168
169
			return FALSE;
170
		}
171
172
		return TRUE;
173
	}
174
175
	/**
176
	 * @param Utils\ArrayHash $element