<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of Laravel Auto Presenter.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace McCool\LaravelAutoPresenter;

use Illuminate\Contracts\Routing\UrlRoutable;
use McCool\LaravelAutoPresenter\Exceptions\MethodNotFoundException;

abstract class BasePresenter implements UrlRoutable
{
    /**
     * The resource that is the object that was decorated.
     *
     * @var object
     */
    protected $wrappedObject;

    /**
     * Get the wrapped object.
     *
     * @param object $resource
     *
     * @return $this
     */
    public function setWrappedObject($resource)
    {
        $this->wrappedObject = $resource;

        return $this;
    }

    /**
     * Get the wrapped object.
     *
     * @return object
     */
    public function getWrappedObject()
    {
        return $this->wrappedObject;
    }

    /**
     * Get the value of the model's route key.
     *
     * @return mixed
     */
    public function getRouteKey()
    {
        return $this->wrappedObject->getRouteKey();
    }

    /**
     * Get the route key for the model.
     *
     * @return string
     */
    public function getRouteKeyName()
    {
        return $this->wrappedObject->getRouteKeyName();
    }

    /**
     * Retrieve model for route model binding.
     *
     * @param mixed $routeKey
     *
     * @return mixed
     */
    public function resolveRouteBinding($routeKey)
    {
        if (method_exists($this->wrappedObject, 'resolveRouteBinding') && is_callable([$this->wrappedObject, 'resolveRouteBinding'])) {
            return $this->wrappedObject->resolveRouteBinding($routeKey);
        }

        return $this->wrappedObject->where($this->wrappedObject->getRouteKeyName(), $routeKey)->first();
    }<commit_msg>Fixed base presenter<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of Laravel Auto Presenter.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace McCool\LaravelAutoPresenter;

use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Support\Str;
use McCool\LaravelAutoPresenter\Exceptions\MethodNotFoundException;

abstract class BasePresenter implements UrlRoutable
{
    /**
     * The resource that is the object that was decorated.
     *
     * @var object
     */
    protected $wrappedObject;

    /**
     * Get the wrapped object.
     *
     * @param object $resource
     *
     * @return $this
     */
    public function setWrappedObject($resource)
    {
        $this->wrappedObject = $resource;

        return $this;
    }

    /**
     * Get the wrapped object.
     *
     * @return object
     */
    public function getWrappedObject()
    {
        return $this->wrappedObject;
    }

    /**
     * Get the value of the model's route key.
     *
     * @return mixed
     */
    public function getRouteKey()
    {
        return $this->wrappedObject->getRouteKey();
    }

    /**
     * Get the route key for the model.
     *
     * @return string
     */
    public function getRouteKeyName()
    {
        return $this->wrappedObject->getRouteKeyName();
    }

    /**
     * Retrieve model for route model binding.
     *
     * @param mixed       $routeKey
     * @param string|null $field
     *
     * @return mixed
     */
    public function resolveRouteBinding($routeKey, $field = null)
    {
        if (method_exists($this->wrappedObject, 'resolveRouteBinding') && is_callable([$this->wrappedObject, 'resolveRouteBinding'])) {
            return $this->wrappedObject->resolveRouteBinding($routeKey, $field);
        }

        return $this->wrappedObject->where($field ?? $this->wrappedObject->getRouteKeyName(), $routeKey)->first();
    }

    /**
     * Retrieve the child model for a bound value.
     *
     * @param  string      $childType
     * @param  mixed       $value
     * @param  string|null $field
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function resolveChildRouteBinding($childType, $value, $field)
    {
        if (method_exists($this->wrappedObject, 'resolveChildRouteBinding') && is_callable([$this->wrappedObject, 'resolveChildRouteBinding'])) {
            return $this->wrappedObject->resolveChildRouteBinding($childType, $value, $field);
        }

        return $this->wrappedObject->{Str::plural($childType)}()->where($field, $value)->first();
    }
{'fraction_non_alphanumeric': 0.12110800944814258, 'fraction_numerical': 0.00042946102641185313, 'mean_word_length': 2.5207860922146637, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, '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': '2319879', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1348, 'n_words': 325}