8000 ERROR: "Property doesn't exist...". But it has not to exist! · Issue #309 · php-translation/symfony-bundle · GitHub
[go: up one dir, main page]

Skip to content

ERROR: "Property doesn't exist...". But it has not to exist! #309

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

Closed
Aerendir opened this issue Jun 3, 2019 · 5 comments
Closed

ERROR: "Property doesn't exist...". But it has not to exist! #309

Aerendir opened this issue Jun 3, 2019 · 5 comments

Comments

@Aerendir
Copy link
Aerendir commented Jun 3, 2019
In PropertyMetadata.php line 40:
                                                                               
  [Symfony\Component\Validator\Exception\ValidatorException]                   
  Property "read" does not exist in class "App\Entity\NotificationDevelopers"  
                                                                               

Exception trace:
 () at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/PropertyMetadata.php:40
 Symfony\Component\Validator\Mapping\PropertyMetadata->__construct() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/ClassMetadata.php:216
 Symfony\Component\Validator\Mapping\ClassMetadata->addPropertyConstraint() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php:106
 Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader->loadClassMetadata() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/LoaderChain.php:54
 Symfony\Component\Validator\Mapping\Loader\LoaderChain->loadClassMetadata() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php:105
 Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Validator/RecursiveValidator.php:83
 Symfony\Component\Validator\Validator\RecursiveValidator->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Validator/TraceableValidator.php:50
 Symfony\Component\Validator\Validator\TraceableValidator->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Visitor/Php/Symfony/ValidationAnnotation.php:74
 Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation->enterNode() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:200
 PhpParser\NodeTraverser->traverseArray() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
 PhpParser\NodeTraverser->traverseNode() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
 PhpParser\NodeTraverser->traverseArray() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:91
 PhpParser\NodeTraverser->traverse() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/FileExtractor/PHPFileExtractor.php:44
 Translation\Extractor\FileExtractor\PHPFileExtractor->getSourceLocations() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Extractor.php:106
 Translation\Extractor\Extractor->doExtract() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Extractor.php:39
 Translation\Extractor\Extractor->extract() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/symfony-bundle/Service/Importer.php:80
 Translation\Bundle\Service\Importer->extractToCatalogues() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/symfony-bundle/Command/ExtractCommand.php:114
 Translation\Bundle\Command\ExtractCommand->execute() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:939
 Symfony\Component\Console\Application->doRunCommand() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/framework-bundle/Console/Application.php:87
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/framework-bundle/Console/Application.php:73
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/bin/console:42

This is the first error and is caused by this class:

<?php

declare(strict_types=1);

namespace App\Entity;

use BadMethodCallException;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Monolog\Logger;
use function Safe\sprintf;

/**
 * @ORM\MappedSuperclass()
 */
class NotificationAbstract
{
    ...

    /**
     * @var bool
     *
     * @ORM\Column(name="read", type="boolean", nullable=false)
     */
    private $read = false;

    ...

    /**
     * @return bool
     */
    public function isRead(): bool
    {
        return $this->read;
    }

    ...

    /**
     * @param bool $isRead
     *
     * @return NotificationAbstract
     */
    public function setRead(bool $isRead = false): self
    {
        $this->read = $isRead;

        return $this;
    }
}

As you can see, the property NotificationAbstract::$read exists, but the error says it doesn't.

To fix this I have to change the visibility from private to protected and error goes away.

But at this point another one arises:

In PropertyMetadata.php line 40:
                                                                                                
  [Symfony\Component\Validator\Exception\ValidatorException]                                    
  Property "newFeedback" does not exist in class "App\Entity\Embeddable\ScoresEmbeddable"  
                                                                                                

Exception trace:
 () at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/PropertyMetadata.php:40
 Symfony\Component\Validator\Mapping\PropertyMetadata->__construct() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/ClassMetadata.php:216
 Symfony\Component\Validator\Mapping\ClassMetadata->addPropertyConstraint() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php:153
 Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader->handleAllConstraint() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php:103
 Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader->loadClassMetadata() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/LoaderChain.php:54
 Symfony\Component\Validator\Mapping\Loader\LoaderChain->loadClassMetadata() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php:105
 Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Validator/RecursiveValidator.php:83
 Symfony\Component\Validator\Validator\RecursiveValidator->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Validator/TraceableValidator.php:50
 Symfony\Component\Validator\Validator\TraceableValidator->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Visitor/Php/Symfony/ValidationAnnotation.php:74
 Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation->enterNode() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:200
 PhpParser\NodeTraverser->traverseArray() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
 PhpParser\NodeTraverser->traverseNode() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
 PhpParser\NodeTraverser->traverseArray() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:91
 PhpParser\NodeTraverser->traverse() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/FileExtractor/PHPFileExtractor.php:44
 Translation\Extractor\FileExtractor\PHPFileExtractor->getSourceLocations() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Extractor.php:106
 Translation\Extractor\Extractor->doExtract() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Extractor.php:39
 Translation\Extractor\Extractor->extract() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/symfony-bundle/Service/Importer.php:80
 Translation\Bundle\Service\Importer->extractToCatalogues() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/symfony-bundle/Command/ExtractCommand.php:114
 Translation\Bundle\Command\ExtractCommand->execute() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:939
 Symfony\Component\Console\Application->doRunCommand() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/framework-bundle/Console/Application.php:87
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/framework-bundle/Console/Application.php:73
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/bin/console:42

The class that produces it is this:

<?php

declare(strict_types=1);

namespace App\Entity\Embeddable;

use App\Entity\Feedback;
use Doctrine\ORM\Mapping as ORM;

class ScoresEmbeddable
{
    /**
     * @param Feedback $feedback
     */
    public function addNewFeedback(Feedback $feedback): void
    {
        if (
            null !== $feedback->getScore() &&
            null !== $feedback->getConformity() &&
            null !== $feedback->getCustomerCare() &&
            null !== $feedback->getShippingTimes() &&
            null !== $feedback->getShippingCosts()
        ) {
            $this->registerScore($feedback->getScore());

            // Calculate the average valuation
            $this->addValuations(
                $feedback->getConformity(),
                $feedback->getCustomerCare(),
                $feedback->getShippingTimes(),
                $feedback->getShippingCosts()
            );
        }
    }
}

So, now the extractor thinks that as I have a method addNewFeedback(), then I have to have also a property called newFeedback: but this is not true.

The method actually only does a calculation using the passed feedback and does not set any newFeedback property anywhere.

But, lets say I want to fix it: I change the method from addNewFeedback() to registerNewFeedback().

But now the uncontrollable happens:

In PropertyMetadata.php line 40:
                                                                   
  [Symfony\Component\Validator\Exception\ValidatorException]       
  Property "superAdmin" does not exist in class "App\Entity\User"  
                                                                   

Exception trace:
 () at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/PropertyMetadata.php:40
 Symfony\Component\Validator\Mapping\PropertyMetadata->__construct() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/ClassMetadata.php:216
 Symfony\Component\Validator\Mapping\ClassMetadata->addPropertyConstraint() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php:106
 Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader->loadClassMetadata() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Loader/LoaderChain.php:54
 Symfony\Component\Validator\Mapping\Loader\LoaderChain->loadClassMetadata() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php:105
 Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Validator/RecursiveValidator.php:83
 Symfony\Component\Validator\Validator\RecursiveValidator->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/validator/Validator/TraceableValidator.php:50
 Symfony\Component\Validator\Validator\TraceableValidator->getMetadataFor() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Visitor/Php/Symfony/ValidationAnnotation.php:74
 Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation->enterNode() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:200
 PhpParser\NodeTraverser->traverseArray() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
 PhpParser\NodeTraverser->traverseNode() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
 PhpParser\NodeTraverser->traverseArray() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:91
 PhpParser\NodeTraverser->traverse() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/FileExtractor/PHPFileExtractor.php:44
 Translation\Extractor\FileExtractor\PHPFileExtractor->getSourceLocations() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Extractor.php:106
 Translation\Extractor\Extractor->doExtract() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/extractor/src/Extractor.php:39
 Translation\Extractor\Extractor->extract() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/symfony-bundle/Service/Importer.php:80
 Translation\Bundle\Service\Importer->extractToCatalogues() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/php-translation/symfony-bundle/Command/ExtractCommand.php:114
 Translation\Bundle\Command\ExtractCommand->execute() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:939
 Symfony\Component\Console\Application->doRunCommand() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/framework-bundle/Console/Application.php:87
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/framework-bundle/Console/Application.php:73
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /Users/Aerendir/Documents/JooServer/_Projects/Coommercio/Apps/app-trust-back-me-www/bin/console:42

The presupposed property superAdmin is actually a method in the User model from FOSUserBundle:

class User {
    ...

    /**
     * {@inheritdoc}
     */
    public function setSuperAdmin($boolean)
    {
        if (true === $boolean) {
            $this->addRole(static::ROLE_SUPER_ADMIN);
        } else {
            $this->removeRole(static::ROLE_SUPER_ADMIN);
        }

        return $this;
    }

    ...
}

So, there is no property superAdmin but the extractor thinks it exists and throws an error as it cannot find it.

I think the problem is related to a behavior very similar to the one of ReflectionExtractor of Symfony's PropertyInfo component: practically that class uses accessors and mutators method to derive the list of properties and so, if we have a method like setSuperAdmin(), it suppose there is also a property called superAdmin and this is, obviously, not true.

Anyway, for me, is now impossible to extract translations: any ideas?

@xabbuh
Copy link
xabbuh commented Jun 5, 2019

This is probably fixed by symfony/symfony#31836.

@Aerendir
Copy link
Author
Aerendir commented Jun 5, 2019

@xabbuh I hope it will! But I have to wait the release 4.3.1, have I?

@xabbuh
Copy link
xabbuh commented Jun 5, 2019

You can require symfony/doctrine-bridge with a version constraint like 4.3.*@dev to test it.

@Aerendir
Copy link
Author
Aerendir commented Jun 5, 2019

@xabbuh yes, this fixed the issue! 🎉Thank you!

@Aerendir Aerendir closed this as completed Jun 5, 2019
@xabbuh
Copy link
xabbuh commented Jun 5, 2019

👍 thank you for the feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0