Skip to content

Commit df97b82

Browse files
authored
Added AlreadyExistsExceptions for filesystem along with related excep… (#5)
* Added AlreadyExistsExceptions for filesystem along with related exception tag * Formatting fix
1 parent 8c0afd5 commit df97b82

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Exceptions\IO\Filesystem;
4+
5+
use Exceptions\Tag\AlreadyExistsException;
6+
7+
/**
8+
* Use this exception when your code tries to create a local directory but it already exists.
9+
*
10+
* @author Mathieu Dumoulin aka CrazyCodr <[email protected]>
11+
* @license MIT
12+
*/
13+
class DirectoryAlreadyExistsException extends FilesystemException implements AlreadyExistsException
14+
{
15+
public function __construct(
16+
$message = 'Cannot find specified directory',
17+
$code = 0,
18+
$previous = null
19+
) {
20+
parent::__construct($message, $code, $previous);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Exceptions\IO\Filesystem;
4+
5+
use Exceptions\Tag\AlreadyExistsException;
6+
7+
/**
8+
* Use this exception when your code tries to create a file but it already exists.
9+
*
10+
* @author Mathieu Dumoulin aka CrazyCodr <[email protected]>
11+
* @license MIT
12+
*/
13+
class FileAlreadyExistsException extends FilesystemException implements AlreadyExistsException
14+
{
15+
public function __construct(
16+
$message = 'Cannot find specified file',
17+
$code = 0,
18+
$previous = null
19+
) {
20+
parent::__construct($message, $code, $previous);
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Exceptions\Tag;
4+
5+
/**
6+
* This is a tag interface that is used to conveys a shared means throughout many different exceptions in many
7+
* different namespaces. If you want to catch a potential error about something that already exists, you would try to
8+
* catch any exception that implements this interface.
9+
*
10+
* @author Mathieu Dumoulin aka CrazyCodr <[email protected]>
11+
* @license MIT
12+
*/
13+
interface AlreadyExistsException
14+
{
15+
}

Tests/ExceptionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ public function providesConstructorTestClasses()
3434
[\Exceptions\Http\Server\NotImplementedException::class],
3535
[\Exceptions\Http\Server\ServiceUnavailableException::class],
3636
[\Exceptions\IO\Filesystem\FileNotWritableException::class],
37+
[\Exceptions\IO\Filesystem\FileAlreadyExistsException::class],
3738
[\Exceptions\IO\Filesystem\NotAFileException::class],
3839
[\Exceptions\IO\Filesystem\NotADirectoryException::class],
3940
[\Exceptions\IO\Filesystem\FileNotFoundException::class],
4041
[\Exceptions\IO\Filesystem\DirectoryNotWritableException::class],
42+
[\Exceptions\IO\Filesystem\DirectoryAlreadyExistsException::class],
4143
[\Exceptions\IO\Filesystem\DirectoryNotFoundException::class],
4244
[\Exceptions\IO\Filesystem\FileNotReadableException::class],
4345
[\Exceptions\IO\Filesystem\DirectoryNotReadableException::class],

0 commit comments

Comments
 (0)