<commit_before><?php

namespace JS\Service;

use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use JS\Exception\BaseException;

class BaseService implements ServiceLocatorAwareInterface {

    protected $entity;
    protected $entityName;

    /**
     * Entity manager
     * @var \Doctrine\ORM\EntityManager
     */
    protected $entityManager;

    /**
     * @var \Zend\ServiceManager\ServiceLocatorInterface
     */
    protected $serviceLocator;
    protected $translator;

    /**
     * Set up base BaseService options
     *
     * @param \Doctrine\ORM\EntityManager $em
     * @return void
     */
    public function __construct($em, $translator = null, $entityName = null) {
        $this->setEntityManager($em);
        $this->setEntityName($entityName);
        $this->setTranslator($translator);
    }

    /**
     * Find object by id in repository
     * @param int @id id of an object
     * @return Doctrine\ORM\Mapping\Entity
     */
    protected function find($id) {
        return $this->getRepository()->find($id);
    }

    /**
     * Find object reference by id in repository
     * @param int @id id of an object
     * @return Doctrine\ORM\Mapping\Entity
     */
    protected function getReference($id) {
        return $this->getEntityManager()->getReference($this->getEntityName(), $id);
    }

    /**
     * @return \Doctrine\ORM\EntityRepository
     */
    public function getRepository() {
        return $this->getEntityManager()->getRepository($this->entityName);
    }

    public function create($entity) {
        try {
            $this->getEntityManager()->persist($entity);
            $this->getEntityManager()->flush();
            return $entity;
        } catch (\Exception $ex) {
            $this->chooseHandleTransactionException($ex);
        }
    }

    public function update($entity) {
        try {
            $this->getEntityManager()->persist($entity);
            $this->getEntityManager()->flush();
            return $entity;
        } catch (\Exception $ex) {
            $this->chooseHandleTransactionException($ex);
        }
    }

    public function remove($data = array()) {
        try {
            $this->entity = $this->getRepository()->findOneBy($data);
            if ($this->entity) {
                $this->getEntityManager()->remove($this->entity);
                $this->getEntityManager()->flush();
                return $this->entity;
            } else
                throw new BaseException($this->getTranslator()->translate('e_entity_not_found'), BaseException::ERROR_ENTITY_NOT_EXIST);
        } catch (\Exception $ex) {
            $this->chooseHandleTransactionException($ex);
        }<commit_msg>fix update function -> exchange persist <> merge<commit_after><?php

namespace JS\Service;

use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use JS\Exception\BaseException;

class BaseService implements ServiceLocatorAwareInterface {

    protected $entity;
    protected $entityName;

    /**
     * Entity manager
     * @var \Doctrine\ORM\EntityManager
     */
    protected $entityManager;

    /**
     * @var \Zend\ServiceManager\ServiceLocatorInterface
     */
    protected $serviceLocator;
    protected $translator;

    /**
     * Set up base BaseService options
     *
     * @param \Doctrine\ORM\EntityManager $em
     * @return void
     */
    public function __construct($em, $translator = null, $entityName = null) {
        $this->setEntityManager($em);
        $this->setEntityName($entityName);
        $this->setTranslator($translator);
    }

    /**
     * Find object by id in repository
     * @param int @id id of an object
     * @return Doctrine\ORM\Mapping\Entity
     */
    protected function find($id) {
        return $this->getRepository()->find($id);
    }

    /**
     * Find object reference by id in repository
     * @param int @id id of an object
     * @return Doctrine\ORM\Mapping\Entity
     */
    protected function getReference($id) {
        return $this->getEntityManager()->getReference($this->getEntityName(), $id);
    }

    /**
     * @return \Doctrine\ORM\EntityRepository
     */
    public function getRepository() {
        return $this->getEntityManager()->getRepository($this->entityName);
    }

    public function create($entity) {
        try {
            $this->getEntityManager()->persist($entity);
            $this->getEntityManager()->flush();
            return $entity;
        } catch (\Exception $ex) {
            $this->chooseHandleTransactionException($ex);
        }
    }

    public function update($entity) {
        try {
            $this->getEntityManager()->merge($entity);
            $this->getEntityManager()->flush();
            return $entity;
        } catch (\Exception $ex) {
            $this->chooseHandleTransactionException($ex);
        }
    }

    public function remove($data = array()) {
        try {
            $this->entity = $this->getRepository()->findOneBy($data);
            if ($this->entity) {
                $this->getEntityManager()->remove($this->entity);
                $this->getEntityManager()->flush();
                return $this->entity;
            } else
                throw new BaseException($this->getTranslator()->translate('e_entity_not_found'), BaseException::ERROR_ENTITY_NOT_EXIST);
        } catch (\Exception $ex) {
            $this->chooseHandleTransactionException($ex);
        }
{'fraction_non_alphanumeric': 0.13190795433955427, 'fraction_numerical': 0.0, 'mean_word_length': 2.380281690140845, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 73, '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': '793599', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1451, 'n_words': 293}