Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
15 / 15
BatchSavePlugin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
15 / 15
 getUseClassNameList
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getDependantPluginList
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
0 / 0
 generate
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 generateBatchSave
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
11 / 11
<?php
declare(strict_types = 1);
namespace Siesta\GeneratorPlugin\ServiceClass;
use Siesta\CodeGenerator\CodeGenerator;
use Siesta\GeneratorPlugin\BasePlugin;
use Siesta\GeneratorPlugin\Entity\SavePlugin;
use Siesta\Model\Entity;
/**
 * @author Gregor Müller
 */
class BatchSavePlugin extends BasePlugin
{
    const METHOD_BATCH_SAVE = "batchSave";
    /**
     * @param Entity $entity
     *
     * @return string[]
     */
    public function getUseClassNameList(Entity $entity) : array
    {
        return [];
    }
    /**
     * @return string[]
     */
    public function getDependantPluginList() : array
    {
        return [];
    }
    /**
     * @param Entity $entity
     * @param CodeGenerator $codeGenerator
     */
    public function generate(Entity $entity, CodeGenerator $codeGenerator)
    {
        $this->setup($entity, $codeGenerator);
        $this->generateBatchSave();
    }
    /**
     *
     */
    protected function generateBatchSave()
    {
        $method = $this->codeGenerator->newPublicMethod(self::METHOD_BATCH_SAVE);
        $method->addParameter($this->entity->getInstantiationClassShortName() . '[]', 'entityList');
        $method->addConnectionNameParameter();
        // create the batch call
        $method->addLine('$batchCall = "";');
        $method->addForeachStart('$entityList as $entity');
        $method->addLine('$batchCall .= $entity->' . SavePlugin::METHOD_CREATE_SP_CALL_STATEMENT . '();');
        $method->addForeachEnd();
        $method->addConnectionLookup();
        $method->addLine('$connection->execute($batchCall);');
        $method->end();
    }
}