Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
24 / 24
MySQLSelectByPKStoredProcedure
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
5 / 5
9
100.00% covered (success)
100.00%
24 / 24
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 buildElements
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 getCreateProcedureStatement
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 buildSignature
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 buildStatement
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
7 / 7
<?php
declare(strict_types=1);
namespace Siesta\Driver\MySQL\StoredProcedure;
use Siesta\Database\StoredProcedureNaming;
use Siesta\Model\DataModel;
use Siesta\Model\Entity;
/**
 * @author Gregor Müller
 */
class MySQLSelectByPKStoredProcedure extends MySQLStoredProcedureBase
{
    /**
     * SelectStoredProcedure constructor.
     *
     * @param DataModel $model
     * @param Entity $entity
     */
    public function __construct(DataModel $model, Entity $entity)
    {
        parent::__construct($model, $entity);
        $this->buildElements();
    }
    /**
     * @return void
     */
    protected function buildElements()
    {
        $this->modifies = false;
        $this->name = StoredProcedureNaming::getSelectByPrimaryKeyName($this->entity);
        $this->determineTableNames();
        $this->buildSignature();
        $this->buildStatement();
    }
    /**
     * @return string|null
     */
    public function getCreateProcedureStatement()
    {
        if (!$this->entity->hasPrimaryKey()) {
            return null;
        }
        return parent::getCreateProcedureStatement();
    }
    /**
     * @return void
     */
    protected function buildSignature()
    {
        $parameterList = [];
        foreach ($this->entity->getPrimaryKeyAttributeList() as $attribute) {
            $parameterList[] = $this->buildSignatureParameter($attribute->getStoredProcedureParameterName(), $attribute->getDbType());
        }
        $this->signature = $this->buildSignatureFromList($parameterList);
    }
    /**
     * @return void
     */
    protected function buildStatement()
    {
        $whereList = [];
        foreach ($this->entity->getPrimaryKeyAttributeList() as $attribute) {
            $whereList[] = $this->buildWherePart($attribute);
        }
        $where = $this->buildWhereAndSnippet($whereList);
        $tableName = $this->isReplication ? $this->replicationTableName : $this->tableName;
        $this->statement = sprintf(self::SELECT_WHERE, $tableName, $where);
    }
}