<commit_before><?php

namespace Cftf\AsnBundle\Controller;

use CftfBundle\Entity\LsDocRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Cftf\AsnBundle\Service\AsnImport;
use GuzzleHttp\Client;

/**
 * Class DefaultController
 *
 * @Security("is_granted('create', 'lsdoc')")
 */
class DefaultController extends Controller
{
    /**
     * @Route("/cf/asn/import", name="import_from_asn")
     */
    public function importAsnAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $response = new JsonResponse();

        $fileUrl = $request->request->get('fileUrl');
        $asnDoc = $this->getAsnFile($fileUrl);

        $asnImport = new AsnImport($em);
        $res = $asnImport->parseAsnDocument($asnDoc);

        return $response->setData(array(
            'message' => 'Framework imported successfully!'
        ));
    }

    protected function getAsnFile($fileUrl){
        $client = new Client();

        $result = $client->request('GET', $fileUrl . '_full.json',
            [
                'headers' => [
                    'Content-Type' => 'application/json',
                ],
            ]
        );

        return (string) $result->getBody();<commit_msg>use the ASN Import service instead of creating a new instance of the class<commit_after><?php

namespace Cftf\AsnBundle\Controller;

use CftfBundle\Entity\LsDocRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Cftf\AsnBundle\Service\AsnImport;
use GuzzleHttp\Client;

/**
 * Class DefaultController
 *
 * @Security("is_granted('create', 'lsdoc')")
 */
class DefaultController extends Controller
{
    /**
     * @Route("/cf/asn/import", name="import_from_asn")
     */
    public function importAsnAction(Request $request)
    {
        $response = new JsonResponse();

        $fileUrl = $request->request->get('fileUrl');
        $asnDoc = $this->getAsnFile($fileUrl);

        $asnImport = $this->get('cftf_import.asn');
        $asnImport->parseAsnDocument($asnDoc);

        return $response->setData(array(
            'message' => 'Framework imported successfully!'
        ));
    }

    protected function getAsnFile($fileUrl){
        $client = new Client();

        $result = $client->request('GET', $fileUrl . '_full.json',
            [
                'headers' => [
                    'Content-Type' => 'application/json',
                ],
            ]
        );

        return (string) $result->getBody();
{'fraction_non_alphanumeric': 0.13361646520744855, 'fraction_numerical': 0.0, 'mean_word_length': 3.0718085106382977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '4934206', 'n_tokens_mistral': 892, 'n_tokens_neox': 873, 'n_words': 150}