PHP Linter

OK

composer validate

OK

Copy/Paste Detector

phpcpd 6.0.3 by Sebastian Bergmann.

Found 3 clones with 190 duplicated lines in 4 files:

  - /app/swissup/module-diagnostic/Console/Command/DisableSwissupCommand.php:101-184 (83 lines)
    /app/swissup/module-diagnostic/Console/Command/DisableThirdpartyCommand.php:102-185

    private function getEnabledSwissupModules(array $allSwissupModules): array
    {
        $enabledModules = [];
        
        foreach ($allSwissupModules as $moduleName) {
            if ($this->moduleManager->isEnabled($moduleName)) {
                $enabledModules[] = $moduleName;
            }
        }
        
        return $enabledModules;
    }

    private function displayModulesTable(OutputInterface $output, array $allModules, string $title)
    {
        $this->displaySectionHeader($output, "๐Ÿ“‹ $title");
        
        $table = new Table($output);
        $table->setHeaders(['<header>Module Name</header>', '<header>Current Status</header>']);
        $table->setStyle('box-double');
        $table->setColumnWidth(0, 40);
        $table->setColumnWidth(1, 15);

        foreach ($allModules as $moduleName) {
            $isEnabled = $this->moduleManager->isEnabled($moduleName);
            $status = $isEnabled ? '<fg=green>โœ… Enabled</>' : '<fg=red>โŒ Disabled</>';
            
            $table->addRow([
                "<comment>$moduleName</comment>",
                $status
            ]);
        }

        $table->render();
        $this->displaySectionSeparator($output);
    }

    private function saveModulesState(array $enabledModules, OutputInterface $output)
    {
        $this->displaySectionHeader($output, '๐Ÿ’พ SAVING CURRENT STATE');
        
        $stateFile = BP . '/' . self::STATE_FILE;
        $stateData = [
            'timestamp' => date('Y-m-d H:i:s'),
            'enabled_modules' => $enabledModules
        ];
        
        $dir = dirname($stateFile);
        if (!is_dir($dir)) {
            mkdir($dir, 0755, true);
        }
        
        if (file_put_contents($stateFile, json_encode($stateData, JSON_PRETTY_PRINT))) {
            $output->writeln("    <fg=white>โ”‚</> <success>โœ… State saved to: " . self::STATE_FILE . "</success>");
            $output->writeln("    <fg=white>โ”‚</> <comment>๐Ÿ“Š Enabled modules count: " . count($enabledModules) . "</comment>");
        } else {
            throw new \Exception("Failed to save state file: $stateFile");
        }
        
        $this->displaySectionSeparator($output);
    }

    private function disableModules(array $modules, OutputInterface $output)
    {
        $this->displaySectionHeader($output, '๐Ÿ”„ DISABLING MODULES');
        
        $output->writeln("    <fg=white>โ”‚</> <comment>Disabling " . count($modules) . " module(s)...</comment>");
        $output->writeln('');
        
        try {
            $this->moduleStatus->setIsEnabled(false, $modules);
            
            foreach ($modules as $moduleName) {
                $output->writeln("    <fg=white>โ”‚</> <fg=red>โŒ</> <comment>$moduleName</comment>");
            }
            
            $output->writeln('');
            $output->writeln("    <fg=white>โ”‚</> <success>โœ… All modules disabled successfully</success>");
        } catch (\Exception $e) {
            throw new \Exception("Failed to disable modules: " . $e->getMessage());
        }
        
        $this->displaySectionSeparator($output);

  - /app/swissup/module-diagnostic/Console/Command/EnableSwissupCommand.php:104-171 (67 lines)
    /app/swissup/module-diagnostic/Console/Command/EnableThirdpartyCommand.php:105-172

            if (strpos($moduleName, 'Swissup_') === 0) {
                $swissupModules[] = $moduleName;
            }
        }
        
        sort($swissupModules);
        return $swissupModules;
    }

    private function loadModulesState(string $stateFile, OutputInterface $output): array
    {
        $this->displaySectionHeader($output, '๐Ÿ“‚ LOADING SAVED STATE');
        
        $stateContent = file_get_contents($stateFile);
        $savedState = json_decode($stateContent, true);
        
        if (!$savedState || !isset($savedState['enabled_modules'])) {
            throw new \Exception("Invalid state file format");
        }
        
        $output->writeln("    <fg=white>โ”‚</> <success>โœ… State loaded from: " . self::STATE_FILE . "</success>");
        $output->writeln("    <fg=white>โ”‚</> <comment>๐Ÿ“… Saved on: " . ($savedState['timestamp'] ?? 'Unknown') . "</comment>");
        $output->writeln("    <fg=white>โ”‚</> <comment>๐Ÿ“Š Modules to enable: " . count($savedState['enabled_modules']) . "</comment>");
        
        $this->displaySectionSeparator($output);
        
        return $savedState;
    }

    private function displayModulesTable(OutputInterface $output, array $allModules, array $toEnable, string $title)
    {
        $this->displaySectionHeader($output, "๐Ÿ“‹ $title");
        
        $table = new Table($output);
        $table->setHeaders(['<header>Module Name</header>', '<header>Current Status</header>', '<header>Will Enable</header>']);
        $table->setStyle('box-double');
        $table->setColumnWidth(0, 40);
        $table->setColumnWidth(1, 15);
        $table->setColumnWidth(2, 12);

        foreach ($allModules as $moduleName) {
            $isEnabled = $this->moduleManager->isEnabled($moduleName);
            $willEnable = in_array($moduleName, $toEnable);
            
            $status = $isEnabled ? '<fg=green>โœ… Enabled</>' : '<fg=red>โŒ Disabled</>';
            $willEnableText = $willEnable ? '<fg=green>โœ… Yes</>' : '<fg=gray>โ€”</>';
            
            $table->addRow([
                "<comment>$moduleName</comment>",
                $status,
                $willEnableText
            ]);
        }

        $table->render();
        $this->displaySectionSeparator($output);
    }

    private function confirmAction(InputInterface $input, OutputInterface $output, int $moduleCount): bool
    {
        if ($input->getOption('no-interaction')) {
            return true;
        }
        
        $helper = $this->getHelper('question');
        $question = new ConfirmationQuestion(
            "<fg=yellow>โš ๏ธ  Are you sure you want to enable $moduleCount Swissup module(s)? [y/N] </>",

  - /app/swissup/module-diagnostic/Console/Command/EnableSwissupCommand.php:171-211 (40 lines)
    /app/swissup/module-diagnostic/Console/Command/EnableThirdpartyCommand.php:172-212

            false
        );
        
        return $helper->ask($input, $output, $question);
    }

    private function enableModules(array $modules, OutputInterface $output)
    {
        $this->displaySectionHeader($output, '๐Ÿ”„ ENABLING MODULES');
        
        $output->writeln("    <fg=white>โ”‚</> <comment>Enabling " . count($modules) . " module(s)...</comment>");
        $output->writeln('');
        
        try {
            $this->moduleStatus->setIsEnabled(true, $modules);
            
            foreach ($modules as $moduleName) {
                $output->writeln("    <fg=white>โ”‚</> <fg=green>โœ…</> <comment>$moduleName</comment>");
            }
            
            $output->writeln('');
            $output->writeln("    <fg=white>โ”‚</> <success>โœ… All modules enabled successfully</success>");
        } catch (\Exception $e) {
            throw new \Exception("Failed to enable modules: " . $e->getMessage());
        }
        
        $this->displaySectionSeparator($output);
    }

    private function removeStateFile(string $stateFile, OutputInterface $output)
    {
        $this->displaySectionHeader($output, '๐Ÿงน CLEANUP');
        
        if (unlink($stateFile)) {
            $output->writeln("    <fg=white>โ”‚</> <success>โœ… State file removed: " . self::STATE_FILE . "</success>");
        } else {
            $output->writeln("    <fg=white>โ”‚</> <warning>โš ๏ธ  Could not remove state file: " . self::STATE_FILE . "</warning>");
        }
        
        $this->displaySectionSeparator($output);

11.77% duplicated lines out of 1614 total lines of code.
Average size of duplication is 63 lines, largest clone has 83 of lines

Time: 00:00.004, Memory: 4.00 MB

PHP Stan

OK

Magento Coding Standard

OK