Failed Conditions
Push — master ( 0b1cfb...8905c0 )
by Michał
02:34
created

ViewOneNote::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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
    protected function configure()
21
    {
22
        $this
23
            ->setName('barenote:note:one')
24
            ->setDescription('Detailed information about one of your notes')
25
            ->setHelp('Help for command');
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $client = $this->getApplication()->getClient();
31
        /** @var QuestionHelper $helper */
32
        $helper = $this->getHelper('question');
33
34
        $question = new Question('Please provide ID of the note you would like to read' . PHP_EOL, '1');
35
        $question->setAutocompleterValues(['1']);
36
        $id   = $helper->ask($input, $output, $question);
37
        $note = $client->getNotesEndpoint()->getOne(new NoteId((int)$id));
38
39
        $output->writeln("<info>ID:</info>" . PHP_EOL . $note->getId()->getValue());
1 ignored issue
show
Coding Style Comprehensibility introduced by
The string literal <info>ID:</info> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
40
        $output->writeln("<info>Title:</info>" . PHP_EOL . $note->getTitle());
1 ignored issue
show
Coding Style Comprehensibility introduced by
The string literal <info>Title:</info> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
41
        $output->writeln("<info>Content:</info>" . PHP_EOL . $note->getContent());
1 ignored issue
show
Coding Style Comprehensibility introduced by
The string literal <info>Content:</info> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
42
43
        $question = new ConfirmationQuestion('Do you want to exit the app? (y/N)' . PHP_EOL, false);
44
45
        if ($helper->ask($input, $output, $question)) {
46
            exit(0);
1 ignored issue
show
Coding Style Compatibility introduced by
The method execute() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
47
        }
48
    }
49
}