Completed
Pull Request — master (#391)
by Marco
07:35
created

fromInvalidMoveOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Exception;
6
7
use UnexpectedValueException;
8
9
/**
10
 * Exception for non writable files
11
 *
12
 * @author Marco Pivetta <[email protected]>
13
 * @license MIT
14
 */
15
class FileNotWritableException extends UnexpectedValueException implements ExceptionInterface
16
{
17 1
    public static function fromInvalidMoveOperation(string $fromPath, string $toPath) : self
18
    {
19 1
        return new self(sprintf(
20
            'Could not move file "%s" to location "%s": '
21 1
            . 'either the source file is not readable, or the destination is not writable',
22 1
            $fromPath,
23 1
            $toPath
24
        ));
25
    }
26
27
    /**
28
     * @deprecated this method is unused, and will be removed in ProxyManager 3.0.0
29
     */
30 3
    public static function fromNonWritableLocation($path) : self
31
    {
32 3
        $messages    = [];
33 3
        $destination = realpath($path);
34
35 3
        if (! $destination) {
36 1
            $messages[] = 'path does not exist';
37
        }
38
39 3
        if ($destination && ! is_file($destination)) {
40 2
            $messages[] = 'exists and is not a file';
41
        }
42
43 3
        if ($destination && ! is_writable($destination)) {
44 1
            $messages[] = 'is not writable';
45
        }
46
47 3
        return new self(sprintf('Could not write to path "%s": %s', $path, implode(', ', $messages)));
48
    }
49
}
50