<commit_before><?php
/**
 * PHP version 5
 *
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
 */
namespace Mandragora\Gateway\Doctrine;

use Mandragora\Gateway\GatewayInterface;
use Doctrine_Record;
use Mandragora\Model\AbstractModel;
use Mandragora\StringObject;

/**
 * Base class for Doctrine gateway objects
 */
abstract class DoctrineGateway implements GatewayInterface
{
    /**
     * @var Doctrine_Record
     */
    protected $dao;

    /**
     * @var string
     */
    protected $alias;

    /**
     * @var boolean
     */
    protected $clearRelated = false;

    /**
     * @param Doctrine_Record $dao
     */
    public function __construct(Doctrine_Record $dao)
    {
      $this->dao = $dao;
    }

    /**
     * @param string $alias = null
     * @return string
     */
    protected function alias($alias = null)
    {
        if (!$this->alias) {
            $name = new StringObject(get_class($this));
            $daoName = $name->replace('Gateway', 'Dao') . 'Dao';
            if ($alias === null) {
                $name->setValue($daoName);
                $alias = $name->subString($name->indexOf('Dao\\') + 4, 1)->toLower();
            }
            $this->alias = $daoName . ' ' . $alias;
        }
        return $this->alias;
    }

    /**
     * @return void
     */
    public function clearRelated()
    {
        $this->clearRelated = true;
    }

    public function insert(AbstractModel $model)
    {
        $this->save($model);
    }

    public function update(AbstractModel $model)
    {
        $this->dao->assignIdentifier($model->getIdentifier());
        $this->save($model);
    }

    protected function save(AbstractModel $model)
    {
        $model->version += 1;
        $this->dao->fromArray($model->toArray(true));
        if ($this->clearRelated) {
            $this->dao->clearRelated();<commit_msg>Add logic to get the proper alias using the Gateway suffix.<commit_after><?php
/**
 * PHP version 5
 *
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
 */
namespace Mandragora\Gateway\Doctrine;

use Mandragora\Gateway\GatewayInterface;
use Doctrine_Record;
use Mandragora\Model\AbstractModel;
use Mandragora\StringObject;

/**
 * Base class for Doctrine gateway objects
 */
abstract class DoctrineGateway implements GatewayInterface
{
    /**
     * @var Doctrine_Record
     */
    protected $dao;

    /**
     * @var string
     */
    protected $alias;

    /**
     * @var boolean
     */
    protected $clearRelated = false;

    /**
     * @param Doctrine_Record $dao
     */
    public function __construct(Doctrine_Record $dao)
    {
      $this->dao = $dao;
    }

    protected function alias(string $alias = null): string
    {
        if (!$this->alias) {
            $name = new StringObject(get_class($this));
            if ($name->endsWith('Gateway')) {
                $daoName = $name->replace('Gateway', 'Dao');
            } else {
                $daoName = $name->replace('Gateway', 'Dao') . 'Dao';
            }
            if ($alias === null) {
                $name->setValue($daoName);
                $alias = $name->subString($name->indexOf('Dao\\') + 4, 1)->toLower();
            }
            $this->alias = $daoName . ' ' . $alias;
        }

        return $this->alias;
    }

    /**
     * @return void
     */
    public function clearRelated()
    {
        $this->clearRelated = true;
    }

    public function insert(AbstractModel $model)
    {
        $this->save($model);
    }

    public function update(AbstractModel $model)
    {
        $this->dao->assignIdentifier($model->getIdentifier());
        $this->save($model);
    }

    protected function save(AbstractModel $model)
    {
        $model->version += 1;
        $this->dao->fromArray($model->toArray(true));
        if ($this->clearRelated) {
            $this->dao->clearRelated();
{'fraction_non_alphanumeric': 0.14184576485461442, 'fraction_numerical': 0.00202275600505689, 'mean_word_length': 2.1051805337519625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '524755', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1161, 'n_words': 261}