Diff   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 45
ccs 14
cts 22
cp 0.6364
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpDefinition() 0 8 1
A performAction() 0 25 6
1
<?php
2
3
namespace Swaggest\JsonCli;
4
5
6
use Yaoi\Command;
7
8
class Diff extends BaseDiff
9
{
10
    public $prettyShort;
11
    public $merge;
12
13
    /**
14
     * @param Command\Definition $definition
15
     * @param \stdClass|static $options
16 1
     */
17
    public static function setUpDefinition(Command\Definition $definition, $options)
18 1
    {
19 1
        parent::setUpDefinition($definition, $options);
20 1
        $definition->description = 'Make patch from two json documents, output to STDOUT';
21 1
        $options->prettyShort = Command\Option::create()
22 1
            ->setDescription('Pretty short format');
23
        $options->merge = Command\Option::create()
24
            ->setDescription('Use merge patch (RFC 7386)');
25 1
    }
26
27 1
28 1
    public function performAction()
29
    {
30
        $this->prePerform();
31
        if (null === $this->diff) {
32 1
            return;
33
        }
34 1
35 1
        if ($this->merge) {
36
            $this->out = $this->diff->getMergePatch();
37
        } else {
38
            $this->out = $this->diff->getPatch();
39
            $outJson = $this->out->jsonSerialize();
40
            if ($this->prettyShort && !empty($outJson)) {
41
                $out = '[';
42
                foreach ($outJson as $item) {
43
                    $out .= "\n    " . json_encode($item, JSON_UNESCAPED_SLASHES) . ',';
44
                }
45
                $out = substr($out, 0, -1);
46 1
                $out .= "\n]";
47 1
                $this->response->addContent($out);
48
                return;
49
            }
50
        }
51
52
        $this->postPerform();
53
    }
54
}