Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (success)
75.00%
3 / 4
CRAP
96.00% covered (success)
96.00%
24 / 25
MySQLDeleteByReferenceStoredProcedure
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (success)
75.00%
3 / 4
7
96.00% covered (success)
96.00%
24 / 25
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 buildElements
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 buildSignature
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 buildStatement
0.00% covered (danger)
0.00%
0 / 1
3.01
88.89% covered (success)
88.89%
8 / 9
<?php
declare(strict_types=1);
namespace Siesta\Driver\MySQL\StoredProcedure;
use Siesta\Database\StoredProcedureNaming;
use Siesta\Model\DataModel;
use Siesta\Model\Entity;
use Siesta\Model\Reference;
/**
 * @author Gregor Müller
 */
class MySQLDeleteByReferenceStoredProcedure extends MySQLStoredProcedureBase
{
    /**
     * @var Reference
     */
    protected $reference;
    /**
     * SelectReferenceStoredProcedure constructor.
     *
     * @param DataModel $dataModel
     * @param Entity $entity
     * @param Reference $reference
     */
    public function __construct(DataModel $dataModel, Entity $entity, Reference $reference)
    {
        parent::__construct($dataModel, $entity);
        $this->reference = $reference;
        $this->buildElements();
    }
    /**
     * @return void
     */
    protected function buildElements()
    {
        $this->modifies = true;
        $this->name = StoredProcedureNaming::getDeleteByReferenceName($this->entity, $this->reference);
        $this->determineTableNames();
        $this->buildSignature();
        $this->buildStatement();
    }
    /**
     * @return void
     */
    protected function buildSignature()
    {
        $signatureList = [];
        foreach ($this->reference->getReferenceMappingList() as $referenceMapping) {
            $localAttribute = $referenceMapping->getLocalAttribute();
            $signatureList[] = $this->buildSignatureParameter($localAttribute->getStoredProcedureParameterName(), $localAttribute->getDbType());
        }
        $this->signature = $this->buildSignatureFromList($signatureList);
    }
    /**
     * @return void
     */
    protected function buildStatement()
    {
        $whereList = [];
        foreach ($this->reference->getReferenceMappingList() as $referenceMapping) {
            $localAttribute = $referenceMapping->getLocalAttribute();
            $whereList[] = $this->buildWherePart($localAttribute);
        }
        $where = $this->buildWhereAndSnippet($whereList);
        $this->statement = sprintf(self::DELETE_WHERE, $this->tableName, $where);
        if ($this->isReplication) {
            $this->statement .= sprintf(self::DELETE_WHERE, $this->delimitTable, $where);
        }
    }
}