<commit_before><?php

/**
 * Returns information about customers
 *
 * @package     Nails
 * @subpackage  module-invoice
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

namespace Nails\Api\Invoice;

use Nails\Factory;
use Nails\Api\Controller\Base;

class Customer extends Base
{
    /**
     * Search for a customer
     */
    public function getSearch()
    {
        if (!userHasPermission('admin:invoice:customer:manage')) {

            return array(
                'status' => 401,
                'error' => 'You are not authorised to search customers.'
            );

        } else {

            $sKeywords      = $this->input->get('keywords');
            $oCustomerModel = Factory::model('Customer', 'nailsapp/module-invoice');

            if (strlen($sKeywords) >= 3) {

                $oResult = $oCustomerModel->search($sKeywords);
                $aOut    = array();

                foreach ($oResult->data as $oCustomer) {
                    $aOut[] = $this->formatCustomer($oCustomer);
                }

                return array(
                    'data' => $aOut
                );

            } else {

                return array(
                    'status' => 400,
                    'error' => 'Search term must be 3 characters or longer.'
                );
            }
        }
    }

    // --------------------------------------------------------------------------

    /**
     * Returns a customer by their ID
     * @param  string $iId The customer's ID
     * @return array
     */
    public function getId($iId = null)
    {
        $iId = (int) $iId ?: (int) $this->input->get('id');

        if (empty($iId)) {
            return array(
                'status' => 404
            );
        }

        $oCustomerModel = Factory::model('Customer', 'nailsapp/module-invoice');
        $oCustomer      = $oCustomerModel->getById($iId);
<commit_msg>Using Factory laoded input service<commit_after><?php

/**
 * Returns information about customers
 *
 * @package     Nails
 * @subpackage  module-invoice
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

namespace Nails\Api\Invoice;

use Nails\Factory;
use Nails\Api\Controller\Base;

class Customer extends Base
{
    /**
     * Search for a customer
     */
    public function getSearch()
    {
        if (!userHasPermission('admin:invoice:customer:manage')) {

            return array(
                'status' => 401,
                'error' => 'You are not authorised to search customers.'
            );

        } else {

            $oInput         = Factory::service('Input');
            $sKeywords      = $oInput->get('keywords');
            $oCustomerModel = Factory::model('Customer', 'nailsapp/module-invoice');

            if (strlen($sKeywords) >= 3) {

                $oResult = $oCustomerModel->search($sKeywords);
                $aOut    = array();

                foreach ($oResult->data as $oCustomer) {
                    $aOut[] = $this->formatCustomer($oCustomer);
                }

                return array(
                    'data' => $aOut
                );

            } else {

                return array(
                    'status' => 400,
                    'error' => 'Search term must be 3 characters or longer.'
                );
            }
        }
    }

    // --------------------------------------------------------------------------

    /**
     * Returns a customer by their ID
     * @param  string $iId The customer's ID
     * @return array
     */
    public function getId($iId = null)
    {
        $oInput = Factory::service('Input');
        $iId    = (int) $iId ?: (int) $oInput->get('id');

        if (empty($iId)) {
            return array(
                'status' => 404
            );
        }

        $oCustomerModel = Factory::model('Customer', 'nailsapp/module-invoice');
        $oCustomer      = $oCustomerModel->getById($iId);

{'fraction_non_alphanumeric': 0.16171284634760705, 'fraction_numerical': 0.0055415617128463475, 'mean_word_length': 1.366507747318236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6410022', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1039, 'n_words': 244}