-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check data can be casted before actual casting
- Loading branch information
Showing
8 changed files
with
188 additions
and
8 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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Exception; | ||
|
||
class NonCastableTypeException extends RuntimeException | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __construct(string $expectedType, $value) | ||
{ | ||
$this->value = $value; | ||
|
||
parent::__construct( | ||
sprintf( | ||
'Cannot convert value of type "%s" to %s', | ||
gettype($value), | ||
$expectedType | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Exception; | ||
|
||
class NonFloatCastableTypeException extends NonCastableTypeException | ||
{ | ||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __construct($value) | ||
{ | ||
parent::__construct('float', $value); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Exception; | ||
|
||
class NonIntCastableTypeException extends NonCastableTypeException | ||
{ | ||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __construct($value) | ||
{ | ||
parent::__construct('int', $value); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Exception; | ||
|
||
class NonStringCastableTypeException extends NonCastableTypeException | ||
{ | ||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __construct($value) | ||
{ | ||
parent::__construct('string', $value); | ||
} | ||
} |
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