Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
18 / 18 |
MySQLCustomStoredProcedure | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
18 / 18 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
buildElements | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
buildSignature | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
buildStatement | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
buildStatementForReplication | |
100.00% |
1 / 1 |
2 | |
100.00% |
0 / 0 |
<?php | |
declare(strict_types=1); | |
namespace Siesta\Driver\MySQL\StoredProcedure; | |
use Siesta\Database\MigrationStatementFactory; | |
use Siesta\Model\DataModel; | |
use Siesta\Model\Entity; | |
use Siesta\Model\StoredProcedure; | |
/** | |
* @author Gregor Müller | |
*/ | |
class MySQLCustomStoredProcedure extends MySQLStoredProcedureBase | |
{ | |
/** | |
* @var StoredProcedure | |
*/ | |
protected $storedProcedure; | |
/** | |
* MySQLCustomStoredProcedure constructor. | |
* | |
* @param DataModel $dataModel | |
* @param Entity $entity | |
* @param StoredProcedure $storedProcedure | |
*/ | |
public function __construct(DataModel $dataModel, Entity $entity, StoredProcedure $storedProcedure) | |
{ | |
parent::__construct($dataModel, $entity); | |
$this->storedProcedure = $storedProcedure; | |
$this->buildElements(); | |
} | |
/** | |
* @return void | |
*/ | |
protected function buildElements() | |
{ | |
$this->modifies = $this->storedProcedure->getModifies(); | |
$this->name = $this->storedProcedure->getDBName(); | |
$this->determineTableNames(); | |
$this->buildSignature(); | |
$this->buildStatement(); | |
} | |
/** | |
* @return void | |
*/ | |
protected function buildSignature() | |
{ | |
$parameterList = []; | |
foreach ($this->storedProcedure->getParameterList() as $parameter) { | |
$parameterList[] = $this->buildSignatureParameter($parameter->getSpName(), $parameter->getDbType()); | |
} | |
$this->signature = $this->buildSignatureFromList($parameterList); | |
} | |
/** | |
* @return void | |
*/ | |
protected function buildStatement() | |
{ | |
$sql = $this->storedProcedure->getStatement(); | |
$this->statement = str_replace(MigrationStatementFactory::TABLE_PLACE_HOLDER, $this->tableName, $sql); | |
} | |
/** | |
* @param string $sql | |
* | |
* @return void | |
*/ | |
protected function buildStatementForReplication($sql) | |
{ | |
// in case of modifying procedures execute on both tables | |
if ($this->modifies) { | |
$this->statement = str_replace(MigrationStatementFactory::TABLE_PLACE_HOLDER, $this->tableName, $sql); | |
$this->statement .= str_replace(MigrationStatementFactory::TABLE_PLACE_HOLDER, $this->replicationTableName, $sql); | |
return; | |
} | |
// in case of non modifying read from memory table only | |
$this->statement = str_replace(MigrationStatementFactory::TABLE_PLACE_HOLDER, $this->replicationTableName, $sql); | |
} | |
} |