Check::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 8
Ratio 47.06 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 17
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Yuloh\JsonGuardCli\Commands;
4
5
use League\JsonReference\Dereferencer;
6
use League\JsonGuard\Validator;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Yuloh\JsonGuardCli\Util;
9
10
class Check
11
{
12 14
    public function __invoke($schema, OutputInterface $output)
13
    {
14 14
        $schema = Util::loadJson($schema);
15
16 12
        $metaSchema = Dereferencer::draft4()
17 12
            ->dereference('file://' . Util::schemaPath('draft4.json'));
18 12
        $validator  = new Validator($schema, $metaSchema);
19
20 12 View Code Duplication
        if ($validator->passes()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21 8
            $output->writeln('<info>✓ Valid draft-04 JSON Schema</info>');
22 8
            return 0;
23
        } else {
24 4
            $output->writeln('<error>✗ Invalid draft-04 JSON Schema</error>');
25 4
            Util::renderErrorTable($output, $validator->errors());
26 4
            return 1;
27
        }
28
    }
29
}
30