-
Notifications
You must be signed in to change notification settings - Fork 31
Refactor attribute type system to use enums and manage dynamic list attributes table names #369
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
TatevikGr
wants to merge
14
commits into
main
Choose a base branch
from
dev
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.
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1dbb679
Rename classes/functions
tatevikg1 d750c73
DynamicListAttrManager
tatevikg1 360b3dd
coderabbitai
tatevikg1 e91e5ad
Fix createTable
tatevikg1 d7502dc
After review 0
tatevikg1 e760472
After review 1
tatevikg1 1c0b58d
After review 2
tatevikg1 14ca832
DynamicTableMessageHandler
tatevikg1 d0e50ad
Code rabbit config
tatevikg1 f1bd033
After review 3
tatevikg1 229ca78
Move enum to common
tatevikg1 b160bf7
Refactor
tatevikg1 6b19b00
StaticAccess
tatevikg1 ee2646b
test fix
tatevikg1 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
19 changes: 19 additions & 0 deletions
19
src/Domain/Subscription/Exception/AttributeTypeChangeNotAllowed.php
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,19 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\Core\Domain\Subscription\Exception; | ||
|
|
||
| use RuntimeException; | ||
|
|
||
| class AttributeTypeChangeNotAllowed extends RuntimeException | ||
| { | ||
| public function __construct(string $oldType, string $newType) | ||
| { | ||
| parent::__construct(sprintf( | ||
| 'attribute_definition.type_change_not_allowed:%s->%s', | ||
| $oldType, | ||
| $newType | ||
| )); | ||
| } | ||
| } |
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,56 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\Core\Domain\Subscription\Model; | ||
|
|
||
| use PhpList\Core\Domain\Subscription\Exception\AttributeTypeChangeNotAllowed; | ||
|
|
||
| enum AttributeTypeEnum: string | ||
| { | ||
| case Text = 'text'; | ||
| case Number = 'number'; | ||
| case Date = 'date'; | ||
| case Select = 'select'; | ||
| case Checkbox = 'checkbox'; | ||
| case MultiSelect = 'multiselect'; | ||
| case CheckboxGroup = 'checkboxgroup'; | ||
| case Radio = 'radio'; | ||
|
|
||
| public function equals(self $other): bool | ||
| { | ||
| return $this === $other; | ||
| } | ||
|
|
||
| public function isMultiValued(): bool | ||
| { | ||
| return match ($this) { | ||
| self::Select, | ||
| self::Checkbox, | ||
| self::MultiSelect, | ||
| self::Radio, | ||
| self::CheckboxGroup => true, | ||
| default => false, | ||
| }; | ||
| } | ||
|
|
||
| public function canTransitionTo(self $toType): bool | ||
| { | ||
| if ($this === $toType) { | ||
| return true; | ||
| } | ||
|
|
||
| if ($this->isMultiValued() !== $toType->isMultiValued()) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public function assertTransitionAllowed(self $toType): void | ||
| { | ||
| if (!$this->canTransitionTo($toType)) { | ||
| throw new AttributeTypeChangeNotAllowed($this->value, $toType->value); | ||
| } | ||
| } | ||
| } |
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,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\Core\Domain\Subscription\Model\Dto; | ||
|
|
||
| use InvalidArgumentException; | ||
| use Symfony\Component\Serializer\Annotation\SerializedName; | ||
|
|
||
| class DynamicListAttrDto | ||
| { | ||
| public readonly ?int $id; | ||
|
|
||
| public readonly string $name; | ||
|
|
||
| #[SerializedName('listorder')] | ||
| public readonly ?int $listOrder; | ||
|
|
||
| public function __construct( | ||
| ?int $id, | ||
| string $name, | ||
| ?int $listOrder = null | ||
| ) { | ||
| $trimmed = trim($name); | ||
| if ($trimmed === '') { | ||
| throw new InvalidArgumentException('Option name cannot be empty'); | ||
| } | ||
|
|
||
| $this->id = $id; | ||
| $this->name = $trimmed; | ||
| $this->listOrder = $listOrder; | ||
| } | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.