<commit_before><?php

namespace RcmUser\ApiController;

use RcmUser\Provider\RcmUserAclResourceProvider;
use RcmUser\User\InputFilter\LoginInputFilter;
use Reliv\RcmApiLib\Model\ApiMessage;
use Zend\Http\Response;

/**
 * Class UserController
 *
 * PHP version 5
 *
 * @category  Reliv
 * @package   RcmUser\ApiController
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 Reliv International
 * @license   License.txt New BSD License
 * @version   Release: <package_version>
 * @link      https://github.com/reliv
 */
class UserController extends AbstractController
{
    /**
     * List of RPC methods that are passed as IDs
     * 
     * @var array
     */
    protected $reservedIds
        = [
            'new',
            'current',
            'login',
            'logout',
        ];

    /**
     * isReservedId
     *
     * @param $id
     *
     * @return bool
     */
    protected function isReservedId($id)
    {
        return in_array($id, $this->reservedIds);
    }

    /**
     * get
     *
     * @param mixed $id
     *
     * @return \Reliv\RcmApiLib\Http\ApiResponse
     */
    public function get($id)
    {
        $rcmUserService = $this->getRcmUserService();
        $user = null;

        if ($id == 'new') {
            $user = $rcmUserService->buildNewUser();
        }

        if ($id == 'current') {
            $user = $rcmUserService->getCurrentUser();
        }

        if (!$this->isReservedId($id) && $this->isAllowed(
            RcmUserAclResourceProvider::RESOURCE_ID_USER,
            'read'
        )
        ) {
            $user = $rcmUserService->getUserById($id);
        }

        if (empty($user)) {
            return $this->getApiResponse(
                $user,
                404
            );
        }

        return $this->getApiResponse(
            $user
        );
    }

    /**
     * create
     *<commit_msg>Add User API with login<commit_after><?php

namespace RcmUser\ApiController;

use RcmUser\Provider\RcmUserAclResourceProvider;
use RcmUser\User\InputFilter\LoginInputFilter;
use Reliv\RcmApiLib\Model\ApiMessage;
use Zend\Http\Response;

/**
 * Class UserController
 *
 * PHP version 5
 *
 * @category  Reliv
 * @package   RcmUser\ApiController
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 Reliv International
 * @license   License.txt New BSD License
 * @version   Release: <package_version>
 * @link      https://github.com/reliv
 */
class UserController extends AbstractController
{
    /**
     * List of RPC methods that are passed as IDs
     *
     * @var array
     */
    protected $reservedIds
        = [
            'new',
            'current',
            'login',
            'logout',
        ];

    /**
     * isReservedId
     *
     * @param $id
     *
     * @return bool
     */
    protected function isReservedId($id)
    {
        return in_array($id, $this->reservedIds);
    }

    /**
     * get
     *
     * @param mixed $id
     *
     * @return \Reliv\RcmApiLib\Http\ApiResponse
     */
    public function get($id)
    {
        $rcmUserService = $this->getRcmUserService();
        $user = null;

        if ($id == 'new') {
            $user = $rcmUserService->buildNewUser();
        }

        if ($id == 'current') {
            $user = $rcmUserService->getCurrentUser();
        }

        if (!$this->isReservedId($id)
            && $this->isAllowed(
                RcmUserAclResourceProvider::RESOURCE_ID_USER,
                'read'
            )
        ) {
            $user = $rcmUserService->getUserById($id);
        }

        if (empty($user)) {
            return $this->getApiResponse(
                $user,
                404
            );
        }

        return $this->getApiResponse(
            $user
        );
    }

    /**
     * create
     *
{'fraction_non_alphanumeric': 0.12595520421607379, 'fraction_numerical': 0.004216073781291172, 'mean_word_length': 1.6770098730606489, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 2, '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': '4537327', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1146, 'n_words': 222}