-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add better vendor-specific exceptions and replace uses
Fixes #43
- Loading branch information
Showing
15 changed files
with
267 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Exceptions; | ||
|
||
/** | ||
* Compatibility Exception | ||
* | ||
* This exception is used when a component of Sprout is not compatible with | ||
* another. | ||
* | ||
* @package Core | ||
*/ | ||
final class CompatibilityException extends SproutException | ||
{ | ||
/** | ||
* Create the exception | ||
* | ||
* @param string $firstType | ||
* @param string $firstName | ||
* @param string $secondType | ||
* @param string $secondName | ||
* | ||
* @return self | ||
*/ | ||
public static function make(string $firstType, string $firstName, string $secondType, string $secondName): self | ||
{ | ||
return new self('Cannot use ' . $firstType . ' [' . $firstName . '] with ' . $secondType . ' [' . $secondName . ']'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Exceptions; | ||
|
||
/** | ||
* Misconfiguration Exception | ||
* | ||
* This exception is used when a component of Sprout does not have the correct | ||
* configuration, whether that's through omissions or incorrect values. | ||
* This also includes cases where instances of certain classes/interfaces is | ||
* expected, but not provided. | ||
* | ||
* @package Core | ||
*/ | ||
final class MisconfigurationException extends SproutException | ||
{ | ||
/** | ||
* Create an exception for when a config value is missing | ||
* | ||
* @param string $value | ||
* @param string $type | ||
* @param string $name | ||
* | ||
* @return self | ||
*/ | ||
public static function missingConfig(string $value, string $type, string $name): self | ||
{ | ||
return new self('The ' . $type . ' [' . $name . '] is missing a required value for \'' . $value . '\''); | ||
} | ||
|
||
/** | ||
* Create an exception for when a config value is invalid | ||
* | ||
* @param string $value | ||
* @param string $type | ||
* @param string $name | ||
* | ||
* @return self | ||
*/ | ||
public static function invalidConfig(string $value, string $type, string $name): self | ||
{ | ||
return new self('The provided value for \'' . $value . '\' is not valid for' . $type . ' [' . $name . ']'); | ||
} | ||
|
||
/** | ||
* Create an exception for when something is misconfigured for a use | ||
* | ||
* @param string $type | ||
* @param string $name | ||
* @param string $subject | ||
* | ||
* @return self | ||
*/ | ||
public static function misconfigured(string $type, string $name, string $subject): self | ||
{ | ||
return new self('The current ' . $type . ' [' . $name . '] is not configured correctly for ' . $subject); | ||
} | ||
|
||
/** | ||
* Create an exception for when an expected configuration is not found | ||
* | ||
* @param string $type | ||
* @param string $name | ||
* | ||
* @return self | ||
*/ | ||
public static function notFound(string $type, string $name): self | ||
{ | ||
return new self('The ' . $type . ' for [' . $name . '] could not be found'); | ||
} | ||
|
||
/** | ||
* Create a new exception for when a default value is missing | ||
* | ||
* @param string $type | ||
* | ||
* @return self | ||
*/ | ||
public static function noDefault(string $type): self | ||
{ | ||
return new self('There is no default ' . $type . ' set'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Exceptions; | ||
|
||
/** | ||
* Tenancy Missing Exception | ||
* | ||
* This exception is used when there is no current tenancy, but one is | ||
* expected/required. | ||
* | ||
* @package Core | ||
*/ | ||
final class TenancyMissing extends SproutException | ||
{ | ||
/** | ||
* Create the exception | ||
* | ||
* @return self | ||
*/ | ||
public static function make(): self | ||
{ | ||
return new self( | ||
'There is no current tenancy' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Exceptions; | ||
|
||
use Throwable; | ||
|
||
/** | ||
* Tenant Relation Exception | ||
* | ||
* This exception is used for issues that arise with tenant child/descendant | ||
* relations. | ||
* | ||
* @package Database\Eloquent | ||
*/ | ||
final class TenantRelationException extends SproutException | ||
{ | ||
/** | ||
* Create an exception for when the tenant relation is missing | ||
* | ||
* @param string $model | ||
* @param \Throwable|null $previous | ||
* | ||
* @return self | ||
*/ | ||
public static function missing(string $model, ?Throwable $previous = null): self | ||
{ | ||
return new self('Cannot find tenant relation for model [' . $model . ']', previous: $previous); | ||
} | ||
|
||
/** | ||
* Create an exception for when there are too many tenant relations | ||
* | ||
* @param string $model | ||
* @param int $count | ||
* | ||
* @return self | ||
*/ | ||
public static function tooMany(string $model, int $count): self | ||
{ | ||
return new self('Expected one tenant relation, found ' . $count . ' in model [' . $model . ']'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.