-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throws exception if the paired property does not exist in the o…
…ther class if the `Map` attribute has `class` set
- Loading branch information
Showing
6 changed files
with
119 additions
and
10 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
44 changes: 44 additions & 0 deletions
44
src/Transformer/Exception/PairedPropertyNotFoundException.php
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Transformer\Exception; | ||
|
||
use Rekalogika\Mapper\Exception\ExceptionInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class PairedPropertyNotFoundException extends \LogicException implements ExceptionInterface | ||
{ | ||
/** | ||
* @param class-string $class | ||
*/ | ||
public function __construct( | ||
string $class, | ||
string $property, | ||
string $pairedClass, | ||
string $pairedProperty, | ||
) { | ||
$message = \sprintf( | ||
'Trying to map class "%s" property "%s" to class "%s" property "%s" according to the "Map" attribute, but the property "%s" is not found in class "%s"', | ||
$class, | ||
$property, | ||
$pairedClass, | ||
$pairedProperty, | ||
$pairedProperty, | ||
$pairedClass, | ||
); | ||
|
||
parent::__construct($message); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
tests/src/Fixtures/MapAttribute/SomeObjectWithInvalidTargetDto.php
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Tests\Fixtures\MapAttribute; | ||
|
||
use Rekalogika\Mapper\Attribute\Map; | ||
|
||
class SomeObjectWithInvalidTargetDto | ||
{ | ||
#[Map(property: 'foo', class: SomeObject::class)] | ||
public ?string $targetPropertyA = null; | ||
} |
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