Skip to content

[Workflow] Fix error when we use ValueObject for the marking property #34294

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

Merged
merged 1 commit into from
Nov 8, 2019

Conversation

FabienSalles
Copy link
Contributor

@FabienSalles FabienSalles commented Nov 8, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #28203 #22031
License MIT

Fix Illegal offset type in MethodMarkingStore class when we use Value Object for
the marking property.

Now, we can avoid to use only a string an we can have a Subject class with a Value Object like this :

final class State
{
    public const DRAFT = 'draft';
    public const REVIEWED = 'reviewed';
    public const REJECTED = 'rejected';
    public const PUBLISHED = 'published';
            
     /** @var string */
    private $state;

    public function __construct(string $state)
    {
        // some validation
        $this->state = $state;
    }

    public function __toString()
     {
         return $this->state;
    }

    public static function Draft()
     {
         return new self(self::DRAFT);      
     }
    ...
}

final class Subject
{
    private $marking;

    public function __construct(State $marking = null)
    {
        $this->marking = $marking;
    }

    public function getMarking()
    {
        return $this->marking;
    }

    public function setMarking($marking)
    {
        $this->marking = $marking instanceof State ? $marking : new State($marking);
    }

Fix Illegal offset type when we use ValueObject instead of string for
the marking property symfony#28203 symfony#22031
@FabienSalles FabienSalles force-pushed the fix-illegal-offset-type branch from 99b5bb2 to 6570d5c Compare November 8, 2019 11:46
@FabienSalles FabienSalles changed the title Fix error when we use ValueObject for the marking property [Workflow] Fix error when we use ValueObject for the marking property Nov 8, 2019
Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for your first contribution

(note: failures are not related)

@nicolas-grekas
Copy link
Member

Thank you @FabienSalles.

nicolas-grekas added a commit that referenced this pull request Nov 8, 2019
…ng property (FabienSalles)

This PR was merged into the 4.3 branch.

Discussion
----------

[Workflow] Fix error when we use ValueObject for the marking property

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #28203 #22031
| License       | MIT

Fix Illegal offset type in `MethodMarkingStore` class when we use Value Object for
the marking property.

Now, we can avoid to use only a string an we can have a Subject class with a Value Object like this :
```php
final class State
{
    public const DRAFT = 'draft';
    public const REVIEWED = 'reviewed';
    public const REJECTED = 'rejected';
    public const PUBLISHED = 'published';

     /** @var string */
    private $state;

    public function __construct(string $state)
    {
        // some validation
        $this->state = $state;
    }

    public function __toString()
     {
         return $this->state;
    }

    public static function Draft()
     {
         return new self(self::DRAFT);
     }
    ...
}

final class Subject
{
    private $marking;

    public function __construct(State $marking = null)
    {
        $this->marking = $marking;
    }

    public function getMarking()
    {
        return $this->marking;
    }

    public function setMarking($marking)
    {
        $this->marking = $marking instanceof State ? $marking : new State($marking);
    }

```

Commits
-------

6570d5c Fix error when we use VO for the marking property
@nicolas-grekas nicolas-grekas merged commit 6570d5c into symfony:4.3 Nov 8, 2019
@lyrixx lyrixx added the Workflow label Nov 8, 2019
@fabpot fabpot mentioned this pull request Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants