<commit_before><?php

namespace Concrete\Core\Permission;

use Concrete\Core\Permission\Key\Key as PermissionKey;
use Concrete\Core\Permission\Response\Response as PermissionResponse;
use Loader;

class Checker
{
    public $error;

    /** @var PermissionResponse */
    protected $response;

    public function __construct($object = false)
    {
        if ($object) {
            $this->response = PermissionResponse::getResponse($object);
            $r = $this->response->testForErrors();
            if ($r) {
                $this->error = $r;
            }
        }
    }

    /**
     * We take any permissions function run on the permissions class and send it into the category object.
     *
     * @param mixed $f
     * @param mixed $a
     */
    public function __call($f, $a)
    {
        if (!is_object($this->response)) {
            // handles task permissions
            $permission = Loader::helper('text')->uncamelcase($f);
        }

        if (count($a) > 0) {
            if (is_object($this->response)) {
                $r = call_user_func_array([$this->response, $f], $a);
            } else {
                $pk = PermissionKey::getByHandle($permission);
                $r = call_user_func_array([$pk, $f], $a);
            }
        } elseif (is_object($this->response)) {
            $r = $this->response->{$f}();
        } else {
            $pk = PermissionKey::getByHandle($permission);
            if (is_object($pk)) {
                $r = $pk->validate();
            } else {
                throw new \Exception(t('Unable to get permission key for %s', $permission));
            }
        }

        if (is_array($r) || is_object($r)) {
            return $r;
        } elseif ($r) {
            return 1;
        } else {
            return 0;
        }
    }

    /**
     * Checks to see if there is a fatal error with this particular permission call.
     */
    public function isError()
    {
        return $this->error != '';
    }

    /**
     * Returns the error code if there is one.
     */
    public function getError()
    {
        return $this->error;
    }

    /**
     * Legacy.
     *
     * @private
     */
    public function getOriginalObject()
    {
        return $this->response->getPermissionObject();
    }

    public function getResponseObject()
    {
        return $this->response;
    }
}<commit_msg>Avoid deprecated methods, add phpdoc<commit_after><?php

namespace Concrete\Core\Permission;

use Concrete\Core\Permission\Key\Key as PermissionKey;
use Concrete\Core\Permission\Response\Response as PermissionResponse;
use Concrete\Core\Support\Facade\Application;
use Exception;

class Checker
{
    /**
     * The ID of an error (if not falsy), of false|null if no errors.
     * List of some errors: https://github.com/concrete5/concrete5/blob/8.4.2/concrete/bootstrap/configure.php#L326-L336.
     *
     * @var int|null|false
     */
    public $error;

    /**
     * @var \Concrete\Core\Permission\Response\Response|null
     */
    protected $response;

    /**
     * @param \Concrete\Core\Permission\ObjectInterface|null|false $object
     */
    public function __construct($object = false)
    {
        if ($object) {
            $this->response = PermissionResponse::getResponse($object);
            $r = $this->response->testForErrors();
            if ($r) {
                $this->error = $r;
            }
        }
    }

    /**
     * We take any permissions function run on the permissions class and send it into the category object.
     *
     * @param string $f The method name
     * @param array $a The method arguments
     *
     * @return array|object|int
     */
    public function __call($f, $a)
    {
        if (!is_object($this->response)) {
            $app = Application::getFacadeApplication();
            // handles task permissions
            $permission = $app->make('helper/text')->uncamelcase($f);
        }

        if (count($a) > 0) {
            if ($this->response) {
                $r = call_user_func_array([$this->response, $f], $a);
            } else {
                $pk = PermissionKey::getByHandle($permission);
                $r = call_user_func_array([$pk, $f], $a);
            }
        } elseif (is_object($this->response)) {
            $r = $this->response->{$f}();
        } else {
            $pk = PermissionKey::getByHandle($permission);
            if (!$pk) {
                throw new Exception(t('Unable to get permission key for %s', $permission));
            }
            $r = $pk->validate();
        }

        if (is_array($r) || is_object($r)) {
            return $r;
        }

        return $r ? 1 : 0;
    }

    /**
     * Checks to see if there is a fatal error with this particular permission call.
     *
     * @return bool
     */
    public function isError()
    {
        return $this->error ? true : false;
    }

    /**
     * Returns the error code if there is one.
     *
     * @return int|null|false
     */
    public function getError()
    {
        return $this->error;
    }

    /**
     * Legacy.
     *
     * @private
     *
     * @return \Concrete\Core\Permission\ObjectInterface
     */
    public function getOriginalObject()
    {
        return $this->response->getPermissionObject();
    }

    /**
     * @return \Concrete\Core\Permission\Response\Response|null
     */
    public function getResponseObject()
    {
        return $this->response;
    }
}
{'fraction_non_alphanumeric': 0.13383376052727938, 'fraction_numerical': 0.0031124130355181254, 'mean_word_length': 1.7972350230414746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, 'https://': 1, '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': '6521559', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1551, 'n_words': 371}