<commit_before><?php
namespace inklabs\kommerce\Service;

use inklabs\kommerce\EntityRepository;
use inklabs\kommerce\Entity;
use inklabs\kommerce\View;

class Order extends AbstractService
{
    /** @var EntityRepository\OrderInterface */
    private $orderRepository;

    public function __construct(EntityRepository\OrderInterface $orderRepository)
    {
        $this->orderRepository = $orderRepository;
    }

    /**
     * @param int $id
     * @return View\Order|null
     */
    public function find($id)
    {
        $order = $this->orderRepository->find($id);

        if ($order === null) {
            return null;
        }

        return $order->getView()
            ->withAllData()
            ->export();
    }

    public function getLatestOrders(Entity\Pagination & $pagination = null)
    {
        $orders = $this->orderRepository->getLatestOrders($pagination);

        return $this->getViewOrders($orders);
    }

    /**
     * @param Entity\Order[] $orders
     * @return View\Order[]
     */
    private function getViewOrders($orders)
    {
        $viewOrders = [];
        foreach ($orders as $order) {
            $viewOrders[] = $order->getView()
                ->withAllData()
                ->export();
        }

        return $viewOrders;
    }

    /**
     * @param int $userId
     * @return View\Order[]
     */
    public function getOrdersByUserId($userId)
    {
        $orders = $this->orderRepository->getOrdersByUserId($userId);

        return $this->getViewOrders($orders);
    }
}<commit_msg>Optimizing order listing.<commit_after><?php
namespace inklabs\kommerce\Service;

use inklabs\kommerce\EntityRepository;
use inklabs\kommerce\Entity;
use inklabs\kommerce\View;

class Order extends AbstractService
{
    /** @var EntityRepository\OrderInterface */
    private $orderRepository;

    public function __construct(EntityRepository\OrderInterface $orderRepository)
    {
        $this->orderRepository = $orderRepository;
    }

    /**
     * @param int $id
     * @return View\Order|null
     */
    public function find($id)
    {
        $order = $this->orderRepository->find($id);

        if ($order === null) {
            return null;
        }

        return $order->getView()
            ->withAllData()
            ->export();
    }

    public function getLatestOrders(Entity\Pagination & $pagination = null)
    {
        $orders = $this->orderRepository->getLatestOrders($pagination);
        return $this->getSimpleViewOrders($orders);
    }

    /**
     * @param Entity\Order[] $orders
     * @return View\Order[]
     */
    private function getSimpleViewOrders($orders)
    {
        $viewOrders = [];
        foreach ($orders as $order) {
            $viewOrders[] = $order->getView()
                ->export();
        }

        return $viewOrders;
    }
    /**
     * @param Entity\Order[] $orders
     * @return View\Order[]
     */
    private function getViewOrders($orders)
    {
        $viewOrders = [];
        foreach ($orders as $order) {
            $viewOrders[] = $order->getView()
                ->withAllData()
                ->export();
        }

        return $viewOrders;
    }

    /**
     * @param int $userId
     * @return View\Order[]
     */
    public function getOrdersByUserId($userId)
    {
        $orders = $this->orderRepository->getOrdersByUserId($userId);
        return $this->getSimpleViewOrders($orders);
    }
}
{'fraction_non_alphanumeric': 0.13350785340314136, 'fraction_numerical': 0.0, 'mean_word_length': 2.157943067033976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4081598', 'n_tokens_mistral': 1003, 'n_tokens_neox': 991, 'n_words': 184}