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

FilenameExistsTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A filenameExists() 0 15 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
/**
18
 * Trait FilenameExistsTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 */
22
trait FilenameExistsTrait
23
{
24
    /**
25
     * Validate filename exists and can be read
26
     *
27
     * @param string $value
28
     * @param string $message
29
     *
30
     * @return null
31
     */
32 28
    public static function filenameExists(string $value, string $message = '')
33
    {
34 28
        if ($value !== realpath($value)) {
35 6
            $format  = '%s must contain the absolute path and file';
36 6
            $message = sprintf($message ?: $format, static::valueToString($value));
37 6
            static::reportInvalidArgument($message);
38
        }
39
40 22
        if (!is_file($value)) {
41 1
            $format  = '%s is not a regular file';
42 1
            $message = sprintf($message ?: $format, static::valueToString($value));
43 1
            static::reportInvalidArgument($message);
44
        }
45
46 21
        return null;
47
    }
48
}
49