<commit_before><?php

namespace Oro\Bundle\WorkflowBundle\Extension;

use Oro\Bundle\ActionBundle\Helper\ApplicationsHelperInterface;
use Oro\Bundle\ActionBundle\Model\ButtonContext;
use Oro\Bundle\ActionBundle\Model\ButtonProviderExtensionInterface;
use Oro\Bundle\ActionBundle\Model\ButtonSearchContext;
use Oro\Bundle\WorkflowBundle\Entity\WorkflowItem;
use Oro\Bundle\WorkflowBundle\Model\Transition;
use Oro\Bundle\WorkflowBundle\Model\TransitionButton;
use Oro\Bundle\WorkflowBundle\Model\Workflow;
use Oro\Bundle\WorkflowBundle\Model\WorkflowData;
use Oro\Bundle\WorkflowBundle\Model\WorkflowRegistry;

class TransitionButtonProviderExtension implements ButtonProviderExtensionInterface
{
    /** @var WorkflowRegistry */
    protected $workflowRegistry;

    /** @var ApplicationsHelperInterface */
    protected $applicationsHelper;

    /**
     * @param WorkflowRegistry $workflowRegistry
     * @param ApplicationsHelperInterface $applicationsHelper
     */
    public function __construct(
        WorkflowRegistry $workflowRegistry,
        ApplicationsHelperInterface $applicationsHelper
    ) {
        $this->workflowRegistry = $workflowRegistry;
        $this->applicationsHelper = $applicationsHelper;
    }

    /**
     * {@inheritdoc}
     */
    public function find(ButtonSearchContext $buttonSearchContext)
    {
        $buttons = [];

        foreach ($this->workflowRegistry->getActiveWorkflows() as $workflow) {
            $transitions = $this->getInitTransitions($workflow, $buttonSearchContext);

            foreach ($transitions as $transition) {
                $workflowItem = $this->buildWorkflowItem($transition, $workflow, $buttonSearchContext);
                $isAvailable = $transition->isAvailable(clone $workflowItem);
                if ($isAvailable || !$transition->isUnavailableHidden()) {
                    $buttonContext = $this->generateButtonContext($transition, $buttonSearchContext);
                    $buttonContext->setEnabled($isAvailable);
                    $buttons[] = new TransitionButton($transition, $workflow, $buttonContext);
                }
            }
        }

        return $buttons;
    }
<commit_msg>BAP-12477: Update provider extension for WorkflowBundle - organize code<commit_after><?php

namespace Oro\Bundle\WorkflowBundle\Extension;

use Oro\Bundle\ActionBundle\Helper\ApplicationsHelperInterface;
use Oro\Bundle\ActionBundle\Model\ButtonContext;
use Oro\Bundle\ActionBundle\Model\ButtonProviderExtensionInterface;
use Oro\Bundle\ActionBundle\Model\ButtonSearchContext;
use Oro\Bundle\WorkflowBundle\Entity\WorkflowItem;
use Oro\Bundle\WorkflowBundle\Model\Transition;
use Oro\Bundle\WorkflowBundle\Model\TransitionButton;
use Oro\Bundle\WorkflowBundle\Model\Workflow;
use Oro\Bundle\WorkflowBundle\Model\WorkflowData;
use Oro\Bundle\WorkflowBundle\Model\WorkflowRegistry;

class TransitionButtonProviderExtension implements ButtonProviderExtensionInterface
{
    /** @var WorkflowRegistry */
    protected $workflowRegistry;

    /** @var ApplicationsHelperInterface */
    protected $applicationsHelper;

    /**
     * @param WorkflowRegistry $workflowRegistry
     * @param ApplicationsHelperInterface $applicationsHelper
     */
    public function __construct(WorkflowRegistry $workflowRegistry, ApplicationsHelperInterface $applicationsHelper)
    {
        $this->workflowRegistry = $workflowRegistry;
        $this->applicationsHelper = $applicationsHelper;
    }

    /**
     * {@inheritdoc}
     */
    public function find(ButtonSearchContext $buttonSearchContext)
    {
        $buttons = [];

        foreach ($this->workflowRegistry->getActiveWorkflows() as $workflow) {
            $transitions = $this->getInitTransitions($workflow, $buttonSearchContext);

            foreach ($transitions as $transition) {
                $workflowItem = $this->buildWorkflowItem($transition, $workflow, $buttonSearchContext);
                $isAvailable = $transition->isAvailable(clone $workflowItem);
                if ($isAvailable || !$transition->isUnavailableHidden()) {
                    $buttonContext = $this->generateButtonContext($transition, $buttonSearchContext);
                    $buttonContext->setEnabled($isAvailable);
                    $buttons[] = new TransitionButton($transition, $workflow, $buttonContext);
                }
            }
        }

        return $buttons;
    }

{'fraction_non_alphanumeric': 0.10099863822060826, 'fraction_numerical': 0.0011348161597821154, 'mean_word_length': 3.5292908530318603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '142328', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1109, 'n_words': 186}