Skip to content
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

[AutoMapper] MappingExtractor::getWriteMutator() returns null if property is writable #666

Closed
ihmels opened this issue Oct 17, 2022 · 1 comment
Labels

Comments

@ihmels
Copy link

ihmels commented Oct 17, 2022

Jane version(s) affected: 7.3.1

Description
If no WriteMutator can be determined via MappingExtractor::getWriteMutator(), but the property is writable according to PropertyInfoExtractorInterface::isWriteable(), an error occurs in line 73 of SourceTargetMappingExtractor, because $targetMutatorConstruct is not checked for null.

How to reproduce

In the following code snippet there is the property Attribute::$values and the corresponding setter Attribute::setValues() (actually this should be called "setValue", but I made a typo).

The PropertyInfoExtractorInterface finds out with the ReflectionExtractor that AttributeValues can be added with addValues(), so PropertyInfoExtractorInterface:isWriteable() returns true, but MappingExtractor::getWriteMutator() return null.

class Attribute
{
    private Collection $values;

    public function __construct()
    {
        $this->values = new ArrayCollection();
    }

    /**
     * @return Collection<int, AttributeValue>
     */
    public function getValues(): Collection
    {
        return $this->values;
    }

    public function addValues(AttributeValue $values): void
    {
        if (!$this->values->contains($values)) {
            $this->values->add($values);
            $values->setAttribute($this);
        }
    }

    public function removeValues(AttributeValue $values): void
    {
        if ($this->values->removeElement($values)) {
            // set the owning side to null (unless already changed)
            if ($values->getAttribute() === $this) {
                $values->setAttribute(null);
            }
        }
    }
}

class AttributeValue {
    // ...
}
@Korbeil
Copy link
Member

Korbeil commented Sep 22, 2023

Switched to jolicode/automapper#3

@Korbeil Korbeil closed this as completed Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants