-
Notifications
You must be signed in to change notification settings - Fork 1
✨ v6 #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lennyrouanet
wants to merge
13
commits into
main
Choose a base branch
from
✨-v6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "\u2728-v6"
Open
✨ v6 #47
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ddd500
✨ Readonly class
lennyrouanet 9ea804b
CS
lennyrouanet 61bc770
♻️ readonly class
lennyrouanet 6c2f762
♻️ version PHP
lennyrouanet 96cea1b
♻️ Update JWT
lennyrouanet 5e13595
⬆️ php stan
lennyrouanet 1021389
♻️ Translate
lennyrouanet 2d092db
✨ EUID
lennyrouanet b466ae7
✅ tests
lennyrouanet aabca04
💬 Exception message
lennyrouanet f55860b
♻️ CS
lennyrouanet 8ec4d72
♻️ Duration
lennyrouanet 2c735b0
Update component/Time/Duration.php
lennyrouanet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,79 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Phant\DataStructure\Company; | ||
|
|
||
| use Phant\DataStructure\Company\Fr\Siren; | ||
| use Phant\Error\NotCompliant; | ||
|
|
||
| readonly class Euid extends \Phant\DataStructure\Abstract\Value\Varchar | ||
| { | ||
| public const PATTERN = '/^(\D{2})(\w+)(\.)(\w+)$/'; | ||
| private const COUNTRY_CODES = ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK']; | ||
|
|
||
|
|
||
| public function __construct( | ||
| string $euid, | ||
| bool $check = true | ||
| ) { | ||
| parent::__construct($euid); | ||
|
|
||
| $parts = $this->extractParts(); | ||
|
|
||
| if (!$parts->countryCode || !in_array($parts->countryCode, self::COUNTRY_CODES)) { | ||
| throw new NotCompliant('Not compliant country code'); | ||
| } | ||
|
|
||
| if ($check) { | ||
| match ($parts->countryCode) { | ||
| 'FR' => new Siren($parts->companyCode), | ||
| default => null, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| public function getFormatted( | ||
| bool $nonBreakingSpace = true | ||
| ): string { | ||
| $parts = $this->extractParts(); | ||
|
|
||
| $euid = implode(' ', [ | ||
| $parts->countryCode, | ||
| $parts->registryCode, | ||
| $parts->separator, | ||
| self::formatCompanyCode($parts->companyCode), | ||
| ]); | ||
|
|
||
| if ($nonBreakingSpace) { | ||
| $euid = str_replace(' ', "\xC2\xA0", $euid); // non breaking space | ||
| } | ||
|
|
||
| return $euid; | ||
| } | ||
|
|
||
| public function extractParts( | ||
| ): object { | ||
| preg_match('/^(\D{2})(\w+)(\.)(\w+)$/', $this->value, $matches); | ||
|
|
||
| return (object) [ | ||
| 'countryCode' => $matches[1] ?? null, | ||
| 'registryCode' => $matches[2] ?? null, | ||
| 'separator' => $matches[3] ?? null, | ||
| 'companyCode' => $matches[4] ?? null, | ||
| ]; | ||
| } | ||
|
|
||
| private static function formatCompanyCode( | ||
| string $companyCode | ||
| ): string { | ||
| return match (strlen($companyCode)) { | ||
| 5 => preg_replace('/^(\d{2})(\d{3})$/', '$1 $2', $companyCode), | ||
| 6 => preg_replace('/^(\d{3})(\d{3})$/', '$1 $2', $companyCode), | ||
| 7 => preg_replace('/^(\d{3})(\d{4})$/', '$1 $2', $companyCode), | ||
| 8 => preg_replace('/^(\d{2})(\d{3})(\d{3})$/', '$1 $2 $3', $companyCode), | ||
| 9 => preg_replace('/^(\d{3})(\d{3})(\d{3})$/', '$1 $2 $3', $companyCode), | ||
| default => $companyCode, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is declared as readonly, but properties 'time', 'date', and 'format' need to be assigned in the constructor body (lines 33-35 which are outside the diff region). This is incompatible with readonly classes in PHP 8.2+ where properties can only be initialized via promoted constructor parameters or at declaration. Consider removing the readonly keyword from the class declaration or refactoring the initialization logic.