<commit_before><?php

namespace Api\V1\Http\Middleware;

use Closure;
use Illuminate\Contracts\Filesystem\Factory as Storage;
use Illuminate\Http\Request;
use Lib\AvgColorPicker\Contracts\AvgColorPicker;

/**
 * Class GenerateAvgColor.
 *
 * @property Storage storage
 * @property AvgColorPicker avgColorPicker
 * @package Api\V1\Http\Middleware
 */
class GenerateAvgColor
{
    /**
     * GenerateAvgColor constructor.
     *
     * @param Storage $storage
     * @param AvgColorPicker $avgColorPicker
     */
    public function __construct(Storage $storage, AvgColorPicker $avgColorPicker)
    {
        $this->storage = $storage;
        $this->avgColorPicker = $avgColorPicker;
    }

    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $imageAbsPath = $this->storage
                ->getDriver()
                ->getAdapter()
                ->getPathPrefix() . $request->get('thumbnails')[1]['path'];

        $request->merge(['avg_color' => $this->avgColorPicker->getImageAvgHexColorByPath($imageAbsPath)]);

        return $next($request);
    }
}<commit_msg>[BE]. Refactored generate avg color middleware<commit_after><?php

namespace Api\V1\Http\Middleware;

use Closure;
use Illuminate\Contracts\Filesystem\Factory as Storage;
use Illuminate\Http\Request;
use Lib\AvgColorPicker\Contracts\AvgColorPicker;

/**
 * Class GenerateAvgColor.
 *
 * @property Storage storage
 * @property AvgColorPicker avgColorPicker
 * @package Api\V1\Http\Middleware
 */
class GenerateAvgColor
{
    /**
     * GenerateAvgColor constructor.
     *
     * @param Storage $storage
     * @param AvgColorPicker $avgColorPicker
     */
    public function __construct(Storage $storage, AvgColorPicker $avgColorPicker)
    {
        $this->storage = $storage;
        $this->avgColorPicker = $avgColorPicker;
    }

    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $imageAbsPath = $this->storage
                ->getDriver()
                ->getAdapter()
                ->getPathPrefix() . $request->get('thumbnails')[1]['path'];

        $request->merge(['avg_color' => $this->avgColorPicker->getImageAvgHexColorByPath($imageAbsPath)]);

        return $next($request);
    }
}
{'fraction_non_alphanumeric': 0.12434607645875252, 'fraction_numerical': 0.002414486921529175, 'mean_word_length': 2.8246153846153845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5523205', 'n_tokens_mistral': 742, 'n_tokens_neox': 739, 'n_words': 146}