GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

JsonQuery   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 85%

Importance

Changes 6
Bugs 4 Features 1
Metric Value
c 6
b 4
f 1
dl 0
loc 82
wmc 5
lcom 1
cbo 5
ccs 17
cts 20
cp 0.85
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setCmd() 0 4 1
A run() 0 18 2
A setDataProvider() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the json-query-wrapper package.
5
 *
6
 * (c) Enrico Stahn <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace JsonQueryWrapper;
13
14
use JsonQueryWrapper\DataProvider\DataProviderInterface;
15
use JsonQueryWrapper\Exception\DataProviderMissingException;
16
use Symfony\Component\Process\ProcessBuilder;
17
18
/**
19
 * Class JsonQuery.
20
 */
21
class JsonQuery
22
{
23
    /**
24
     * @var ProcessBuilder
25
     */
26
    protected $builder;
27
28
    /**
29
     * @var DataTypeMapper
30
     */
31
    protected $mapper;
32
33
    /**
34
     * @var DataProviderInterface
35
     */
36
    protected $dataProvider;
37
38
    /**
39
     * Path to the jq command.
40
     *
41
     * @var string
42
     */
43
    protected $cmd = 'jq';
44
45
    /**
46
     * JsonQuery constructor.
47
     *
48
     * @param ProcessBuilder $builder
49
     * @param DataTypeMapper $dataTypeMapper
50
     */
51 3
    public function __construct(ProcessBuilder $builder, DataTypeMapper $dataTypeMapper)
52
    {
53 3
        $this->builder = $builder;
54 3
        $this->mapper = $dataTypeMapper;
55 3
    }
56
57
    /**
58
     * Set the path to the jq command.
59
     *
60
     * @param string $cmd
61
     */
62
    public function setCmd($cmd)
63
    {
64
        $this->cmd = $cmd;
65
    }
66
67
    /**
68
     * Runs the command-line and returns.
69
     *
70
     * @param string $filter
71
     *
72
     * @throws DataProviderMissingException
73
     *
74
     * @return mixed
75
     */
76 2
    public function run($filter)
77
    {
78 2
        if (!$this->dataProvider instanceof DataProviderInterface) {
79 1
            throw new DataProviderMissingException('A data provider such as file or text is missing.');
80
        }
81
82 1
        $builder = $this->builder;
83
        $builder
84 1
            ->setPrefix($this->cmd)
85 1
            ->setArguments(['-M', $filter, $this->dataProvider->getPath()]);
86
87 1
        $process = $builder->getProcess();
88 1
        $process->run();
89
90 1
        $result = trim($process->getOutput());
91
92 1
        return $this->mapper->map($result);
93
    }
94
95
    /**
96
     * @param DataProviderInterface $provider
97
     */
98 2
    public function setDataProvider(DataProviderInterface $provider)
99
    {
100 2
        $this->dataProvider = $provider;
101 2
    }
102
}
103