Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize exceptions #8

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Exceptions/ArgumentNullException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace EncoreDigitalGroup\StdLib\Exceptions;

use EncoreDigitalGroup\StdLib\Objects\ExitCode;
use EncoreDigitalGroup\StdLib\Exceptions\NullExceptions\ArgumentNullException as BaseArgumentNullException;

class ArgumentNullException extends BaseException
/** @deprecated use EncoreDigitalGroup\StdLib\Exceptions\NullExceptions\ArgumentNullException instead */
class ArgumentNullException extends BaseArgumentNullException
{
public function __construct(string $argumentName = 'Argument')
{
$msg = "{$argumentName} is null on {$this->line}, in {$this->file}";

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
parent::__construct($argumentName);
}
}
13 changes: 4 additions & 9 deletions src/Exceptions/DirectoryNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

namespace EncoreDigitalGroup\StdLib\Exceptions;

use EncoreDigitalGroup\StdLib\Objects\ExitCode;
use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\DirectoryNotFoundException as BaseDirectoryNotFoundException;

class DirectoryNotFoundException extends BaseException
/** @deprecated use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\DirectoryNotFoundException instead */
class DirectoryNotFoundException extends BaseDirectoryNotFoundException
{
public function __construct(?string $path = null)
{
if (is_null($path)) {
$msg = str_concat_space('Unable to locate directory on line', $this->line, 'in', $this->file);
} else {
$msg = str_concat_space('Unable to locate directory', $path, 'on line', $this->line, 'in', $this->file);
}

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
parent::__construct($path);
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/EmptyExceptions/ArrayEmptyException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\EmptyExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class ArrayEmptyException extends BaseException
{
public function __construct(string $arrayName = 'Array')
{
$msg = "{$arrayName} cannot be an empty array.";

parent::__construct($msg, ExitCode::GENERAL_ERROR, $this->getPrevious());
}
}
13 changes: 4 additions & 9 deletions src/Exceptions/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

namespace EncoreDigitalGroup\StdLib\Exceptions;

use EncoreDigitalGroup\StdLib\Objects\ExitCode;
use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\FileNotFoundException as BaseFileNotFoundException;

class FileNotFoundException extends BaseException
/** @deprecated use EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions\FileNotFoundException instead. */
class FileNotFoundException extends BaseFileNotFoundException
{
public function __construct(?string $path = null)
{
if (is_null($path)) {
$msg = str_concat_space('Unable to locate file on line', $this->line, 'in', $this->file);
} else {
$msg = str_concat_space('Unable to locate file', $path, 'on line', $this->line, 'in', $this->file);
}

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
parent::__construct($path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class DirectoryNotFoundException extends BaseException
{
public function __construct(?string $path = null)
{
if (is_null($path)) {
$msg = str_concat_space('Unable to locate directory on line', $this->line, 'in', $this->file);
} else {
$msg = str_concat_space('Unable to locate directory', $path, 'on line', $this->line, 'in', $this->file);
}

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
}
}
20 changes: 20 additions & 0 deletions src/Exceptions/FilesystemExceptions/FileNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\FilesystemExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class FileNotFoundException extends BaseException
{
public function __construct(?string $path = null)
{
if (is_null($path)) {
$msg = str_concat_space('Unable to locate file on line', $this->line, 'in', $this->file);
} else {
$msg = str_concat_space('Unable to locate file', $path, 'on line', $this->line, 'in', $this->file);
}

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/NullExceptions/ArgumentNullException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class ArgumentNullException extends BaseException
{
public function __construct(string $argumentName = 'Argument')
{
$msg = "{$argumentName} is null on {$this->line}, in {$this->file}";

parent::__construct($msg, ExitCode::RESOURCE_UNAVAILABLE, $this->getPrevious());
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/NullExceptions/ClassPropertyNullException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class ClassPropertyNullException extends BaseException
{
public function __construct(string $propertyName = 'Property')
{
$msg = "{$propertyName} cannot be null.";

parent::__construct($msg, ExitCode::GENERAL_ERROR, $this->getPrevious());
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/NullExceptions/NullException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class NullException extends BaseException
{
public function __construct(string $arg)
{
$msg = "{$arg} cannot be null.";

parent::__construct($msg, ExitCode::DATA_ERROR, $this->getPrevious());
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/NullExceptions/VariableNullException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace EncoreDigitalGroup\StdLib\Exceptions\NullExceptions;

use EncoreDigitalGroup\StdLib\Exceptions\BaseException;
use EncoreDigitalGroup\StdLib\Objects\ExitCode;

class VariableNullException extends BaseException
{
public function __construct(string $variableName = 'Variable')
{
$msg = "{$variableName} cannot be null.";

parent::__construct($msg, ExitCode::GENERAL_ERROR, $this->getPrevious());
}
}
Loading