Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
RebuildService
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Hyde\Framework\Services;
4
5use Hyde\Framework\StaticPageBuilder;
6
7/**
8 * Build static pages, but intelligently.
9 *
10 * Runs the static page builder for a given path.
11 */
12class RebuildService
13{
14    /**
15     * The source file to build.
16     * Should be relative to the Hyde installation.
17     *
18     * @var string
19     */
20    public string $filepath;
21
22    /**
23     * The model of the source file.
24     *
25     * @var string
26     *
27     * @internal
28     */
29    public string $model;
30
31    /**
32     * The page builder instance.
33     * Used to get debug output from the builder.
34     *
35     * @var StaticPageBuilder
36     */
37    public StaticPageBuilder $builder;
38
39    /**
40     * Construct the service class instance.
41     *
42     * @param  string  $filepath
43     */
44    public function __construct(string $filepath)
45    {
46        $this->filepath = $filepath;
47        $this->model = DiscoveryService::findModelFromFilePath($this->filepath);
48    }
49
50    /**
51     * Execute the service action.
52     */
53    public function execute(): StaticPageBuilder
54    {
55        return $this->builder = (new StaticPageBuilder(
56            DiscoveryService::getParserInstanceForModel(
57                $this->model,
58                basename(
59                    str_replace(
60                        DiscoveryService::getFilePathForModelClassFiles($this->model).'/',
61                        '',
62                        $this->filepath
63                    ),
64                    DiscoveryService::getFileExtensionForModelFiles($this->model)
65                )
66            )->get(),
67            true
68        ));
69    }
70}