Symbok @Data批注已导入,但字段似乎未使用它

时间:2019-06-25 15:06:07

标签: php symfony

我创建了实体类Employee.php,并希望字段在其中使用@Data注释。

我实际上已经尝试按照https://github.com/mtarld/symbok-bundle中的说明进行操作,其中包括使用默认配置(没有文件,因此我必须在config / packages /下创建)来编辑symbok.yaml。此外,我检查了作曲家是否正确添加了捆绑软件,并且一切似乎都正常。

Employee.php:

namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Mtarld\SymbokBundle\Annotation\Data;
use Mtarld\SymbokBundle\Annotation\ToString;

/**
 * @Data
 * @ToString
 * @ORM\Entity(repositoryClass="App\Repository\EmployeeRepository")
 */
class Employee
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @var int
     */
   private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @var string
     */
   private $firstName;

    /**
     * @ORM\Column(type="string", length=255)
     * @var string
     */
    private $lastName;
}

symbok.yaml:

symbok:
    # Namespaces that you wanna be processed
    namespaces:
        - 'App\Entity'
        - 'App\Model'

    # Cache activation (useful to disable it when developing)
    cache: ~

    defaults:
        # If setters are fluent by default (default false)
        fluent_setters: ~

        nullable:
            # If getters and setters use/return nullable parametes/values (default false)
            getter_setter: ~

            # If constructor uses nullable parameters (default true)
            constructor: ~

bundles.php:

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
    Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
    Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
    Mtarld\SymbokBundle\SymbokBundle::class => ['all' => true],
];

我所拥有的只是“未使用的私人领域。 此外,当我跑步时:  php bin /控制台学说:schema:update

我有:

在AnnotationException.php第54行中:

[语义错误]从未导入类App \ Entity \ Employee中的注释“ @Data”。您是否忘了为此注释添加“使用”语句?

1 个答案:

答案 0 :(得分:0)

我假设未使用的私有字段是PHPMD声明。如果是这种情况,只需在类顶部添加@SuppressWarnings(PHPMD.UnusedPrivateField)批注。

对于@Data注释错误,请尝试使用2.0版本。