<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of SolidInvoice project.
 *
 * (c) 2013-2017 <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace SolidInvoice\InvoiceBundle\Action;

use SolidInvoice\CoreBundle\Response\FlashResponse;
use SolidInvoice\CoreBundle\Traits\SaveableTrait;
use SolidInvoice\InvoiceBundle\Entity\Invoice;
use SolidInvoice\InvoiceBundle\Exception\InvalidTransitionException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Workflow\StateMachine;

final class RecurringTransition
{
    use SaveableTrait;

    /**
     * @var RouterInterface
     */
    private $router;

    /**
     * @var StateMachine
     */
    private $stateMachine;

    public function __construct(RouterInterface $router, StateMachine $stateMachine)
    {
        $this->router = $router;
        $this->stateMachine = $stateMachine;
    }

    public function __invoke(Request $request, string $action, Invoice $invoice)
    {
        if (!$this->stateMachine->can($invoice, $action)) {
            throw new InvalidTransitionException($action);
        }

        $this->stateMachine->apply($invoice, $action);

        $this->save($invoice);

        $route = $this->router->generate('_invoices_view', ['id' => $invoice->getId()]);

        return new class($action, $route) extends RedirectResponse implements FlashResponse {
            /**
             * @var string
             */
            private $action;

            public function __construct(string $action, string $route)
            {
                $this->action = $action;
                parent::__construct($route);
            }

            public function getFlash(): iterable
            {
                yield self::FLASH_SUCCESS => 'invoice.transition.action.'.$this->action;
            }<commit_msg>Fix class import and route name in RecurringTransition action<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of SolidInvoice project.
 *
 * (c) 2013-2017 <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace SolidInvoice\InvoiceBundle\Action;

use SolidInvoice\CoreBundle\Response\FlashResponse;
use SolidInvoice\CoreBundle\Traits\SaveableTrait;
use SolidInvoice\InvoiceBundle\Entity\RecurringInvoice;
use SolidInvoice\InvoiceBundle\Exception\InvalidTransitionException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Workflow\StateMachine;

final class RecurringTransition
{
    use SaveableTrait;

    /**
     * @var RouterInterface
     */
    private $router;

    /**
     * @var StateMachine
     */
    private $stateMachine;

    public function __construct(RouterInterface $router, StateMachine $stateMachine)
    {
        $this->router = $router;
        $this->stateMachine = $stateMachine;
    }

    public function __invoke(Request $request, string $action, RecurringInvoice $invoice)
    {
        if (!$this->stateMachine->can($invoice, $action)) {
            throw new InvalidTransitionException($action);
        }

        $this->stateMachine->apply($invoice, $action);

        $this->save($invoice);

        $route = $this->router->generate('_invoices_view_recurring', ['id' => $invoice->getId()]);

        return new class($action, $route) extends RedirectResponse implements FlashResponse {
            /**
             * @var string
             */
            private $action;

            public function __construct(string $action, string $route)
            {
                $this->action = $action;
                parent::__construct($route);
            }

            public function getFlash(): iterable
            {
                yield self::FLASH_SUCCESS => 'invoice.transition.action.'.$this->action;
            }
{'fraction_non_alphanumeric': 0.10970873786407767, 'fraction_numerical': 0.004368932038834952, 'mean_word_length': 2.8051708217913203, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '4765021', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1099, 'n_words': 254}