Code Duplication    Length = 21-26 lines in 2 locations

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

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

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

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