<commit_before><?php

namespace Avalanche\Bundle\ImagineBundle\Imagine\Filter;

use Imagine\Filter\FilterInterface;
use Imagine\Image\ImageInterface;
use InvalidArgumentException;

class ChainFilter implements FilterInterface
{
    /**
     * @var FilterInterface[]
     */
    protected $filters;

    /**
     * @param FilterInterface[] $filters
     *
     * @throws InvalidArgumentException
     */
    public function __construct(array $filters)
    {
        foreach ($filters as $filter) {
            if (!$filter instanceof FilterInterface) {
                throw new InvalidArgumentException('Instance of Imagine\\Filter\\FilterInterface expected');
            }
        }

        $this->filters = $filters;
    }

    /**
     * {@inheritDoc}
     */
    public function apply(ImageInterface $image)
    {
        foreach ($this->filters as $filter) {<commit_msg>Update chain filter to recognize final filter<commit_after><?php

namespace Avalanche\Bundle\ImagineBundle\Imagine\Filter;

use Imagine\Filter\FilterInterface;
use Imagine\Image\ImageInterface;
use InvalidArgumentException;

class ChainFilter implements FilterInterface
{
    /**
     * @var FilterInterface[]
     */
    protected $filters;

    /**
     * @param FilterInterface[] $filters
     *
     * @throws InvalidArgumentException
     */
    public function __construct(array $filters)
    {
        $final = null;
        foreach ($filters as $filter) {
            if ($final) {
                $message = sprintf('Instance of %s must be used as last filter only', $final);
                throw new InvalidArgumentException($message);
            }

            if (!$filter instanceof FilterInterface) {
                throw new InvalidArgumentException('Instance of Imagine\\Filter\\FilterInterface expected');
            }

            if ($filter instanceof FinalFilterInterface) {
                $final = get_class($filter);
            }
        }

        $this->filters = $filters;
    }

    /**
     * {@inheritDoc}
     */
    public function apply(ImageInterface $image)
    {
        foreach ($this->filters as $filter) {
{'fraction_non_alphanumeric': 0.1039510818438382, 'fraction_numerical': 0.0, 'mean_word_length': 2.3496062992125983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4798059', 'n_tokens_mistral': 532, 'n_tokens_neox': 512, 'n_words': 133}