<commit_before><?php

namespace Bundle\MainBundle\Controller\Api;

use Bundle\MainBundle\Constant\Constant;
use Bundle\MainBundle\Controller\AdvancedController;
use Bundle\MainBundle\Entity\Audit;
use Bundle\MainBundle\Entity\User;
use Bundle\MainBundle\Repository\AuditRepository;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Symfony\Component\HttpFoundation\Response;
use Doctrine\DBAL\Connection;
/**
 * User controller
 *
 * @Route("/api")
 */
class AuditController extends ApiController
{
    /**
     * @Route("/putAudit/")
     * @param Request $request
     * @return Response
     */
    public function putAuditAction()
    {
        $content = $this->getRequest()->getContent();

        $audits = unserialize($content);

        if (empty($audits)) return new Response();

        $repository = $this->getRepository('audit');
        foreach ($audits as $audit) {
            try {
                // Пропускаем, если нет заполненных полей
                if (!$audit) {
                    continue;
                }
                $auditObj = $repository->findOneBy(array('projectID' => $audit['projectID']));

                if (!$auditObj) {
                    $auditObj = new Audit();
                }

                foreach ($audit as $field => $value) {

                    $isObject = false;
                    $method = 'set' . ucfirst($field);
                    if (!method_exists($auditObj, $method)) {
                        $method = 'add' . ucfirst($field);
                    }

                    if (method_exists($auditObj, $method)) {
                        switch($field) {
                            case 'title':
                                if (!$value) {
                                    $value = Constant::AUDIT_DEFAULT_TITLE;
                                }

                                break;
                            case 'pdkDocument':
                            case 'pdkDocumentFinishStatus':
                                $value = !empty($value);
                                break;
                            case 'contact':
                            case 'owner':
                            case 'author':
                                $rep = $this->getRepository('user');
                                $value = $rep->findOneBy(array('contactID' => $value));

                                if ($field == 'contact' && $auditObj->hasContact($value)) {
                                    $method = null;
                                }
<commit_msg>Правка<commit_after><?php

namespace Bundle\MainBundle\Controller\Api;

use Bundle\MainBundle\Constant\Constant;
use Bundle\MainBundle\Controller\AdvancedController;
use Bundle\MainBundle\Entity\Audit;
use Bundle\MainBundle\Entity\User;
use Bundle\MainBundle\Repository\AuditRepository;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Symfony\Component\HttpFoundation\Response;
use Doctrine\DBAL\Connection;
/**
 * User controller
 *
 * @Route("/api")
 */
class AuditController extends ApiController
{
    /**
     * @Route("/putAudit/")
     * @param Request $request
     * @return Response
     */
    public function putAuditAction()
    {
        $content = $this->getRequest()->getContent();

        $audits = unserialize($content);

        if (empty($audits)) return new Response();

        $repository = $this->getRepository('audit');
        foreach ($audits as $audit) {
            try {
                // Пропускаем, если нет заполненных полей
                if (!$audit) {
                    continue;
                }
                $auditObj = $repository->findOneBy(array('projectID' => $audit['projectID']));

                if (!$auditObj) {
                    $auditObj = new Audit();
                }

                foreach ($audit as $field => $value) {

                    $isObject = false;
                    $method = 'set' . ucfirst($field);
                    if (!method_exists($auditObj, $method)) {
                        $method = 'add' . ucfirst($field);
                    }

                    if (method_exists($auditObj, $method)) {
                        switch($field) {
                            case 'title':
                                if (!$value) {
                                    $value = Constant::AUDIT_DEFAULT_TITLE;
                                }

                                break;
                            case 'pdkDocument':
                            case 'pdkDocumentFinishStatus':
                                $value = !empty($value);
                                break;
                            case 'contact':
                            case 'owner':
                            case 'author':
                                $rep = $this->getRepository('user');
                                $value = $rep->findOneBy(array('contactID' => $value));

                                if ($field == 'contact' && $value && $auditObj->hasContact($value)) {
                                    $method = null;
                                }

{'fraction_non_alphanumeric': 0.11290027447392498, 'fraction_numerical': 0.0, 'mean_word_length': 1.3611231101511878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '11169', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1315, 'n_words': 249}