<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Hydrator;

use BrBundle\Entity\Company as CompanyEntity,
    BrBundle\Entity\Company\Page as PageEntity;

/**
 * This hydrator hydrates/extracts Company data.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Company extends \CommonBundle\Component\Hydrator\Hydrator
{
    /**
     * @static @var string[] Key attributes to hydrate using the standard method.
     */
    private static $std_keys = array('name', 'vat_number', 'phone_number', 'website', 'sector');

    protected function doHydrate(array $data, $object = null)
    {
        if (null === $object) {
            $object = new CompanyEntity();
        }

        $object->setAddress(
            $this->getHydrator('CommonBundle\Hydrator\General\Address')
                ->hydrate($data['address'], $object->getAddress())
        );

        $years = array();
        $archiveYears = array();
        if (count($data['cvbook']) > 0) {
            $repository = $this->getEntityManager()
                ->getRepository('CommonBundle\Entity\General\AcademicYear');
            foreach ($data['cvbook'] as $yearId) {
                if (strpos($yearId, 'archive-') === 0) {
                    $archiveYears[] = substr($yearId, strlen('archive-'));
                } else {
                    $years[] = $repository->findOneById(substr($yearId, strlen('year-')));
                }
            }
        }

        $object->setCvBookYears($years);
        $object->setCvBookArchiveYears($archiveYears);

        $years = array();
        if (count($data['page']['years']) > 0) {
            $yearIds = $data['page']['years'];
            $repository = $this->getEntityManager()
                ->getRepository('CommonBundle\Entity\General\AcademicYear');
            foreach ($yearIds as $yearId) {
                $years[] = $repository->findOneById($yearId);
            }
        }

        if (null === $object->getPage()) {
            $object->setPage(
                new PageEntity(
                    $object
                )
            );
            $this->getEntityManager()->persist($object->getPage());
        }

        $object->getPage()->setYears($years)
            ->setSummary($data['page']['summary'])
            ->setDescription($data['page']['description']);

        return $this->stdHydrate($data, $object, self::$std_keys);
    }

    protected function doExtract($object = null)
    {
        if (null === $object) {
            return array();
        }

        $data = $this->stdExtract($object, self::$std_keys);

        $data['cvbook'] = array();
        foreach ($object->getCvBookYears() as $year) {
            $data['cvbook'][] = 'year-' . $year->getId();
        }

        foreach ($object->getCvBookArchiveYears() as $year) {
            $data['cvbook'][] = 'archive-' . $year->getId();
        }

        $data['address'] = $this->getHydrator('CommonBundle\Hydrator\General\Address')
            ->extract($object->getAddress());

        $page = $object->getPage();
        if (null !== $page) {
            $data['page']['years'] = array();
            foreach ($page->getYears() as $year) {
                $data['page']['years'][] = $year->getId();
            }
            $data['page']['summary'] = $page->getSummary();
            $data['page']['description'] = $page->getDescription();
        }

        return $data;<commit_msg>bugfix<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Hydrator;


use BrBundle\Entity\Company as CompanyEntity,
    BrBundle\Entity\Company\Page as PageEntity;

/**
 * This hydrator hydrates/extracts Company data.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Company extends \CommonBundle\Component\Hydrator\Hydrator
{
    /**
     * @static @var string[] Key attributes to hydrate using the standard method.
     */
    private static $std_keys = array('name', 'vat_number', 'phone_number', 'website', 'sector');

    protected function doHydrate(array $data, $object = null)
    {
        if (null === $object) {
            $object = new CompanyEntity();
        }

        $object->setAddress(
            $this->getHydrator('CommonBundle\Hydrator\General\Address')
                ->hydrate($data['address'], $object->getAddress())
        );

        $years = array();
        $archiveYears = array();
        if (count($data['cvbook']) > 0) {
            $repository = $this->getEntityManager()
                ->getRepository('CommonBundle\Entity\General\AcademicYear');
            foreach ($data['cvbook'] as $yearId) {
                if (strpos($yearId, 'archive-') === 0) {
                    $archiveYears[] = substr($yearId, strlen('archive-'));
                } else {
                    $years[] = $repository->findOneById(substr($yearId, strlen('year-')));
                }
            }
        }

        $object->setCvBookYears($years);
        $object->setCvBookArchiveYears($archiveYears);

        $years = array();
        if (count($data['page']['years']) > 0) {
            $yearIds = $data['page']['years'];
            $repository = $this->getEntityManager()
                ->getRepository('CommonBundle\Entity\General\AcademicYear');
            foreach ($yearIds as $yearId) {
                $years[] = $repository->findOneById($yearId);
            }
        }

        if (null === $object->getPage()) {
            $object->setPage(
                new PageEntity(
                    $object
                )
            );
            $this->getEntityManager()->persist($object->getPage());
        }

        $object->getPage()->setYears($years)
            ->setSummary($data['page']['summary'])
            ->setDescription($data['page']['description']);

        return $this->stdHydrate($data, $object, self::$std_keys);
    }

    protected function doExtract($object = null)
    {
        if (null === $object) {
            return array();
        }

        $data = $this->stdExtract($object, self::$std_keys);

        $data['cvbook'] = array();
        foreach ($object->getCvBookYears() as $year) {
            $data['cvbook'][] = 'year-' . $year->getId();
        }

        foreach ($object->getCvBookArchiveYears() as $year) {
            $data['cvbook'][] = 'archive-' . $year;
        }

        $data['address'] = $this->getHydrator('CommonBundle\Hydrator\General\Address')
            ->extract($object->getAddress());

        $page = $object->getPage();
        if (null !== $page) {
            $data['page']['years'] = array();
            foreach ($page->getYears() as $year) {
                $data['page']['years'][] = $year->getId();
            }
            $data['page']['summary'] = $page->getSummary();
            $data['page']['description'] = $page->getDescription();
        }

        return $data;
{'fraction_non_alphanumeric': 0.17887232663642255, 'fraction_numerical': 0.0007777057679844458, 'mean_word_length': 2.1897478296816866, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 142, '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': '349307', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2201, 'n_words': 449}