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

FilenameExistsTrait::filenameExists()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.6111
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
/**
18
 * Trait FilenameExistsTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 * @author  Jonathan Maron (@JonathanMaron)
22
 */
23
trait FilenameExistsTrait
24
{
25
    /**
26
     * Validate filename exists and can be read
27
     *
28
     * @param string $value
29
     * @param string $message
30
     *
31
     * @return null
32
     * @throws \TxTextControl\ReportingCloud\Exception\InvalidArgumentException
33
     */
34 82
    public static function filenameExists(string $value, string $message = '')
35
    {
36 82
        if ($value !== realpath($value)) {
37 18
            $format  = '%s must contain the absolute path and file';
38 18
            $message = sprintf($message ?: $format, self::valueToString($value));
39 18
            self::reportInvalidArgument($message);
40
        }
41
42 64
        if (!is_file($value)) {
43 3
            $format  = '%s is not a regular file';
44 3
            $message = sprintf($message ?: $format, self::valueToString($value));
45 3
            self::reportInvalidArgument($message);
46
        }
47
48 61
        return null;
49
    }
50
}
51