Passed
Push — master ( fbc447...748ca4 )
by Jonathan
18:21
created

AssertTemplateFormatTrait::assertTemplateFormat()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 5
cts 5
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 AssertTemplateFormatTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 * @author  Jonathan Maron (@JonathanMaron)
22
 */
23
trait AssertTemplateFormatTrait
24
{
25
    /**
26
     * Validate template format
27
     *
28
     * @param string $value
29
     * @param string $message
30
     *
31
     * @return null
32
     * @throws \TxTextControl\ReportingCloud\Exception\InvalidArgumentException
33
     */
34 69
    public static function assertTemplateFormat(string $value, string $message = '')
35
    {
36 69
        $ucValue = strtoupper($value);
37
38 69
        $format  = '%s contains an unsupported template format file extension';
39 69
        $message = sprintf($message ?: $format, self::valueToString($value));
40
41 69
        return self::oneOf($ucValue, self::getTemplateFormats(), $message);
42
    }
43
}
44