Passed
Push — master ( d94c8e...28d464 )
by Caen
02:56 queued 12s
created

HydeBuildRssFeedCommand::getExecutionTimeInMs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework\Commands;
4
5
use Hyde\Framework\Concerns\ActionCommand;
6
use Hyde\Framework\Helpers\Features;
7
use Hyde\Framework\Hyde;
8
use Hyde\Framework\Services\RssFeedService;
9
10
/**
11
 * Hyde Command to run the Build Process for the RSS Feed.
12
 *
13
 * @see \Hyde\Framework\Testing\Feature\Commands\HydeBuildRssFeedCommandTest
14
 */
15
class HydeBuildRssFeedCommand extends ActionCommand
16
{
17
    /**
18
     * The signature of the command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'build:rss {--no-api : (Not yet supported)}';
23
24
    /**
25
     * The description of the command.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Generate the RSS feed';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @return int
35
     */
36
    public function handle(): int
37
    {
38
        if (! Features::rss()) {
39
            $this->error('Cannot generate an RSS feed, please check your configuration.');
40
41
            return 1;
42
        }
43
44
        $this->action('Generating RSS feed', function () {
45
            file_put_contents(
46
                Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()),
47
                RssFeedService::generateFeed()
48
            );
49
        }, sprintf('Created <info>%s</info>', RssFeedService::getDefaultOutputFilename()));
50
51
        return 0;
52
    }
53
}
54