Passed
Push — master ( 1100a1...b83671 )
by Caen
03:15 queued 14s
created

GenerateSearch   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 13
c 4
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 13 3
A then() 0 3 1
A guesstimateGenerationTime() 0 3 1
1
<?php
2
3
namespace Hyde\Framework\Actions\PostBuildTasks;
4
5
use Hyde\Framework\Concerns\InteractsWithDirectories;
6
use Hyde\Framework\Contracts\AbstractBuildTask;
7
use Hyde\Framework\Services\DiscoveryService;
8
use Hyde\Framework\Services\DocumentationSearchService;
9
10
class GenerateSearch extends AbstractBuildTask
11
{
12
    use InteractsWithDirectories;
13
14
    public static string $description = 'Generating search index';
15
16
    public function run(): void
17
    {
18
        $expected = $this->guesstimateGenerationTime();
19
        if ($expected >= 1) {
20
            $this->line("<fg=gray>This will take an estimated $expected seconds. Terminal may seem non-responsive.</>");
21
        }
22
23
        DocumentationSearchService::generate();
24
25
        if (config('docs.create_search_page', true)) {
26
            $directory = DocumentationSearchService::generateSearchPage();
27
28
            $this->createdSiteFile("$directory/search.html");
29
        }
30
    }
31
32
    public function then(): void
33
    {
34
        $this->createdSiteFile(DocumentationSearchService::$filePath)->withExecutionTime();
35
    }
36
37
    /** @internal Estimated processing time per file in ms */
38
    public static float $guesstimationFactor = 52.5;
39
40
    protected function guesstimateGenerationTime(): int|float
41
    {
42
        return (int) round(count(DiscoveryService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000;
43
    }
44
}
45