<commit_before><?php

declare(strict_types=1);

namespace BEAR\Resource;

/**
 * @property $this $get
 * @property $this $post
 * @property $this $put
 * @property $this $patch
 * @property $this $delete
 * @property $this $head
 * @property $this $options
 */
final class Resource implements ResourceInterface
{
    /**
     * Resource factory
     *
     * @var FactoryInterface
     */
    private $factory;

    /**
     * @var InvokerInterface
     */
    private $invoker;

    /**
     * Anchor
     *
     * @var AnchorInterface
     */
    private $anchor;

    /**
     * Linker
     *
     * @var LinkerInterface
     */
    private $linker;

    /**
     * Request
     *
     * @var Request
     * @psalm-suppress PropertyNotSetInConstructor
     */
    private $request;

    /**
     * Request method
     *
     * @var string
     */
    private $method = 'get';

    /**
     * @var UriFactory
     */
    private $uri;

    /** @noinspection MoreThanThreeArgumentsInspection */

    /**
     * @param FactoryInterface $factory Resource factory
     * @param InvokerInterface $invoker Resource request invoker
     * @param AnchorInterface  $anchor  Resource anchor
     * @param LinkerInterface  $linker  Resource linker
     * @param UriFactory       $uri     URI factory
     */
    public function __construct(
        FactoryInterface $factory,
        InvokerInterface $invoker,
        AnchorInterface $anchor,
        LinkerInterface $linker,
        UriFactory $uri
    ) {
        $this->factory = $factory;
        $this->invoker = $invoker;
        $this->anchor = $anchor;
        $this->linker = $linker;
        $this->uri = $uri;
    }

    /**
     * @param string $name
     */
    public function __get($name) : self
    {
        $this->method = $name;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function newInstance($uri) : ResourceObject
    {
        if (is_string($uri)) {
            $uri = ($this->uri)($uri);
        }

        return $this->factory->newInstance($uri);
    }

    /**
     * {@inheritdoc}
     *
     * @throws \BEAR\Resource\Exception\MethodException
     */
    public function object(ResourceObject $ro) : RequestInterface
    {
        return new Request($this->invoker, $ro, $this->method);
    }

    /**
     * {@inheritdoc}
     */
    public function uri($uri) : RequestInterface
    {
        $method = $this->method; // save method, this may change on newInstance(), this is singleton!
        $this->method = 'get';
        $ro = $this->newInstance($uri);
        $ro->uri->method = $method;
        $this->request = new Request($this->invoker, $ro, $ro->uri->method, $ro->uri->query, [], $this->linker);

        return $this->request;
    }

    /**
     * {@inheritdoc}
     */
    public function href(string $rel, array $query = []) : ResourceObject
    {
        [$method, $uri] = $this->anchor->href($rel, $this->request, $query);

        return $this->{$method}->uri($uri)->addQuery($query)->eager->request();
    }

    public function get(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::GET, $uri)($query);
    }

    public function post(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::POST, $uri)($query);
    }

    public function put(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::PUT, $uri)($query);
    }

    public function patch(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::PATCH, $uri)($query);
    }<commit_msg>suppress MixedPropertyFetch and MixedMethodCall<commit_after><?php

declare(strict_types=1);

namespace BEAR\Resource;

/**
 * @property $this $get
 * @property $this $post
 * @property $this $put
 * @property $this $patch
 * @property $this $delete
 * @property $this $head
 * @property $this $options
 */
final class Resource implements ResourceInterface
{
    /**
     * Resource factory
     *
     * @var FactoryInterface
     */
    private $factory;

    /**
     * @var InvokerInterface
     */
    private $invoker;

    /**
     * Anchor
     *
     * @var AnchorInterface
     */
    private $anchor;

    /**
     * Linker
     *
     * @var LinkerInterface
     */
    private $linker;

    /**
     * Request
     *
     * @var Request
     * @psalm-suppress PropertyNotSetInConstructor
     */
    private $request;

    /**
     * Request method
     *
     * @var string
     */
    private $method = 'get';

    /**
     * @var UriFactory
     */
    private $uri;

    /** @noinspection MoreThanThreeArgumentsInspection */

    /**
     * @param FactoryInterface $factory Resource factory
     * @param InvokerInterface $invoker Resource request invoker
     * @param AnchorInterface  $anchor  Resource anchor
     * @param LinkerInterface  $linker  Resource linker
     * @param UriFactory       $uri     URI factory
     */
    public function __construct(
        FactoryInterface $factory,
        InvokerInterface $invoker,
        AnchorInterface $anchor,
        LinkerInterface $linker,
        UriFactory $uri
    ) {
        $this->factory = $factory;
        $this->invoker = $invoker;
        $this->anchor = $anchor;
        $this->linker = $linker;
        $this->uri = $uri;
    }

    /**
     * @param string $name
     */
    public function __get($name) : self
    {
        $this->method = $name;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function newInstance($uri) : ResourceObject
    {
        if (is_string($uri)) {
            $uri = ($this->uri)($uri);
        }

        return $this->factory->newInstance($uri);
    }

    /**
     * {@inheritdoc}
     *
     * @throws \BEAR\Resource\Exception\MethodException
     */
    public function object(ResourceObject $ro) : RequestInterface
    {
        return new Request($this->invoker, $ro, $this->method);
    }

    /**
     * {@inheritdoc}
     */
    public function uri($uri) : RequestInterface
    {
        $method = $this->method; // save method, this may change on newInstance(), this is singleton!
        $this->method = 'get';
        $ro = $this->newInstance($uri);
        $ro->uri->method = $method;
        $this->request = new Request($this->invoker, $ro, $ro->uri->method, $ro->uri->query, [], $this->linker);

        return $this->request;
    }

    /**
     * {@inheritdoc}
     *
     * @psalm-suppress MixedPropertyFetch
     */
    public function href(string $rel, array $query = []) : ResourceObject
    {
        [$method, $uri] = $this->anchor->href($rel, $this->request, $query);
        /** @psalm-suppress MixedMethodCall */
        $resourceObject = $this->{$method}->uri($uri)->addQuery($query)->eager->request();
        assert($resourceObject instanceof ResourceObject);

        return $resourceObject;
    }

    public function get(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::GET, $uri)($query);
    }

    public function post(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::POST, $uri)($query);
    }

    public function put(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::PUT, $uri)($query);
    }

    public function patch(string $uri, array $query = []) : ResourceObject
    {
        return $this->methodUri(Request::PATCH, $uri)($query);
    }
{'fraction_non_alphanumeric': 0.1458444326052211, 'fraction_numerical': 0.0002663825253063399, 'mean_word_length': 2.2117194183062447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, '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': '6134933', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2205, 'n_words': 494}