Completed
Push — master ( d6e24f...c5cb7d )
by Viacheslav
02:06
created

Resolve::performAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 10
ccs 4
cts 7
cp 0.5714
crap 2.3149
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Swaggest\JsonCli;
4
5
6
use Swaggest\JsonDiff\Exception;
7
use Swaggest\JsonDiff\JsonPointer;
8
use Yaoi\Command\Definition;
9
use Yaoi\Command\Option;
10
11
class Resolve extends Base
12
{
13
    public $pointer;
14
    public $path;
15
16
    /**
17
     * @param Definition $definition
18
     * @param \stdClass|static $options
19
     */
20 1
    static function setUpDefinition(Definition $definition, $options)
21
    {
22 1
        $options->path = Option::create()->setType()->setIsUnnamed()
23 1
            ->setDescription('Path to JSON/YAML file');
24 1
        $options->pointer = Option::create()->setType()->setIsUnnamed()
25 1
            ->setDescription('JSON Pointer, example /key4/1/a');
26 1
    }
27
28 1
    public function performAction()
29
    {
30 1
        $jsonData = $this->readData($this->path);
31
        try {
32 1
            $this->out = JsonPointer::getByPointer($jsonData, $this->pointer);
33
        } catch (Exception $e) {
34
            $this->response->error($e->getMessage());
35
            die(1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
36
        }
37 1
        $this->postPerform();
38 1
    }
39
40
}