Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| HydeBuildRssFeedCommand | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| handle | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| runPreflightCheck | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getExecutionTimeInMs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Commands; |
| 4 | |
| 5 | use Hyde\Framework\Hyde; |
| 6 | use Hyde\Framework\Services\RssFeedService; |
| 7 | use LaravelZero\Framework\Commands\Command; |
| 8 | |
| 9 | /** |
| 10 | * Hyde Command to run the Build Process for the RSS Feed. |
| 11 | * |
| 12 | * @see \Tests\Feature\Commands\HydeBuildRssFeedCommandTest |
| 13 | */ |
| 14 | class HydeBuildRssFeedCommand extends Command |
| 15 | { |
| 16 | /** |
| 17 | * The signature of the command. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | protected $signature = 'build:rss {--no-api : (Not yet supported)}'; |
| 22 | |
| 23 | /** |
| 24 | * The description of the command. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | protected $description = 'Generate the RSS feed'; |
| 29 | |
| 30 | /** |
| 31 | * Execute the console command. |
| 32 | * |
| 33 | * @return int |
| 34 | */ |
| 35 | public function handle(): int |
| 36 | { |
| 37 | $actionTime = microtime(true); |
| 38 | |
| 39 | if (! $this->runPreflightCheck()) { |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | $this->comment('Generating RSS feed...'); |
| 44 | file_put_contents(Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()), RssFeedService::generateFeed()); |
| 45 | $this->line(' > Created <info>'.RssFeedService::getDefaultOutputFilename().'</> in '.$this->getExecutionTimeInMs($actionTime)."ms\n"); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | protected function runPreflightCheck(): bool |
| 51 | { |
| 52 | if (! RssFeedService::canGenerateFeed()) { |
| 53 | $this->error('Cannot generate an RSS feed, please check your configuration.'); |
| 54 | |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | protected function getExecutionTimeInMs(float $timeStart): string |
| 62 | { |
| 63 | return number_format(((microtime(true) - $timeStart) * 1000), 2); |
| 64 | } |
| 65 | } |