Passed
Branch development-2.0 (f1893c)
by Jonathan
06:14
created

assertDocumentExtension()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP Wrapper
6
 *
7
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
8
 *
9
 * @link      https://www.reporting.cloud to learn more about ReportingCloud
10
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
11
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
12
 * @copyright © 2019 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Assert;
16
17
/**
18
 * Trait AssertDocumentExtensionTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 */
22
trait AssertDocumentExtensionTrait
23
{
24
    /**
25
     * Validate document format extension
26
     *
27
     * @param string $value
28
     * @param string $message
29
     *
30
     * @return null
31
     */
32 10
    public static function assertDocumentExtension(string $value, string $message = '')
33
    {
34 10
        $extension = pathinfo($value, PATHINFO_EXTENSION);
35 10
        $extension = strtoupper($extension);
36
37 10
        $format  = '%s contains an unsupported document format file extension';
38 10
        $message = sprintf($message ?: $format, static::valueToString($value));
39
40 10
        return static::oneOf($extension, static::getDocumentFormats(), $message);
41
    }
42
}
43