Conditions | 3 |
Paths | 3 |
Total Lines | 14 |
Code Lines | 7 |
Lines | 14 |
Ratio | 100 % |
Tests | 7 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
18 | 3 | public static function create(string $path, string $content): File |
|
19 | { |
||
20 | 3 | if (is_file($path)) { |
|
21 | 1 | throw new ExistsException(sprintf('The file `%s` already exists.', $path)); |
|
22 | } |
||
23 | |||
24 | 2 | @file_put_contents($path, $content); |
|
25 | |||
26 | 2 | if (!is_file($path)) { |
|
27 | 1 | throw new PermissionDeniedException(error_get_last()['message'], error_get_last()['type']); |
|
28 | } |
||
29 | |||
30 | 1 | return new self($path); |
|
31 | } |
||
32 | |||
38 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.