• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

onmoon / openapi-server-bundle / 15881876638

25 Jun 2025 04:28PM UTC coverage: 80.585% (-0.5%) from 81.095%
15881876638

Pull #196

github

web-flow
Merge 90ce8070d into c35fba5f2
Pull Request #196: Fix minimum versions install

9 of 29 new or added lines in 5 files covered. (31.03%)

44 existing lines in 12 files now uncovered.

1378 of 1710 relevant lines covered (80.58%)

3.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/Command/DeleteGeneratedCodeCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace OnMoon\OpenApiServerBundle\Command;
6

7
use FilesystemIterator;
8
use RecursiveDirectoryIterator;
9
use RecursiveIteratorIterator;
10
use SplFileInfo;
11
use Symfony\Component\Console\Attribute\AsCommand;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Helper\QuestionHelper;
14
use Symfony\Component\Console\Input\InputDefinition;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Question\ConfirmationQuestion;
19

20
use function is_dir;
21
use function Safe\rmdir;
22
use function Safe\unlink;
23
use function sprintf;
24

25
#[AsCommand(name: 'open-api:delete')]
26
final class DeleteGeneratedCodeCommand extends Command
27
{
28
    public const COMMAND = 'open-api:delete';
29

30
    private string $rootPath;
31

32
    public function __construct(string $rootPath, ?string $name = null)
33
    {
34
        $this->rootPath = $rootPath;
2✔
35

36
        parent::__construct($name);
2✔
37
    }
38

39
    /**
40
     * phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
41
     *
42
     * @var string|null
43
     */
44
    protected static $defaultName = self::COMMAND;
45

46
    protected function configure(): void
47
    {
48
        $this
2✔
49
            ->setDescription('Deletes API server code generated by the bundle')
2✔
50
            ->setDefinition(
2✔
51
                new InputDefinition([
2✔
52
                    new InputOption('yes', 'y', InputOption::VALUE_NONE, 'Disable confirmation prompt'),
2✔
53
                ])
2✔
54
            );
2✔
55
    }
56

57
    protected function execute(InputInterface $input, OutputInterface $output): int
58
    {
59
        if (! (bool) $input->getOption('yes')) {
2✔
60
            /** @var QuestionHelper $questionHelper */
61
            $questionHelper = $this->getHelper('question');
2✔
62
            $question       = new ConfirmationQuestion(
2✔
63
                sprintf(
2✔
64
                    'Delete all contents of the directory %s? (y/n): ',
2✔
65
                    $this->rootPath
2✔
66
                ),
2✔
67
                false
2✔
68
            );
2✔
69

70
            if (! (bool) $questionHelper->ask($input, $output, $question)) {
2✔
71
                return 0;
1✔
72
            }
73
        }
74

75
        $this->recursiveDelete($this->rootPath);
1✔
76
        $output->writeln(sprintf('All contents of directory were deleted: %s', $this->rootPath));
1✔
77

78
        return 0;
1✔
79
    }
80

81
    private function recursiveDelete(string $directoryPath): void
82
    {
83
        if (! is_dir($directoryPath)) {
1✔
UNCOV
84
            return;
×
85
        }
86

87
        $iterator = new RecursiveIteratorIterator(
1✔
88
            new RecursiveDirectoryIterator(
1✔
89
                $directoryPath,
1✔
90
                FilesystemIterator::SKIP_DOTS
1✔
91
            ),
1✔
92
            RecursiveIteratorIterator::CHILD_FIRST
1✔
93
        );
1✔
94

95
        /** @var SplFileInfo $directoryOrFile */
96
        foreach ($iterator as $directoryOrFile) {
1✔
97
            if ($directoryOrFile->isDir()) {
1✔
UNCOV
98
                rmdir($directoryOrFile->getPathname());
×
99
            } else {
100
                unlink($directoryOrFile->getPathname());
1✔
101
            }
102
        }
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc