-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add relationship between countries and currencies (#100)
- Loading branch information
1 parent
76efd31
commit 9c64486
Showing
22 changed files
with
969 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Standards\Dev\DataTarget; | ||
|
||
class EnumMethod | ||
{ | ||
/** @var array<int|string, list<string>> */ | ||
private array $mapping = []; | ||
|
||
public function __construct( | ||
public readonly string $name, | ||
public readonly string $returnType, | ||
public readonly ?string $default, | ||
) { | ||
} | ||
|
||
public function addMapping(string $from, string $to): void | ||
{ | ||
if (array_key_exists($from, $this->mapping) && in_array($to, $this->mapping[$from], true) === true) { | ||
return; | ||
} | ||
|
||
$this->mapping[$from][] = $to; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
$mappingString = ''; | ||
$sortedMapping = $this->mapping; | ||
ksort($sortedMapping); | ||
|
||
foreach ($sortedMapping as $key => $values) { | ||
sort($values); | ||
|
||
if (count($values) <= 1) { | ||
$mappingString .= $key . ' => [' . implode(',', $values) . '],' . PHP_EOL; | ||
|
||
continue; | ||
} | ||
|
||
$mappingString .= $key . ' => [' . PHP_EOL . implode(',' . PHP_EOL, $values) . PHP_EOL . '],' . PHP_EOL; | ||
} | ||
|
||
if ($this->default !== null) { | ||
$mappingString .= 'default => ' . $this->default; | ||
} | ||
|
||
return <<<EOD | ||
public function {$this->name}(): {$this->returnType} | ||
{ | ||
return match(\$this) { | ||
{$mappingString} | ||
}; | ||
} | ||
EOD; | ||
} | ||
} |
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.