<commit_before><?php

namespace Best365Bundle\Controller;

use Mmoreram\ControllerExtraBundle\Annotation\Entity as EntityAnnotation;
use Mmoreram\ControllerExtraBundle\Annotation\Form as FormAnnotation;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

use Elcodi\Store\GeoBundle\Controller\AddressController;
use Elcodi\Component\Geo\Entity\Interfaces\AddressInterface;
use Elcodi\Component\User\Entity\Interfaces\CustomerInterface;
use Elcodi\Store\CoreBundle\Controller\Traits\TemplateRenderTrait;

/**
 * Address controllers
 *
 * @Security("has_role('ROLE_CUSTOMER')")
 * @Route(
 *      path = "/best365/user/address",
 * )
 */
class Best365AddressController extends AddressController
{
    use TemplateRenderTrait;

    /**
     * @var string
     *
     * Checkout source, used for redirection.
     */
    const CHECKOUT_SOURCE = 'checkout';

    /**
     * List addresses page
     *
     * @return Response Response
     *
     * @Route(
     *      path = "/",
     *      name = "best365_store_address_list",
     *      methods = {"GET"}
     * )
     */
    public function listAction()
    {
        $addressFormatter = $this->get('elcodi.formatter.address');

        $addresses = $this
            ->get('elcodi.wrapper.customer')
            ->get()
            ->getAddresses();

        $addressesFormatted = [];
        foreach ($addresses as $address) {
            $addressesFormatted[] =
                $addressFormatter
                    ->toArray($address);
        }

        return $this->render(
            'Best365Bundle:User:address.list.html.twig',
            [
                'addresses' => $addressesFormatted,
            ]
        );
    }

    /**
     * Edit an address
     *
     * @param integer $id      The address id
     * @param Request $request The current request
     * @param string  $source  The form source to redirect back
     *
     * @return Response Response
     *
     * @Route(
     *      path = "/{id}/edit/{source}",
     *      name = "best365_store_address_edit",
     *      methods = {"GET","POST"},
     *      defaults = {
     *          "source" = null,
     *      },
     * )
     */
    public function editAction($id, Request $request, $source)
    {
        $address = $this
            ->get('elcodi.repository.customer')
            ->findAddress(
                $this->getUser()->getId(),
                $id
            );

        if (!($address instanceof AddressInterface)) {
            throw new NotFoundHttpException('Address not found');
        }

        $form = $this
            ->createForm(
                'store_geo_form_type_address',
                $address
            );

        $form->handleRequest($request);

        if ($form->isValid()) {
			$best365_address = $this
				->get('best365.manager.address')
				->generateAddress($address);

            $addressToSave = $this
                ->get('elcodi.manager.address')
                ->saveAddress($best365_address);

            $customer = $this->getUser();
            $customer->removeAddress($address);
            $customer->addAddress($addressToSave);
            $this
                ->get('elcodi.object_manager.customer')
                ->flush($customer);

            $message = $this
                ->get('translator')
                ->trans('store.address.save.response_ok');

            $this->addFlash('success', $message);

            $redirectUrl = self::CHECKOUT_SOURCE == $source
                ? 'store_checkout_address'
                : 'best365_store_address_list';

            return $this->redirect(
                $this->generateUrl($redirectUrl)
            );
        } else {
            $this
                ->get('elcodi.object_manager.address')
                ->clear($address);
        }

        return $this->render(
            'Best365Bundle:User:address.edit.html.twig',
            [
                'address' => $address,
                'form'    => $form->createView(),
            ]
        );
    }
<commit_msg>fix warning when edit address<commit_after><?php

namespace Best365Bundle\Controller;

use Mmoreram\ControllerExtraBundle\Annotation\Entity as EntityAnnotation;
use Mmoreram\ControllerExtraBundle\Annotation\Form as FormAnnotation;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

use Elcodi\Store\GeoBundle\Controller\AddressController;
use Elcodi\Component\Geo\Entity\Interfaces\AddressInterface;
use Elcodi\Component\User\Entity\Interfaces\CustomerInterface;
use Elcodi\Store\CoreBundle\Controller\Traits\TemplateRenderTrait;

/**
 * Address controllers
 *
 * @Security("has_role('ROLE_CUSTOMER')")
 * @Route(
 *      path = "/best365/user/address",
 * )
 */
class Best365AddressController extends AddressController
{
    use TemplateRenderTrait;

    /**
     * @var string
     *
     * Checkout source, used for redirection.
     */
    const CHECKOUT_SOURCE = 'checkout';

    /**
     * List addresses page
     *
     * @return Response Response
     *
     * @Route(
     *      path = "/",
     *      name = "best365_store_address_list",
     *      methods = {"GET"}
     * )
     */
    public function listAction()
    {
        $addressFormatter = $this->get('elcodi.formatter.address');

        $addresses = $this
            ->get('elcodi.wrapper.customer')
            ->get()
            ->getAddresses();

        $addressesFormatted = [];
        foreach ($addresses as $address) {
            $addressesFormatted[] =
                $addressFormatter
                    ->toArray($address);
        }

        return $this->render(
            'Best365Bundle:User:address.list.html.twig',
            [
                'addresses' => $addressesFormatted,
            ]
        );
    }

    /**
     * Edit an address
     *
     * @param integer $id      The address id
     * @param Request $request The current request
     * @param string  $source  The form source to redirect back
     *
     * @return Response Response
     *
     * @Route(
     *      path = "/{id}/edit/{source}",
     *      name = "best365_store_address_edit",
     *      methods = {"GET","POST"},
     *      defaults = {
     *          "source" = null,
     *      },
     * )
     */
    public function editAction($id, Request $request, $source)
    {
        $address = $this
            ->get('elcodi.repository.customer')
            ->findAddress(
                $this->getUser()->getId(),
                $id
            );

        if (!($address instanceof AddressInterface)) {
            throw new NotFoundHttpException('Address not found');
        }

        $form = $this
            ->createForm(
                'store_geo_form_type_address',
                $address
            );

        $form->handleRequest($request);

        if ($form->isValid()) {
			$best365_address = $this
				->get('best365.manager.address')
				->generateAddress($address);

            $addressToSave = $this
                ->get('elcodi.manager.address')
                ->saveAddress($best365_address);

            $customer = $this->getUser();
            $customer->removeAddress($address);
            $customer->addAddress($addressToSave);
            $this
                ->get('elcodi.object_manager.customer')
                ->flush($customer);

            $message = $this
                ->get('translator')
                ->trans('store.address.save.response_ok');

            $this->addFlash('success', $message);

            $redirectUrl = self::CHECKOUT_SOURCE == $source
                ? 'store_checkout_address'
                : 'best365_store_address_list';

            return $this->redirect(
                $this->generateUrl($redirectUrl)
            );
        } elseif ($request->isMethod('POST')) {
            $this
                ->get('elcodi.object_manager.address')
                ->clear($address);
        }

        return $this->render(
            'Best365Bundle:User:address.edit.html.twig',
            [
                'address' => $address,
                'form'    => $form->createView(),
            ]
        );
    }

{'fraction_non_alphanumeric': 0.12507125755330065, 'fraction_numerical': 0.007524797628548626, 'mean_word_length': 1.9152542372881356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 72, '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': '6957909', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2347, 'n_words': 397}