OwnerValidationTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
c 1
b 0
f 0
dl 0
loc 11
ccs 3
cts 3
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateOwner() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Lib\Component;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Uxmp\Core\Api\Lib\Exception\AccessViolation;
9
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware;
10
use Uxmp\Core\Component\User\OwnerProviderInterface;
11
12
/**
13
 * Match a user object against the requesting user
14
 */
15
trait OwnerValidationTrait
16
{
17
    /**
18
     * @throws AccessViolation
19
     */
20 4
    private function validateOwner(
21
        ServerRequestInterface $request,
22
        OwnerProviderInterface $provider
23
    ): void {
24 4
        if ($provider->getOwner()->getId() !== $request->getAttribute(SessionValidatorMiddleware::USER_ID)) {
25 1
            throw new AccessViolation();
26
        }
27
    }
28
}
29