Passed
Pull Request — master (#60)
by Tim
02:15
created

HMACOutputLengthValue   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Type;
6
7
use SimpleSAML\XML\Exception\SchemaViolationException;
8
use SimpleSAML\XML\Type\IntegerValue;
9
use SimpleSAML\XMLSecurity\Assert\Assert;
10
use SimpleSAML\XMLSecurity\Exception\ProtocolViolationException;
11
12
/**
13
 * @package simplesaml/xml-security
14
 */
15
class HMACOutputLengthValue extends IntegerValue
16
{
17
    /**
18
     * Validate the value.
19
     *
20
     * @param string $value
21
     * @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure
22
     * @return void
23
     */
24
    protected function validateValue(string $value): void
25
    {
26
        // Note: value must already be sanitized before validating
27
        $value = $this->sanitizeValue($value);
28
29
        Assert::validHMACOutputLength($value, SchemaViolationException::class);
30
        Assert::true(
31
            intval($value) % 8 === 0,
32
            '%s is not devisible by 8 and therefore not a valid ds:HMACOutputLengthType',
33
            ProtocolViolationException::class,
34
        );
35
    }
36
}
37