ViewOneNote::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 2
eloc 13
nc 2
nop 2
1
<?php
2
namespace BarenoteCli\Command\Note;
3
4
use Barenote\Domain\Identity\NoteId;
5
use BarenoteCli\BarenoteApplication;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Helper\QuestionHelper;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Question\ConfirmationQuestion;
11
use Symfony\Component\Console\Question\Question;
12
13
/**
14
 * Class ViewOneNote
15
 * @package BarenoteCli\Command\Note
16
 * @method BarenoteApplication getApplication()
17
 */
18
class ViewOneNote extends Command
19
{
20
    const KEY = 'barenote:note:one';
21
22
    protected function configure()
23
    {
24
        $this
25
            ->setName(self::KEY)
26
            ->setDescription('Detailed information about one of your notes')
27
            ->setHelp('Help for command');
28
    }
29
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $client = $this->getApplication()->getClient();
33
        /** @var QuestionHelper $helper */
34
        $helper = $this->getHelper('question');
35
36
        $question = new Question('Please provide ID of the note you would like to read' . PHP_EOL, '1');
37
        $question->setAutocompleterValues(['1']);
38
        $id   = $helper->ask($input, $output, $question);
39
        $note = $client->getNotesEndpoint()->getOne(new NoteId((int)$id));
40
41
        $output->writeln("<info>ID:</info>" . PHP_EOL . $note->getId()->getValue());
42
        $output->writeln("<info>Title:</info>" . PHP_EOL . $note->getTitle());
43
        $output->writeln("<info>Content:</info>" . PHP_EOL . $note->getContent());
44
45
        $question = new ConfirmationQuestion('Do you want to exit the app? (y/N)' . PHP_EOL, false);
46
47
        if ($helper->ask($input, $output, $question)) {
48
            exit(0);
49
        }
50
    }
51
}