BaselinePostsCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 52
ccs 14
cts 16
cp 0.875
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 15 3
A configure() 0 3 1
A getFrom() 0 3 1
1
<?php
2
3
namespace App\Modules\Posts\Api\Command;
4
5
use App\Modules\Posts\Api\PostsApiInterface;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class BaselinePostsCommand extends Command
12
{
13
14
    protected static $defaultName = 'app:posts:baseline';
15
16
    private ?\DateTime $from = null;
17
18
    /**
19
     * @param PostsApiInterface $postsApi
20
     */
21
    public function __construct(
22 1
        private PostsApiInterface $postsApi
23
    )
24
    {
25
        parent::__construct();
26 1
    }
27 1
28
29
    protected function configure(): void
30 1
    {
31
        $this->addArgument('from', InputArgument::OPTIONAL, 'from');
32 1
    }
33 1
34
    /**
35
     * @param InputInterface $input
36
     * @param OutputInterface $output
37
     * @return int
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output): int
40 1
    {
41
42
        $from = $input->getArgument("from");
43 1
        if ($from != null) {
44 1
            $this->from = \DateTime::createFromFormat("Y-m-d H:i:s", $from . "00:00:00");
45
        }
46
        $this->postsApi->baseline($this);
47 1
        if ($from != null) {
48 1
            $output->writeln(sprintf("Successfully base-lined Posts from %s", $from));
49
        } else {
50
            $output->writeln(sprintf("Successfully base-lined all Posts"));
51 1
        }
52
53
        return Command::SUCCESS;
54 1
55
    }
56
57
    /**
58
     * @return \DateTime|null
59
     */
60
    public function getFrom(): ?\DateTime
61 1
    {
62
        return $this->from;
63 1
    }
64
65
66
67
68
}