BaselinePostsCommand::getFrom()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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
}