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.
Passed
Pull Request — master (#11)
by
unknown
01:55
created

JsonQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 70
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 16 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 JsonQueryWrapper\Process\ProcessFactoryInterface;
17
18
/**
19
 * Class JsonQuery.
20
 */
21
class JsonQuery
22
{
23
    /**
24
     * @var ProcessFactoryInterface
25
     */
26
    protected $processFactory;
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 ProcessFactoryInterface $processFactory
49
     * @param DataTypeMapper $dataTypeMapper
50
     */
51 3
    public function __construct(ProcessFactoryInterface $processFactory, DataTypeMapper $dataTypeMapper)
52
    {
53 3
        $this->processFactory = $processFactory;
54 3
        $this->mapper = $dataTypeMapper;
55 3
    }
56
57
    /**
58
     * Runs the command-line and returns.
59
     *
60
     * @param string $filter
61
     *
62
     * @return mixed
63
     * @throws DataProviderMissingException
64
     * @throws Exception\DataTypeMapperException
65
     */
66
    public function run($filter)
67
    {
68
        if (!$this->dataProvider instanceof DataProviderInterface) {
69
            throw new DataProviderMissingException('A data provider such as file or text is missing.');
70
        }
71
72
        $command = [$this->cmd, '-M', $filter, $this->dataProvider->getPath()];
73
74
        $process = $this->processFactory->build($command);
75
76 2
        $process->run();
77
78 2
        $result = trim($process->getOutput());
79 1
80
        return $this->mapper->map($result);
81
    }
82 1
83
    /**
84 1
     * @param DataProviderInterface $provider
85 1
     */
86
    public function setDataProvider(DataProviderInterface $provider)
87 1
    {
88 1
        $this->dataProvider = $provider;
89
    }
90
}
91