<commit_before><?php

namespace Pyz\Yves\Checkout\Process;

use Generated\Shared\Transfer\QuoteTransfer;
use Pyz\Yves\Checkout\Process\Steps\StepInterface;
use Spryker\Client\Cart\CartClientInterface;
use Spryker\Shared\Gui\Form\AbstractForm;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Spryker\Yves\Application\Controller\AbstractController;

class StepProcess
{

    /**
     * @var StepInterface[]
     */
    protected $steps = [];

    /**
     * @var StepInterface[]
     */
    protected $completedSteps = [];

    /**
     * @var CartClientInterface
     */
    protected $cartClient;

    /**
     * @var string
     */
    protected $errorRoute = 'checkout_error_route';

    /**
     * @var UrlGeneratorInterface
     */
    protected $urlGenerator;

    /**
     * @var FormFactoryInterface
     */
    protected $formFactory;

    /**
     * @param FormFactoryInterface $formFactory
     * @param UrlGeneratorInterface $urlGenerator
     * @param StepInterface[] $steps
     * @param CartClientInterface $cartClient
     */
    public function __construct(
        FormFactoryInterface $formFactory,
        UrlGeneratorInterface $urlGenerator,
        array $steps,
        CartClientInterface $cartClient
    ) {
        $this->formFactory = $formFactory;
        $this->urlGenerator = $urlGenerator;
        $this->steps = $steps;
        $this->cartClient = $cartClient;
    }

    /**
     * @param Request $request
     * @param AbstractForm|null $stepForm
     *
     * @return array|RedirectResponse
     */
    public function process(Request $request, AbstractForm $stepForm = null)
    {
        $currentStep = $this->getCurrentStep($request);

        if ($this->canAccessStep($request, $currentStep) === false) {
            return $this->createRedirectResponse($currentStep->getStepRoute());
        }

        if ($currentStep->preCondition($this->getQuoteTransfer()) === false) {
            $escapeRoute = $this->getEscapeRoute($currentStep);
            return $this->createRedirectResponse($escapeRoute);
        }

        if ($currentStep->requireInput() === false) {
            $route = $this->executeWithoutInput($currentStep);
            return $this->createRedirectResponse($route);
        }

        if ($stepForm !== null) {
            $form = $this->createForm($stepForm, $this->getQuoteTransfer());
            $form->handleRequest($request);
            if ($request->isMethod(Request::METHOD_POST)) {
                if ($form->isValid()) {
                    $route = $this->executeWithFormInput($currentStep, $form->getData());
                    return $this->createRedirectResponse($route);
                } else {
                    $this->setErrorFlashMessage($request, 'checkout.form.validation.failed');
                }
            }
            return [
                'paymentMethodsSubForms' => ['payolution/invoice', 'payolution/installment'],
                'previousStepUrl' => $this->getUrlFromRoute($this->getPreviousStepRoute()),
                'quoteTransfer' => $this->getQuoteTransfer(),
                'form' => $form->createView(),
            ];<commit_msg>updated step process<commit_after><?php

namespace Pyz\Yves\Checkout\Process;

use Generated\Shared\Transfer\PaymentTransfer;
use Generated\Shared\Transfer\QuoteTransfer;
use Pyz\Yves\Checkout\Process\Steps\StepInterface;
use Spryker\Client\Cart\CartClientInterface;
use Spryker\Shared\Gui\Form\AbstractForm;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Spryker\Yves\Application\Controller\AbstractController;

class StepProcess
{

    /**
     * @var StepInterface[]
     */
    protected $steps = [];

    /**
     * @var StepInterface[]
     */
    protected $completedSteps = [];

    /**
     * @var CartClientInterface
     */
    protected $cartClient;

    /**
     * @var string
     */
    protected $errorRoute = 'checkout_error_route';

    /**
     * @var UrlGeneratorInterface
     */
    protected $urlGenerator;

    /**
     * @var FormFactoryInterface
     */
    protected $formFactory;

    /**
     * @param FormFactoryInterface $formFactory
     * @param UrlGeneratorInterface $urlGenerator
     * @param StepInterface[] $steps
     * @param CartClientInterface $cartClient
     */
    public function __construct(
        FormFactoryInterface $formFactory,
        UrlGeneratorInterface $urlGenerator,
        array $steps,
        CartClientInterface $cartClient
    ) {
        $this->formFactory = $formFactory;
        $this->urlGenerator = $urlGenerator;
        $this->steps = $steps;
        $this->cartClient = $cartClient;
    }

    /**
     * @param Request $request
     * @param AbstractForm|null $stepForm
     *
     * @return array|RedirectResponse
     */
    public function process(Request $request, AbstractForm $stepForm = null)
    {
        $currentStep = $this->getCurrentStep($request);

        if ($this->canAccessStep($request, $currentStep) === false) {
            return $this->createRedirectResponse($currentStep->getStepRoute());
        }

        if ($currentStep->preCondition($this->getQuoteTransfer()) === false) {
            $escapeRoute = $this->getEscapeRoute($currentStep);
            return $this->createRedirectResponse($escapeRoute);
        }

        if ($currentStep->requireInput() === false) {
            $route = $this->executeWithoutInput($currentStep);
            return $this->createRedirectResponse($route);
        }

        if ($stepForm !== null) {
            $quoteTransfer = $this->getQuoteTransfer()->setPayment(new PaymentTransfer());
            $form = $this->createForm($stepForm, $quoteTransfer);
            $form->handleRequest($request);
            if ($request->isMethod(Request::METHOD_POST)) {
                if ($form->isValid()) {
                    $route = $this->executeWithFormInput($currentStep, $form->getData());
                    return $this->createRedirectResponse($route);
                } else {
                    $this->setErrorFlashMessage($request, 'checkout.form.validation.failed');
                }
            }
            return [
                'paymentMethodsSubForms' => ['payolution/invoice', 'payolution/installment'],
                'previousStepUrl' => $this->getUrlFromRoute($this->getPreviousStepRoute()),
                'quoteTransfer' => $this->getQuoteTransfer(),
                'form' => $form->createView(),
            ];
{'fraction_non_alphanumeric': 0.1286549707602339, 'fraction_numerical': 0.0, 'mean_word_length': 2.5948502364687336, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, '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': '361654', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1778, 'n_words': 301}