Skip to content

Commit 3ea67ad

Browse files
authored
Organize exceptions (#8)
1 parent 26f5c16 commit 3ea67ad

10 files changed

+132
-23
lines changed

src/Exceptions/ArgumentNullException.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace EncoreDigitalGroup\StdLib\Exceptions;
44

5-
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
5+
use EncoreDigitalGroup\StdLib\Exceptions\NullExceptions\ArgumentNullException as BaseArgumentNullException;
66

7-
class ArgumentNullException extends BaseException
7+
/** @deprecated use EncoreDigitalGroup\StdLib\Exceptions\NullExceptions\ArgumentNullException instead */
8+
class ArgumentNullException extends BaseArgumentNullException
89
{
910
public function __construct(string $argumentName = 'Argument')
1011
{
11-
$msg = "{$argumentName} is null on {$this->line}, in {$this->file}";
12-
13-
parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
12+
parent::__construct($argumentName);
1413
}
1514
}

src/Exceptions/DirectoryNotFoundException.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
namespace EncoreDigitalGroup\StdLib\Exceptions;
44

5-
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
5+
use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\DirectoryNotFoundException as BaseDirectoryNotFoundException;
66

7-
class DirectoryNotFoundException extends BaseException
7+
/** @deprecated use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\DirectoryNotFoundException instead */
8+
class DirectoryNotFoundException extends BaseDirectoryNotFoundException
89
{
910
public function __construct(?string $path = null)
1011
{
11-
if (is_null($path)) {
12-
$msg = str_concat_space('Unable to locate directory on line', $this->line, 'in', $this->file);
13-
} else {
14-
$msg = str_concat_space('Unable to locate directory', $path, 'on line', $this->line, 'in', $this->file);
15-
}
16-
17-
parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
12+
parent::__construct($path);
1813
}
1914
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\EmptyExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class ArrayEmptyException extends BaseException
9+
{
10+
public function __construct(string $arrayName = 'Array')
11+
{
12+
$msg = "{$arrayName} cannot be an empty array.";
13+
14+
parent::__construct($msg, ExitCode::GENERAL_ERROR, $this->getPrevious());
15+
}
16+
}

src/Exceptions/FileNotFoundException.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
namespace EncoreDigitalGroup\StdLib\Exceptions;
44

5-
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
5+
use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\FileNotFoundException as BaseFileNotFoundException;
66

7-
class FileNotFoundException extends BaseException
7+
/** @deprecated use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\FileNotFoundException instead. */
8+
class FileNotFoundException extends BaseFileNotFoundException
89
{
910
public function __construct(?string $path = null)
1011
{
11-
if (is_null($path)) {
12-
$msg = str_concat_space('Unable to locate file on line', $this->line, 'in', $this->file);
13-
} else {
14-
$msg = str_concat_space('Unable to locate file', $path, 'on line', $this->line, 'in', $this->file);
15-
}
16-
17-
parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
12+
parent::__construct($path);
1813
}
1914
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class DirectoryNotFoundException extends BaseException
9+
{
10+
public function __construct(?string $path = null)
11+
{
12+
if (is_null($path)) {
13+
$msg = str_concat_space('Unable to locate directory on line', $this->line, 'in', $this->file);
14+
} else {
15+
$msg = str_concat_space('Unable to locate directory', $path, 'on line', $this->line, 'in', $this->file);
16+
}
17+
18+
parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class FileNotFoundException extends BaseException
9+
{
10+
public function __construct(?string $path = null)
11+
{
12+
if (is_null($path)) {
13+
$msg = str_concat_space('Unable to locate file on line', $this->line, 'in', $this->file);
14+
} else {
15+
$msg = str_concat_space('Unable to locate file', $path, 'on line', $this->line, 'in', $this->file);
16+
}
17+
18+
parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
19+
}
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class ArgumentNullException extends BaseException
9+
{
10+
public function __construct(string $argumentName = 'Argument')
11+
{
12+
$msg = "{$argumentName} is null on {$this->line}, in {$this->file}";
13+
14+
parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class ClassPropertyNullException extends BaseException
9+
{
10+
public function __construct(string $propertyName = 'Property')
11+
{
12+
$msg = "{$propertyName} cannot be null.";
13+
14+
parent::__construct($msg, ExitCode::GENERAL_ERROR, $this->getPrevious());
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class NullException extends BaseException
9+
{
10+
public function __construct(string $arg)
11+
{
12+
$msg = "{$arg} cannot be null.";
13+
14+
parent::__construct($msg, ExitCode::DATA_ERROR, $this->getPrevious());
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;
4+
5+
use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
6+
use EncoreDigitalGroup\StdLib\Objects\ExitCode;
7+
8+
class VariableNullException extends BaseException
9+
{
10+
public function __construct(string $variableName = 'Variable')
11+
{
12+
$msg = "{$variableName} cannot be null.";
13+
14+
parent::__construct($msg, ExitCode::GENERAL_ERROR, $this->getPrevious());
15+
}
16+
}

0 commit comments

Comments
 (0)