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

use BEAR\Resource\Exception\ResourceNotFoundException;
use Ray\Di\Di\Inject;
use Ray\Di\Exception\Unbound;

final class Factory implements FactoryInterface
{
    /**
     * Resource adapter biding config
     *
     * @var SchemeCollectionInterface
     */
    private $scheme;

    /**
     * @param SchemeCollectionInterface $scheme
     */
    public function __construct(SchemeCollectionInterface $scheme)
    {
        $this->scheme = $scheme;
    }

    /**
     * Set scheme collection
     *
     * @param SchemeCollectionInterface $scheme
     *
     * @Inject(optional = true)
     * @codeCoverageIgnore
     */
    public function setSchemeCollection(SchemeCollectionInterface $scheme)
    {
        $this->scheme = $scheme;
    }

    /**
     * {@inheritDoc}
     */
    public function newInstance($uri)
    {
        if (! $uri instanceof Uri) {
            $uri = new Uri($uri);
        }
        $adapter = $this->scheme->getAdapter($uri);
        try {
            $resourceObject = $adapter->get($uri);
        } catch (Unbound $e) {
            $resourceObject = $this->retryWithIndexSuffix($e, $uri);
        }

        return $resourceObject;
    }

    /**
     * @param Unbound $e
     * @param Uri     $uri
     *
     * @return ResourceObject
     */
    private function retryWithIndexSuffix(Unbound $e, Uri $uri)
    {
        if (substr($uri->path, -1) !== '/' || substr($uri->path, -6) === '/index') {
            throw new ResourceNotFoundException($uri, 404, $e);
        }
        $uri .= 'index';

        return $this->newInstance((string) $uri);
    }
}<commit_msg>remove retry with /index<commit_after><?php
/**
 * This file is part of the BEAR.Resource package
 *
 * @license http://opensource.org/licenses/MIT MIT
 */
namespace BEAR\Resource;

use BEAR\Resource\Exception\ResourceNotFoundException;
use Ray\Di\Di\Inject;
use Ray\Di\Exception\Unbound;

final class Factory implements FactoryInterface
{
    /**
     * Resource adapter biding config
     *
     * @var SchemeCollectionInterface
     */
    private $scheme;

    /**
     * @param SchemeCollectionInterface $scheme
     */
    public function __construct(SchemeCollectionInterface $scheme)
    {
        $this->scheme = $scheme;
    }

    /**
     * Set scheme collection
     *
     * @param SchemeCollectionInterface $scheme
     *
     * @Inject(optional = true)
     * @codeCoverageIgnore
     */
    public function setSchemeCollection(SchemeCollectionInterface $scheme)
    {
        $this->scheme = $scheme;
    }

    /**
     * {@inheritDoc}
     */
    public function newInstance($uri)
    {
        if (! $uri instanceof Uri) {
            $uri = new Uri($uri);
        }
        $adapter = $this->scheme->getAdapter($uri);
        try {
            $resourceObject = $adapter->get($uri);
        } catch (Unbound $e) {
            throw new ResourceNotFoundException($uri, 404, $e);
        }

        return $resourceObject;
    }
}
{'fraction_non_alphanumeric': 0.12737214538436797, 'fraction_numerical': 0.002573174654229656, 'mean_word_length': 2.22279792746114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4775197', 'n_tokens_mistral': 906, 'n_tokens_neox': 881, 'n_words': 197}