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

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

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

96.15
/src/Tempest/Router/src/Static/StaticCleanCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Router\Static;
6

7
use FilesystemIterator;
8
use RecursiveDirectoryIterator;
9
use RecursiveIteratorIterator;
10
use SplFileInfo;
11
use Tempest\Console\ConsoleCommand;
12
use Tempest\Console\HasConsole;
13
use Tempest\Console\Middleware\CautionMiddleware;
14
use Tempest\Console\Middleware\ForceMiddleware;
15
use Tempest\Core\Kernel;
16

17
final readonly class StaticCleanCommand
18
{
19
    use HasConsole;
20

21
    public function __construct(
1✔
22
        private Kernel $kernel,
23
    ) {}
1✔
24

25
    #[ConsoleCommand(
1✔
26
        name: 'static:clean',
27
        description: 'Removes statically generated pages',
28
        middleware: [ForceMiddleware::class, CautionMiddleware::class],
29
    )]
30
    public function __invoke(): void
31
    {
32
        $directoryIterator = new RecursiveDirectoryIterator($this->kernel->root . '/public');
1✔
33
        $directoryIterator->setFlags(FilesystemIterator::SKIP_DOTS);
1✔
34

35
        $this->removeFiles($directoryIterator);
1✔
36
        $this->removeEmptyDirectories($directoryIterator);
1✔
37

38
        $this->success('Done.');
1✔
39
    }
40

41
    private function removeFiles(RecursiveDirectoryIterator $directoryIterator): void
1✔
42
    {
43
        /** @var SplFileInfo[] $files */
44
        $files = [];
1✔
45

46
        /** @var SplFileInfo $file */
47
        foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
1✔
48
            if ($file->getExtension() === 'html') {
1✔
49
                $files[] = $file;
1✔
50
            }
51
        }
52

53
        foreach ($files as $file) {
1✔
54
            unlink($file->getPathname());
1✔
55

56
            $pathName = str_replace('\\', '/', $file->getPathname());
1✔
57

58
            $this->writeln("- <u>{$pathName}</u> removed");
1✔
59
        }
60
    }
61

62
    private function removeEmptyDirectories(RecursiveDirectoryIterator $directoryIterator): void
1✔
63
    {
64
        /** @var SplFileInfo $file */
65
        foreach (new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
1✔
66
            if (! $file->isDir()) {
1✔
67
                continue;
1✔
68
            }
69

70
            if (count(glob($file->getPathname() . '/*')) > 0) {
1✔
UNCOV
71
                continue;
×
72
            }
73

74
            rmdir($file->getPathname());
1✔
75

76
            $pathName = str_replace('\\', '/', $file->getPathname());
1✔
77

78
            $this->writeln("- <u>{$pathName}</u> directory removed");
1✔
79
        }
80
    }
81
}
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