<commit_before><?php

namespace Nohex\Eix\Modules\Catalog\Responders;

use Nohex\Eix\Core\Responses\Http\Redirection;
use Nohex\Eix\Modules\Catalog\Model\Order;
use Nohex\Eix\Modules\Catalog\Model\Orders;
use Nohex\Eix\Modules\Catalog\Responses\Html as HtmlResponse;
use Nohex\Eix\Services\Data\Responders\CollectionBrowser;
use Nohex\Eix\Services\Net\Http\BadRequestException;
use Nohex\Eix\Services\Net\Http\NotFoundException;

class OrderBrowser extends CollectionBrowser
{
    public function getCollectionName()
    {
        return 'orders';
    }

    public function getItemName()
    {
        return 'order';
    }

    /**
     * GET /{collection}[/:id]
     * 
     * The parent method is overriden to avoid 404ing on non-existent orders, in
     * order to avoid entity enumeration by malicious users.
     * 
     * The order authentication request is always required, whether the order
     * exists or not. The result of non-existent order or an incorrectly
     * authenticated one is indistinguishable.
     * 
     * @return HtmlResponse
     */
    public function httpGetForHtml()
    {
        $id = $this->getRequest()->getParameter('id');
        $authenticationCode = $this->getRequest()->getParameter('authenticationCode');
        
        $response = $this->getHtmlResponse();
        $response->setTemplateId($this->getViewTemplateId());
        // Add the identifier to the response.
        $response->setData('order', array('id' => $id));

        // No authentication code found.
        if ($authenticationCode) {
            try {
                $order = $this->getEntity($id);
                if ($order && ($order->getAuthenticationCode() == $authenticationCode)) {
                    $response = $this->getViewResponse($order);

                    $response->setData('order', $order->getFieldsData());
                    $response->appendToTitle(sprintf(
                        _('%s %s'),
                        ucfirst($this->getItemName()),
                        $order->getId()
                    ));
                }
            } catch (NotFoundException $exception) {
                // Swallow it, no one needs to know which orders exist and which
                // do not.
            }
        }


        return $response;
    }

    /**
     * POST /orders[/:id]
     * POST /comandes[/:id]
     * @return Html
     */
    public function httpPostForHtml()
    {
        $id = $this->getRequest()->getParameter('id');
        $operation = $this->getRequest()->getParameter('operation');

        $response = NULL;
        switch ($operation) {
            case 'authenticate':
                $response = $this->getAuthenticationResponse($id);
                break;
            case 'resend':
                try {
                    $order = $this->getEntity($id);
                    // Resend the confirmation.
                    $order->sendConfirmationRequest();
                } catch (NotFoundException $exception) {<commit_msg>Fix wrong function call.<commit_after><?php

namespace Nohex\Eix\Modules\Catalog\Responders;

use Nohex\Eix\Core\Responses\Http\Redirection;
use Nohex\Eix\Modules\Catalog\Model\Order;
use Nohex\Eix\Modules\Catalog\Model\Orders;
use Nohex\Eix\Modules\Catalog\Responses\Html as HtmlResponse;
use Nohex\Eix\Services\Data\Responders\CollectionBrowser;
use Nohex\Eix\Services\Net\Http\BadRequestException;
use Nohex\Eix\Services\Net\Http\NotFoundException;

class OrderBrowser extends CollectionBrowser
{
    public function getCollectionName()
    {
        return 'orders';
    }

    public function getItemName()
    {
        return 'order';
    }

    /**
     * GET /{collection}[/:id]
     * 
     * The parent method is overriden to avoid 404ing on non-existent orders, in
     * order to avoid entity enumeration by malicious users.
     * 
     * The order authentication request is always required, whether the order
     * exists or not. The result of non-existent order or an incorrectly
     * authenticated one is indistinguishable.
     * 
     * @return HtmlResponse
     */
    public function httpGetForHtml()
    {
        $id = $this->getRequest()->getParameter('id');
        $authenticationCode = $this->getRequest()->getParameter('authenticationCode');
        
        $response = $this->getHtmlResponse();
        $response->setTemplateId($this->getViewTemplateId());
        // Add the identifier to the response.
        $response->setData('order', array('id' => $id));

        // No authentication code found.
        if ($authenticationCode) {
            try {
                $order = $this->getEntity($id);
                if ($order && ($order->getAuthenticationCode() == $authenticationCode)) {
                    $response = $this->getViewResponse($order);

                    $response->setData('order', $order->getFieldsData());
                    $response->appendToTitle(sprintf(
                        _('%s %s'),
                        ucfirst($this->getItemName()),
                        $order->getId()
                    ));
                }
            } catch (NotFoundException $exception) {
                // Swallow it, no one needs to know which orders exist and which
                // do not.
            }
        }


        return $response;
    }

    /**
     * POST /orders[/:id]
     * POST /comandes[/:id]
     * @return Html
     */
    public function httpPostForHtml()
    {
        $id = $this->getRequest()->getParameter('id');
        $operation = $this->getRequest()->getParameter('operation');

        $response = NULL;
        switch ($operation) {
            case 'authenticate':
                $response = $this->getAuthenticationResponse($id);
                break;
            case 'resend':
                try {
                    $order = $this->getEntity($id);
                    // Resend the confirmation.
                    $order->sendConfirmationRequestMessage();
                } catch (NotFoundException $exception) {
{'fraction_non_alphanumeric': 0.12113659022931206, 'fraction_numerical': 0.0009970089730807576, 'mean_word_length': 1.9548355424644084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6987737', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1558, 'n_words': 355}