Completed
Push — master ( 663715...460573 )
by Matt
04:05
created

Check::__invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 13

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 19
loc 19
ccs 14
cts 14
cp 1
rs 9.4285
cc 3
eloc 13
nc 4
nop 2
crap 3
1
<?php
2
3
namespace Yuloh\JsonGuardCli\Commands;
4
5
use League\JsonGuard\Dereferencer;
6
use League\JsonGuard\Validator;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Yuloh\JsonGuardCli\Util;
9
10 View Code Duplication
class Check
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
11
{
12 21
    public function __invoke($schema, OutputInterface $output)
13
    {
14 21
        if (Util::isLoaderPath($schema)) {
15 6
            $schema = Util::load($schema);
16 6
        } else {
17 15
            $schema = Util::normalizeJsonArgument($schema);
18
        }
19
20 18
        $metaSchema = (new Dereferencer())
21 18
            ->dereference('file://' . Util::schemaPath('draft4.json'));
22 18
        $validator  = new Validator($schema, $metaSchema);
23
24 18
        if ($validator->passes()) {
25 12
            $output->writeln('<info>✓ Valid draft-04 JSON Schema</info>');
26 12
        } else {
27 6
            $output->writeln('<error>✗ Invalid draft-04 JSON Schema</error>');
28 6
            Util::renderErrorTable($output, $validator->errors());
29
        }
30 18
    }
31
}
32