<commit_before><?php
/**
 * This file is part of the BEAR.Resource package
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 */
namespace BEAR\Resource;

use Doctrine\Common\Annotations\AnnotationReader;
use Ray\Di\Di\Inject;

/**
 * Anchor
 */
class Anchor
{
    /**
     * @var AnnotationReader
     */
    protected $reader;

    /**
     * @var Request
     */
    protected $request;

    /**
     * @param AnnotationReader $reader
     * @param Request          $request
     *
     * @Inject
     */
    public function __construct(
        AnnotationReader $reader,
        Request $request
    ) {
        $this->reader = $reader;
        $this->request = $request;
    }

    /**
     * Return linked request with hyper reference
     *
     * @param string  $rel
     * @param array   $query
     * @param Request $request
     *
     * @return Request
     * @throws Exception\Link
     */
    public function href($rel, Request $request, array $query)
    {
        $classMethod = 'on' . ucfirst($request->method);
        $annotations = $this->reader->getMethodAnnotations(new \ReflectionMethod($request->ro, $classMethod));
        foreach ($annotations as $annotation) {
            $isValidLinkAnnotation = $annotation instanceof Annotation\Link && isset($annotation->rel) && $annotation->rel === $rel;
            if ($isValidLinkAnnotation) {
                $body = $request->ro->body;
                $query = is_array($body) ? array_merge($body, $query) : [];
                $uri = \GuzzleHttp\uri_template($annotation->href, $query);

                return [$annotation->method, $uri];
            }
        }

        throw new Exception\Link("rel:{$rel} class:" . get_class($request->ro));
    }
}
<commit_msg>use interface and fix docblock<commit_after><?php
/**
 * This file is part of the BEAR.Resource package
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 */
namespace BEAR\Resource;

use Doctrine\Common\Annotations\AnnotationReader;
use Ray\Di\Di\Inject;

class Anchor
{
    /**
     * @var AnnotationReader
     */
    protected $reader;

    /**
     * @var Request
     */
    protected $request;

    /**
     * @param AnnotationReader $reader
     * @param RequestInterface $request
     *
     * @Inject
     */
    public function __construct(
        AnnotationReader $reader,
        RequestInterface $request
    ) {
        $this->reader = $reader;
        $this->request = $request;
    }

    /**
     * Return linked request with hyper reference
     *
     * @param string           $rel
     * @param RequestInterface $request
     * @param array            $query
     *
     * @return array [$method, $uri];
     * @throws Exception\Link
     */
    public function href($rel, RequestInterface $request, array $query)
    {
        $classMethod = 'on' . ucfirst($request->method);
        $annotations = $this->reader->getMethodAnnotations(new \ReflectionMethod($request->ro, $classMethod));
        foreach ($annotations as $annotation) {
            $isValidLinkAnnotation = $annotation instanceof Annotation\Link && isset($annotation->rel) && $annotation->rel === $rel;
            if ($isValidLinkAnnotation) {
                $body = $request->ro->body;
                $query = is_array($body) ? array_merge($body, $query) : [];
                $uri = \GuzzleHttp\uri_template($annotation->href, $query);

                return [$annotation->method, $uri];
            }
        }

        throw new Exception\Link("rel:{$rel} class:" . get_class($request->ro));
    }
}

{'fraction_non_alphanumeric': 0.13680964395850856, 'fraction_numerical': 0.0, 'mean_word_length': 2.220216606498195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2431717', 'n_tokens_mistral': 1010, 'n_tokens_neox': 992, 'n_words': 225}