<commit_before><?php

namespace SAEApi\Controller;

use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class Customer implements ControllerProviderInterface {

    public function connect(Application $app)
    {
        $c = $app['controllers_factory'];

        $c->get('/{customerid}', function (Application $app, $customerid) {
            $text = $app['db']->fetchAssoc('SELECT * FROM customers WHERE customerID = ?', array($customerid));

            if ($text === false) {
                $app->abort('404', "invalid customer id");
            } else {
                $text['codes'] = $app['db']->fetchAll('SELECT * FROM codes WHERE boxID = ? ORDER BY generated ASC', array($text['boxID']));
                return json_encode($text);
            }
        })->value('customerid', '0');


        $c->get('/{customerid}/codes', function(Application $app, Request $request, $customerid) {
            $text = $app['db']->fetchAssoc('SELECT * FROM customers WHERE customerID = ?', array($customerid));

            if ($text === false) {
                $app->abort('404', "invalid customer id");
            } else {
                $text['codes'] = $app['db']->fetchAll('SELECT * FROM codes WHERE boxID = ? ORDER BY generated ASC', array($text['boxID']));
                return json_encode($text['codes']);
            }
        });

        $c->post('/{customerid}/codes', function(Application $app, Request $request, $customerid) {
            if (!$request->get('paid')) {
                $app->abort('400', "Missing parameter");
            } else if (!is_numeric($request->get('paid'))) {
                $app->abort('400', "Paid amount must a number");
            }

            if (!($text = $app['db']->fetchAssoc('SELECT * FROM customers WHERE customerID = ?', array($customerid)))) {<commit_msg>Small optimisation for GET /customer/<id>/<commit_after><?php

namespace SAEApi\Controller;

use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class Customer implements ControllerProviderInterface {

    public function connect(Application $app)
    {
        $c = $app['controllers_factory'];

        $c->get('/{customerid}/', function (Application $app, $customerid) {
            if (!($text = $app['db']->fetchAssoc('SELECT * FROM customers WHERE customerID = ?', array($customerid)))) {
                $app->abort('404', "invalid customer id");
            } else {
                $text['codes'] = $app['db']->fetchAll('SELECT * FROM codes WHERE boxID = ? ORDER BY generated ASC', array($text['boxID']));
                return json_encode($text);
            }
        })->value('customerid', '0');


        $c->get('/{customerid}/codes/', function(Application $app, Request $request, $customerid) {
            $text = $app['db']->fetchAssoc('SELECT * FROM customers WHERE customerID = ?', array($customerid));

            if ($text === false) {
                $app->abort('404', "invalid customer id");
            } else {
                $text['codes'] = $app['db']->fetchAll('SELECT * FROM codes WHERE boxID = ? ORDER BY generated ASC', array($text['boxID']));
                return json_encode($text['codes']);
            }
        });

        $c->post('/{customerid}/codes/', function(Application $app, Request $request, $customerid) {
            if (!$request->get('paid')) {
                $app->abort('400', "Missing parameter");
            } else if (!is_numeric($request->get('paid'))) {
                $app->abort('400', "Paid amount must a number");
            }

            if (!($text = $app['db']->fetchAssoc('SELECT * FROM customers WHERE customerID = ?', array($customerid)))) {
{'fraction_non_alphanumeric': 0.17215452424163857, 'fraction_numerical': 0.006740990407052113, 'mean_word_length': 2.6777883698760725, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 34, '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': '6868715', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1032, 'n_words': 238}