-
Notifications
You must be signed in to change notification settings - Fork 8
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 #75 from jolicode/fix/multiple-types
Types: better matching between types to better handle multiple types
- Loading branch information
Showing
45 changed files
with
523 additions
and
357 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
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
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
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
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Metadata; | ||
|
||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @extends \SplObjectStorage<Type, Type[]> | ||
*/ | ||
final class TypesMatching extends \SplObjectStorage | ||
{ | ||
public function getSourceUniqueType(): ?Type | ||
{ | ||
if (0 === \count($this) || \count($this) > 1) { | ||
return null; | ||
} | ||
|
||
// Get first type from the SplObjectStorage | ||
$this->rewind(); | ||
$sourceType = $this->current(); | ||
|
||
if (!$sourceType instanceof Type) { | ||
return null; | ||
} | ||
|
||
return $sourceType; | ||
} | ||
|
||
public function getTargetUniqueType(Type $sourceType): ?Type | ||
{ | ||
$targetTypes = $this[$sourceType] ?? []; | ||
|
||
if (0 === \count($targetTypes) || \count($targetTypes) > 1 || !$targetTypes[0] instanceof Type) { | ||
return null; | ||
} | ||
|
||
return $targetTypes[0]; | ||
} | ||
|
||
/** | ||
* @param Type[] $sourceTypes | ||
* @param Type[] $targetTypes | ||
*/ | ||
public static function fromSourceAndTargetTypes(array $sourceTypes, array $targetTypes): self | ||
{ | ||
$types = new self(); | ||
|
||
foreach ($sourceTypes as $sourceType) { | ||
$types[$sourceType] = $targetTypes; | ||
} | ||
|
||
return $types; | ||
} | ||
} |
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.