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.
Completed
Push — master ( 6d7626...60838a )
by Enrico
02:13
created

JsonQuery   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 85%

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 5
c 4
b 2
f 1
lcom 1
cbo 5
dl 0
loc 80
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 setDataProvider() 0 4 1
A run() 0 18 2
1
<?php
2
/**
3
 * JSON Query Wrapper
4
 *
5
 * (The MIT license)
6
 * Copyright (c) 2016 Enrico Stahn
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated * documentation files (the "Software"), to
10
 * deal in the Software without restriction, including without limitation the
11
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
 * sell copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
 * IN THE SOFTWARE.
25
 *
26
 * @package JsonQueryWrapper
27
 * @link    http://github.com/estahn/json-query-wrapper for the canonical source repository
28
 */
29
30
namespace JsonQueryWrapper;
31
32
use JsonQueryWrapper\DataProvider\DataProviderInterface;
33
use JsonQueryWrapper\Exception\DataProviderMissingException;
34
use Symfony\Component\Process\ProcessBuilder;
35
36
/**
37
 * Class JsonQuery
38
 *
39
 * @package JsonQueryWrapper
40
 */
41
class JsonQuery
42
{
43
    /**
44
     * @var ProcessBuilder
45
     */
46
    protected $builder;
47
48
    /**
49
     * @var DataTypeMapper
50
     */
51
    protected $mapper;
52
53
    /**
54
     * @var DataProviderInterface
55
     */
56
    protected $dataProvider;
57
58
    /**
59
     * Path to the jq command
60
     *
61
     * @var string
62
     */
63
    protected $cmd = 'jq';
64
65
    /**
66
     * JsonQuery constructor.
67
     *
68
     * @param ProcessBuilder $builder
69
     * @param DataTypeMapper $dataTypeMapper
70
     */
71 3
    public function __construct(ProcessBuilder $builder, DataTypeMapper $dataTypeMapper)
72
    {
73 3
        $this->builder = $builder;
74 3
        $this->mapper = $dataTypeMapper;
75 3
    }
76
77
    /**
78
     * Set the path to the jq command
79
     *
80
     * @param string $cmd
81
     */
82
    public function setCmd($cmd)
83
    {
84
        $this->cmd = $cmd;
85
    }
86
87
    /**
88
     * Runs the command-line and returns
89
     *
90
     * @param string $filter
91
     * @return mixed
92
     * @throws DataProviderMissingException
93
     */
94 2
    public function run($filter)
95
    {
96 2
        if (!$this->dataProvider instanceof DataProviderInterface) {
97 1
            throw new DataProviderMissingException('A data provider such as file or text is missing.');
98
        }
99
100 1
        $builder = $this->builder;
101
        $builder
102 1
            ->setPrefix($this->cmd)
103 1
            ->setArguments([$filter, $this->dataProvider->getPath()]);
104
105 1
        $process = $builder->getProcess();
106 1
        $process->run();
107
108 1
        $result = trim($process->getOutput());
109
110 1
        return $this->mapper->map($result);
111
    }
112
113
    /**
114
     * @param DataProviderInterface $provider
115
     */
116 2
    public function setDataProvider(DataProviderInterface $provider)
117
    {
118 2
        $this->dataProvider = $provider;
119 2
    }
120
}
121