Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| BuildActionRunner | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| canRunBuildAction | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| runBuildAction | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Concerns\Internal; |
| 4 | |
| 5 | use Hyde\Framework\Services\CollectionService; |
| 6 | use Hyde\Framework\Services\DiscoveryService; |
| 7 | use Hyde\Framework\StaticPageBuilder; |
| 8 | |
| 9 | /** |
| 10 | * Offloads build action logic for static site building commands. |
| 11 | * |
| 12 | * @see \Hyde\Framework\Commands\HydeBuildStaticSiteCommand |
| 13 | * |
| 14 | * @internal |
| 15 | */ |
| 16 | trait BuildActionRunner |
| 17 | { |
| 18 | /** @internal */ |
| 19 | protected function canRunBuildAction(array $collection, string $name, ?string $verb = null): bool |
| 20 | { |
| 21 | if (sizeof($collection) < 1) { |
| 22 | $this->line('No '.$name.' found. Skipping...'); |
| 23 | $this->newLine(); |
| 24 | |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | $this->comment(($verb ?? 'Creating')." $name..."); |
| 29 | |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | /** @internal */ |
| 34 | protected function runBuildAction(string $model): void |
| 35 | { |
| 36 | $collection = CollectionService::getSourceFileListForModel($model); |
| 37 | $modelName = $this->getModelPluralName($model); |
| 38 | if ($this->canRunBuildAction($collection, $modelName)) { |
| 39 | $this->withProgressBar( |
| 40 | $collection, |
| 41 | function ($basename) use ($model) { |
| 42 | new StaticPageBuilder( |
| 43 | DiscoveryService::getParserInstanceForModel( |
| 44 | $model, |
| 45 | $basename |
| 46 | )->get(), |
| 47 | true |
| 48 | ); |
| 49 | } |
| 50 | ); |
| 51 | $this->newLine(2); |
| 52 | } |
| 53 | } |
| 54 | } |