This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from bhulsman/master
Add generic collection support. Fixes #2
- Loading branch information
Showing
5 changed files
with
102 additions
and
1 deletion.
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
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,39 @@ | ||
<?php | ||
|
||
namespace Spatie\ValueObject; | ||
|
||
use Exception; | ||
|
||
class ValueObjectException extends Exception | ||
{ | ||
public static function unknownPublicProperty(string $name, string $className): ValueObjectException | ||
{ | ||
return new self("Public property {$name} not found on {$className}"); | ||
} | ||
|
||
public static function invalidType( | ||
string $propertyName, | ||
string $className, | ||
string $expectedType, | ||
$value | ||
): ValueObjectException { | ||
if ($value === null) { | ||
$value = 'null'; | ||
} | ||
|
||
if (is_object($value)) { | ||
$value = get_class($value); | ||
} | ||
|
||
if (is_array($value)) { | ||
$value = 'array'; | ||
} | ||
|
||
return new self("Invalid type: expected {$className}::{$propertyName} to be of type {$expectedType}; instead got value `{$value}`."); | ||
} | ||
|
||
public static function uninitialisedProperty(string $name): ValueObjectException | ||
{ | ||
return new self("Non-nullable property `{$name}` has not been initialised."); | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Spatie\ValueObject\Tests\TestClasses; | ||
|
||
class OtherClass | ||
{ | ||
} |
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