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

FileNotWritableException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromInvalidMoveOperation() 0 9 1
B fromNonWritableLocation() 0 19 6
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