AuthorizationTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkLogin() 0 7 3
A getAuthentication() 0 3 1
A setAuthentication() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace midorikocak\nanoauth;
6
7
trait AuthorizationTrait
8
{
9
    private ?AuthenticationInterface $authentication = null;
10
11 2
    public function checkLogin(): bool
12
    {
13 2
        if ($this->authentication && !$this->authentication->isLogged()) {
14 1
            throw new UnauthorizedException();
15
        }
16
17 1
        return $this->authentication->isLogged();
0 ignored issues
show
Bug introduced by
The method isLogged() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        return $this->authentication->/** @scrutinizer ignore-call */ isLogged();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
    }
19
20 1
    public function getAuthentication(): ?AuthenticationInterface
21
    {
22 1
        return $this->authentication;
23
    }
24
25 2
    public function setAuthentication(AuthenticationInterface $auth)
26
    {
27 2
        $this->authentication = $auth;
28 2
    }
29
}
30