Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
85.71% covered (success)
85.71%
6 / 7
CRAP
81.82% covered (success)
81.82%
18 / 22
DataModel
0.00% covered (danger)
0.00%
0 / 1
85.71% covered (success)
85.71%
6 / 7
14.02
81.82% covered (success)
81.82%
18 / 22
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 addXMLEntityList
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 addXMLEntity
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 hasEntityByTableName
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 4
 getEntityByTableName
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
 update
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getEntityList
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;
use Siesta\XML\XMLEntity;
/**
 * @author Gregor Müller
 */
class DataModel
{
    /**
     * @var Entity[]
     */
    protected $entityList;
    /**
     * DataModel constructor.
     */
    public function __construct()
    {
        $this->entityList = [];
    }
    /**
     * @param XMLEntity[] $xmlEntityList
     */
    public function addXMLEntityList(array $xmlEntityList)
    {
        foreach ($xmlEntityList as $xmlEntity) {
            $this->addXMLEntity($xmlEntity);
        }
    }
    public function addXMLEntity(XMLEntity $xmlEntity)
    {
        $dataModelBuilder = new XMLEntityReader();
        $entity = new Entity($this);
        $dataModelBuilder->getEntity($entity, $xmlEntity);
        $this->entityList[] = $entity;
    }
    /**
     * @param string $tableName
     *
     * @return bool
     */
    public function hasEntityByTableName(string $tableName)
    {
        foreach ($this->entityList as $entity) {
            if ($entity->getTableName() === $tableName) {
                return true;
            }
        }
        return false;
    }
    /**
     * @param string $tableName
     *
     * @return Entity
     */
    public function getEntityByTableName(string $tableName = null)
    {
        foreach ($this->entityList as $entity) {
            if ($entity->getTableName() === $tableName) {
                return $entity;
            }
        }
        return null;
    }
    public function update()
    {
        foreach ($this->entityList as $entity) {
            $entity->update();
        }
    }
    /**
     * @return Entity[]
     */
    public function getEntityList()
    {
        return $this->entityList;
    }
}