OwnerValidationTrait::validateOwner()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 2
crap 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