Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
22 / 22
Collection
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
11 / 11
13
100.00% covered (success)
100.00%
22 / 22
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 update
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
7 / 7
 getName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getMethodName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getForeignTable
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setForeignTable
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getForeignReferenceName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setForeignReferenceName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getForeignEntity
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getForeignReference
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
declare(strict_types = 1);
namespace Siesta\Model;
/**
 * @author Gregor Müller
 */
class Collection
{
    /**
     * @var DataModel
     */
    protected $datamodel;
    /**
     * @var Entity
     */
    protected $entity;
    /**
     * @var string
     */
    protected $name;
    /**
     * @var string
     */
    protected $foreignTable;
    /**
     * @var string
     */
    protected $foreignReferenceName;
    /**
     * @var Entity
     */
    protected $foreignEntity;
    /**
     * @var Reference
     */
    protected $foreignReference;
    /**
     * Collection constructor.
     *
     * @param DataModel $dataModel
     * @param Entity $entity
     */
    public function __construct(DataModel $dataModel, Entity $entity)
    {
        $this->datamodel = $dataModel;
        $this->entity = $entity;
    }
    /**
     *
     */
    public function update()
    {
        $this->foreignEntity = $this->datamodel->getEntityByTableName($this->getForeignTable());
        if ($this->foreignEntity === null) {
            return;
        }
        $this->foreignReference = $this->foreignEntity->getReferenceByName($this->getForeignReferenceName());
        if ($this->foreignReference !== null) {
            $this->foreignReference->setCollectionRefersTo();
        }
    }
    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
    /**
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }
    /**
     * @return string
     */
    public function getMethodName()
    {
        return ucfirst($this->getName());
    }
    /**
     * @return string
     */
    public function getForeignTable()
    {
        return $this->foreignTable;
    }
    /**
     * @param string $foreignTable
     */
    public function setForeignTable($foreignTable)
    {
        $this->foreignTable = $foreignTable;
    }
    /**
     * @return string
     */
    public function getForeignReferenceName()
    {
        return $this->foreignReferenceName;
    }
    /**
     * @param string $foreignReferenceName
     */
    public function setForeignReferenceName($foreignReferenceName)
    {
        $this->foreignReferenceName = $foreignReferenceName;
    }
    /**
     * @return Entity|null
     */
    public function getForeignEntity()
    {
        return $this->foreignEntity;
    }
    /**
     * @return Reference|null
     */
    public function getForeignReference()
    {
        return $this->foreignReference;
    }
}