Completed
Pull Request — master (#47)
by Pierre
05:18
created

RemoveTranslationCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
rs 9.3142
cc 2
eloc 13
nc 2
nop 2
1
<?php
2
3
namespace Openl10n\Cli\Command;
4
5
use Openl10n\Sdk\EntryPoint\ProjectEntryPoint;
6
use Openl10n\Sdk\EntryPoint\TranslationEntryPoint;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class RemoveTranslationCommand extends AbstractCommand
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('remove-translation')
20
            ->setDescription('Removes a translation given its identifier')
21
            ->addArgument(
22
                'identifier',
23
                InputArgument::REQUIRED,
24
                'Translation\'s identifier you want to remove'
25
            )
26
        ;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $api = $this->get('api');
35
        /* @var ProjectEntryPoint $projectApi */
36
        $projectApi = $api->getEntryPoint('project');
37
        /* @var TranslationEntryPoint $translationApi */
38
        $translationApi = $api->getEntryPoint('translation');
39
40
        $projectSlug = $this->get('project_handler')->getProjectSlug();
41
        $project = $projectApi->get($projectSlug);
42
43
        $identifier = $input->getArgument('identifier');
44
45
        $translation = $translationApi->findOneByIdentifier($project, $identifier);
0 ignored issues
show
Bug introduced by
The method findOneByIdentifier() does not seem to exist on object<Openl10n\Sdk\Entr...\TranslationEntryPoint>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        if (!$translation) {
47
            $output->writeln(sprintf('<error>Translation "%s" does not exist</error>', $identifier));
48
        } else {
49
            $output->writeln(sprintf('<info>Removing</info> translation <comment>"%s"</comment>', $identifier));
50
            $translationApi->delete($translation);
51
        }
52
    }
53
}
54