for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PhpUnitGen\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use PhpUnitGen\Model\ModelInterface\AttributeModelInterface;
use PhpUnitGen\Model\ModelInterface\TraitModelInterface;
/**
* Class TraitModel.
*
* @author Paul Thébaud <[email protected]>.
* @copyright 2017-2018 Paul Thébaud <[email protected]>.
* @license https://opensource.org/licenses/MIT The MIT license.
* @link https://github.com/paul-thebaud/phpunit-generator
* @since Class available since Release 2.0.0.
*/
class TraitModel extends InterfaceModel implements TraitModelInterface
{
* @var AttributeModelInterface[]|Collection $attributes Class attributes.
private $attributes;
* TraitModel constructor.
public function __construct()
parent::__construct();
$this->attributes = new ArrayCollection();
}
* {@inheritdoc}
public function addAttribute(AttributeModelInterface $attribute): void
$this->attributes->add($attribute);
public function hasAttribute(string $name): bool
return $this->attributes->exists(function (AttributeModelInterface $attribute) use ($name) {
return $attribute->getName() === $name;
});
public function getAttribute(string $name): ?AttributeModelInterface
foreach ($this->attributes as $attribute) {
if ($attribute->getName() === $name) {
return $attribute;
return null;
public function getAttributes(): Collection
return $this->attributes;