Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
27 / 27
MemberPlugin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
11
100.00% covered (success)
100.00%
27 / 27
 getUseClassNameList
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
10 / 10
 getDependantPluginList
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
0 / 0
 generate
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
17 / 17
<?php
declare(strict_types = 1);
namespace Siesta\GeneratorPlugin\Entity;
use Siesta\CodeGenerator\CodeGenerator;
use Siesta\GeneratorPlugin\BasePlugin;
use Siesta\Model\Entity;
/**
 * @author Gregor Müller
 */
class MemberPlugin extends BasePlugin
{
    /**
     * @param Entity $entity
     *
     * @return string[]
     */
    public function getUseClassNameList(Entity $entity) : array
    {
        $useList = [];
        foreach ($entity->getAttributeList() as $attribute) {
            if ($attribute->getPhpType() === "SiestaDateTime") {
                $useList[] = 'Siesta\Util\SiestaDateTime';
            }
            if ($attribute->getClassName() !== null) {
                $useList[] = $attribute->getClassName();
            }
        }
        foreach ($entity->getReferenceList() as $reference) {
            $foreignEntity = $reference->getForeignEntity();
            $useList[] = $foreignEntity->getClassName();
        }
        return $useList;
    }
    /**
     * @return string[]
     */
    public function getDependantPluginList() : array
    {
        return [];
    }
    /**
     * @param Entity $entity
     * @param CodeGenerator $codeGenerator
     */
    public function generate(Entity $entity, CodeGenerator $codeGenerator)
    {
        $codeGenerator->addProtectedMember("_existing", "bool");
        $codeGenerator->addProtectedMember("_rawJSON", "array");
        $codeGenerator->addProtectedMember("_rawSQLResult", "array");
        foreach ($entity->getAttributeList() as $attribute) {
            $codeGenerator->addProtectedMember($attribute->getPhpName(), $attribute->getPhpType());
        }
        foreach ($entity->getReferenceList() as $reference) {
            $foreignEntity = $reference->getForeignEntity();
            $codeGenerator->addProtectedMember($reference->getName(), $foreignEntity->getClassShortName());
        }
        foreach ($entity->getCollectionList() as $collection) {
            $foreignEntity = $collection->getForeignEntity();
            $codeGenerator->addProtectedMember($collection->getName(), $foreignEntity->getInstantiationClassShortName() . '[]');
        }
        foreach ($entity->getCollectionManyList() as $collectionMany) {
            $foreignEntity = $collectionMany->getForeignEntity();
            $codeGenerator->addProtectedMember($collectionMany->getName(), $foreignEntity->getInstantiationClassShortName() . '[]');
            $mappingEntity = $collectionMany->getMappingEntity();
            $codeGenerator->addProtectedMember($collectionMany->getName() . 'Mapping', $mappingEntity->getInstantiationClassShortName() . '[]');
        }
    }
}