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::setDataProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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