-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create shared `DonorType` class to indicate usage in use case requests. Add types to AddDonationRequest and UpdateDonorRequest.
- Loading branch information
Showing
13 changed files
with
244 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare( strict_types = 1 ); | ||
|
||
namespace WMDE\Fundraising\DonationContext\Domain\Model; | ||
|
||
/** | ||
* @method static DonorType PERSON() | ||
* @method static DonorType COMPANY() | ||
* @method static DonorType ANONYMOUS() | ||
*/ | ||
class DonorType { | ||
|
||
private string $value; | ||
|
||
private const TYPES = [ | ||
'PERSON' => 'person', | ||
'COMPANY' => 'company', | ||
'ANONYMOUS' => 'anonymous' | ||
]; | ||
|
||
protected function __construct( $type ) { | ||
if ( !isset( self::TYPES[$type] ) ) { | ||
throw new \UnexpectedValueException( 'Invalid type: ' . $type ); | ||
} | ||
$this->value = $type; | ||
} | ||
|
||
public static function __callStatic( $name, $arguments ): DonorType { | ||
return new self( $name ); | ||
} | ||
|
||
public function __toString(): string { | ||
return self::TYPES[$this->value]; | ||
} | ||
|
||
public static function make( $value ): DonorType { | ||
$valueMap = array_flip( self::TYPES ); | ||
if ( !isset( $valueMap[$value] ) ) { | ||
throw new \UnexpectedValueException( 'Invalid value: ' . $value ); | ||
} | ||
return new self( $valueMap[$value] ); | ||
} | ||
|
||
public function is( DonorType $donorType ): bool { | ||
return $this->value === $donorType->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
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
Oops, something went wrong.