BaseDiff::setUpDefinition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Swaggest\JsonCli;
4
5
use Swaggest\JsonDiff\Exception;
6
use Swaggest\JsonDiff\JsonDiff;
7
use Yaoi\Command;
8
9
abstract class BaseDiff extends Base
10
{
11
    public $originalPath;
12
    public $newPath;
13
    public $rearrangeArrays;
14
15 1
    /**
16
     * @param Command\Definition $definition
17 1
     * @param \stdClass|static $options
18 1
     */
19
    static function setUpDefinition(Command\Definition $definition, $options)
20 1
    {
21 1
        $options->originalPath = Command\Option::create()->setIsUnnamed()->setIsRequired()
22
            ->setDescription('Path to old (original) json file');
23 1
24 1
        $options->newPath = Command\Option::create()->setIsUnnamed()->setIsRequired()
25
            ->setDescription('Path to new json file');
26 1
27 1
        $options->rearrangeArrays = Command\Option::create()
28
            ->setDescription('Rearrange arrays to match original');
29
30
        parent::setUpDefinition($definition, $options);
31
    }
32 3
33
    /** @var JsonDiff */
34 3
    protected $diff;
35 3
36
    protected function prePerform()
37
    {
38
        $original = Base::readJsonOrYaml($this->originalPath, $this->response);
39
        $new = Base::readJsonOrYaml($this->newPath, $this->response);
40 3
41 3
        $options = 0;
42
        if ($this->rearrangeArrays) {
43
            $options += JsonDiff::REARRANGE_ARRAYS;
44
        }
45
        try {
46 3
            $this->diff = new JsonDiff($original, $new, $options);
47 3
        } catch (Exception $e) {
48 3
            $this->response->error($e->getMessage());
49
            return;
50
        }
51 3
52
        $this->out = '';
53
    }
54
55
}