Passed
Push — master ( 2ca777...c8fc2a )
by Caen
03:22 queued 13s
created

GenerateBuildManifest::hashOutputPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Hyde\Framework\Actions\PostBuildTasks;
4
5
use Hyde\Framework\Contracts\AbstractBuildTask;
6
use Hyde\Framework\Hyde;
7
use Illuminate\Console\OutputStyle;
8
use Illuminate\Support\Collection;
9
10
/**
11
 * @see \Hyde\Framework\Testing\Unit\GenerateBuildManifestTest
12
 */
13
class GenerateBuildManifest extends AbstractBuildTask
14
{
15
    public static string $description = 'Generating build manifest';
16
17
    public function __construct(?OutputStyle $output = null)
18
    {
19
        parent::__construct($output);
20
        $this->output = null;
21
    }
22
23
    public function run(): void
24
    {
25
        $manifest = new Collection();
26
27
        /** @var \Hyde\Framework\Contracts\AbstractPage $page */
28
        foreach (Hyde::pages() as $page) {
29
            $manifest->push([
0 ignored issues
show
Bug introduced by
array('page' => $page->g...age->getOutputPath()))) of type array<string,mixed|null|string> is incompatible with the type Illuminate\Support\TValue expected by parameter $values of Illuminate\Support\Collection::push(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            $manifest->push(/** @scrutinizer ignore-type */ [
Loading history...
30
                'page' => $page->getSourcePath(),
31
                'source_hash' => md5_file(Hyde::path($page->getSourcePath())),
32
                'output_hash' => $this->hashOutputPath(Hyde::getSiteOutputPath($page->getOutputPath())),
33
            ]);
34
        }
35
36
        file_put_contents(Hyde::path(config('hyde.build_manifest_path',
37
            'storage/framework/cache/build-manifest.json')
38
        ), $manifest->toJson());
39
    }
40
41
    protected function hashOutputPath(string $path): ?string
42
    {
43
        return file_exists($path) ? md5_file($path) : null;
44
    }
45
}
46