<commit_before><?php

namespace App\Command\Migrate;

use App\Entity\Job\TaskTypeOptions;
use Doctrine\ORM\EntityManagerInterface;
use App\Services\ApplicationStateService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RemoveJSJobTaskTypeOptionsCommand extends Command
{
    const RETURN_CODE_OK = 0;
    const RETURN_CODE_IN_MAINTENANCE_READ_ONLY_MODE = 1;

    /**
     * @var ApplicationStateService
     */
    private $applicationStateService;

    /**
     * @var EntityManagerInterface
     */
    private $entityManager;

    /**
     * @param ApplicationStateService $applicationStateService
     * @param EntityManagerInterface $entityManager
     * @param string|null $name
     */
    public function __construct(
        ApplicationStateService $applicationStateService,
        EntityManagerInterface $entityManager,
        $name = null
    ) {
        parent::__construct($name);

        $this->applicationStateService = $applicationStateService;
        $this->entityManager = $entityManager;
    }

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('simplytestable:migrate:remove-js-job-task-type-options')
            ->setDescription('Remove JS JobTaskTypeOption entities')
            ->addOption('dry-run');
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($this->applicationStateService->isInReadOnlyMode()) {
            $output->writeln('In maintenance-read-only mode, I can\'t do that right now');
            return self::RETURN_CODE_IN_MAINTENANCE_READ_ONLY_MODE;
        }

        $isDryRun = $input->getOption('dry-run');

        $entityRepository = $this->entityManager->getRepository(TaskTypeOptions::class);

        $output->write('<info>Finding JS JobTaskTypeOption entities ... </info>');

        $entities = $entityRepository->findAll();
        $entityCount = count($entities);

        $output->writeln('found <comment>' . $entityCount . '</comment>');

        foreach ($entities as $entityIndex => $entity) {
            $entityNumber = $entityIndex + 1;

            $output->writeln(sprintf(
                '<info>Removing</info> #%s (%s of %s)',
                $entity->getId(),
                $entityNumber,
                $entityCount
            ));

            $this->entityManager->remove($entity);

            if (!$isDryRun) {
                $this->entityManager->flush();
            }
        }

        $output->writeln('<info>Done</info>');

        return self::RETURN_CODE_OK;
    }
}<commit_msg>Fix RemoveJSJobTaskTypeOptionsCommand (#363)<commit_after><?php

namespace App\Command\Migrate;

use App\Entity\Job\TaskTypeOptions;
use App\Entity\Task\Type\Type;
use Doctrine\ORM\EntityManagerInterface;
use App\Services\ApplicationStateService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RemoveJSJobTaskTypeOptionsCommand extends Command
{
    const RETURN_CODE_OK = 0;
    const RETURN_CODE_IN_MAINTENANCE_READ_ONLY_MODE = 1;

    /**
     * @var ApplicationStateService
     */
    private $applicationStateService;

    /**
     * @var EntityManagerInterface
     */
    private $entityManager;

    /**
     * @param ApplicationStateService $applicationStateService
     * @param EntityManagerInterface $entityManager
     * @param string|null $name
     */
    public function __construct(
        ApplicationStateService $applicationStateService,
        EntityManagerInterface $entityManager,
        $name = null
    ) {
        parent::__construct($name);

        $this->applicationStateService = $applicationStateService;
        $this->entityManager = $entityManager;
    }

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('simplytestable:migrate:remove-js-job-task-type-options')
            ->setDescription('Remove JS JobTaskTypeOption entities')
            ->addOption('dry-run');
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($this->applicationStateService->isInReadOnlyMode()) {
            $output->writeln('In maintenance-read-only mode, I can\'t do that right now');
            return self::RETURN_CODE_IN_MAINTENANCE_READ_ONLY_MODE;
        }

        $isDryRun = $input->getOption('dry-run');

        $jobTaskTypeOptionsRepository = $this->entityManager->getRepository(TaskTypeOptions::class);
        $taskTypeRepository = $this->entityManager->getRepository(Type::class);
        $jsTaskType = $taskTypeRepository->findOneBy([
            'name' => 'JS static analysis',
        ]);

        $output->write('<info>Finding JS JobTaskTypeOption entities ... </info>');

        $jobTaskTypeOptionsCollection = $jobTaskTypeOptionsRepository->findBy([
            'taskType' => $jsTaskType,
        ]);
        $jobTaskTypeOptionsCount = count($jobTaskTypeOptionsCollection);

        $output->writeln('found <comment>' . $jobTaskTypeOptionsCount . '</comment>');

        foreach ($jobTaskTypeOptionsCollection as $jobTaskTypeOptionsIndex => $jobTaskTypeOptions) {
            $jobTaskTypeOptionsNumber = $jobTaskTypeOptionsIndex + 1;

            $output->writeln(sprintf(
                '<info>Removing</info> #%s (%s of %s)',
                $jobTaskTypeOptions->getId(),
                $jobTaskTypeOptionsNumber,
                $jobTaskTypeOptionsCount
            ));

            $this->entityManager->remove($jobTaskTypeOptions);

            if (!$isDryRun) {
                $this->entityManager->flush();
            }
        }

        $output->writeln('<info>Done</info>');

        return self::RETURN_CODE_OK;
    }
}
{'fraction_non_alphanumeric': 0.12102443923669233, 'fraction_numerical': 0.0015065282892534316, 'mean_word_length': 2.7157960199004973, 'pattern_counts': {'":': 0, '<': 21, '<?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': '6269140', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1604, 'n_words': 270}