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

AssertTemplateNameTrait::assertTemplateName()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.5555
c 0
b 0
f 0
cc 5
nc 4
nop 2
crap 5
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
use InvalidArgumentException;
18
19
/**
20
 * Trait AssertTemplateNameTrait
21
 *
22
 * @package TxTextControl\ReportingCloud
23
 */
24
trait AssertTemplateNameTrait
25
{
26 28
    public static function assertTemplateName(string $value, string $message = '')
27
    {
28 28
        if (basename($value) != $value) {
29 8
            $format  = "%s contains path information ('/', '.', or '..')";
30 8
            $message = sprintf($message ?: $format, static::valueToString($value));
31 8
            static::reportInvalidArgument($message);
32
        }
33
34 20
        $extension = pathinfo($value, PATHINFO_EXTENSION);
35
36
        try {
37 20
            static::assertTemplateFormat($extension);
0 ignored issues
show
Bug introduced by
The method assertTemplateFormat() does not exist on TxTextControl\ReportingC...AssertTemplateNameTrait. Did you maybe mean assertTemplateName()? ( Ignorable by Annotation )

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

37
            static::/** @scrutinizer ignore-call */ 
38
                    assertTemplateFormat($extension);

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...
38 5
        } catch (InvalidArgumentException $e) {
39 5
            $format  = "%s contains an unsupported file extension";
40 5
            $message = sprintf($message ?: $format, static::valueToString($value));
41 5
            static::reportInvalidArgument($message);
42
        }
43
44 15
        return null;
45
    }
46
}
47