Passed
Push — feature/open-with ( a1b551...a1d555 )
by Arnaud
10:49 queued 05:26
created

OpenWith::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
/**
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Command;
12
13
use Cecil\Exception\RuntimeException;
14
use Cecil\Util;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputDefinition;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Open content with an editor.
22
 */
23
class OpenWith extends AbstractCommand
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('open')
32
            ->setDescription('Open content with the editor')
33
            ->setDefinition(
34
                new InputDefinition([
35
                    new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'),
36
                ])
37
            )
38
            ->setHelp('Open content directory with the editor defined in the configuration file.)');
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @throws RuntimeException
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        try {
49
            if (!$this->hasEditor()) {
50
                $output->writeln('<comment>No editor configured.</comment>');
51
52
                return 0;
53
            }
54
            $output->writeln(\sprintf('<info>Opening content directory with %s...</info>', (string) $this->getBuilder()->getConfig()->get('editor')));
55
            $this->openEditor(Util::joinFile($this->getPath(), $this->getBuilder()->getConfig()->get('content.dir')));
0 ignored issues
show
Bug introduced by
It seems like $this->getBuilder()->get...g()->get('content.dir') can also be of type null; however, parameter $path of Cecil\Util::joinFile() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
            $this->openEditor(Util::joinFile($this->getPath(), /** @scrutinizer ignore-type */ $this->getBuilder()->getConfig()->get('content.dir')));
Loading history...
56
        } catch (\Exception $e) {
57
            throw new RuntimeException(\sprintf($e->getMessage()));
58
        }
59
60
        return 0;
61
    }
62
}
63