Completed
Push — master ( 3be072...ba2d3a )
by Marco
231:32 queued 209:55
created

SignatureChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Signature;
6
7
use ProxyManager\Signature\Exception\InvalidSignatureException;
8
use ProxyManager\Signature\Exception\MissingSignatureException;
9
use ReflectionClass;
10
use function array_key_exists;
11
12
/**
13
 * Generator for signatures to be used to check the validity of generated code
14
 */
15
final class SignatureChecker implements SignatureCheckerInterface
16
{
17
    private SignatureGeneratorInterface $signatureGenerator;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
18
19
    public function __construct(SignatureGeneratorInterface $signatureGenerator)
20
    {
21 3
        $this->signatureGenerator = $signatureGenerator;
22
    }
23 3
24 3
    /**
25
     * {@inheritDoc}
26
     */
27
    public function checkSignature(ReflectionClass $class, array $parameters) : void
28
    {
29 3
        $propertyName      = 'signature' . $this->signatureGenerator->generateSignatureKey($parameters);
30
        $signature         = $this->signatureGenerator->generateSignature($parameters);
31 3
        $defaultProperties = $class->getDefaultProperties();
32 3
33 3
        if (! array_key_exists($propertyName, $defaultProperties)) {
34
            throw MissingSignatureException::fromMissingSignature($class, $parameters, $signature);
35 3
        }
36 1
37
        if ($defaultProperties[$propertyName] !== $signature) {
38
            throw InvalidSignatureException::fromInvalidSignature(
39 2
                $class,
40 1
                $parameters,
41 1
                $defaultProperties[$propertyName],
42 1
                $signature
43 1
            );
44 1
        }
45
    }
46
}
47