ViewOneNote   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 9
dl 0
loc 34
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 21 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
}