Request   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
c 1
b 0
f 1
dl 0
loc 41
ccs 12
cts 13
cp 0.9231
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A detectClass() 0 9 4
A __construct() 0 4 1
A createRequest() 0 7 2
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart\auto;
12
13
use hiqdev\hiart\Query;
14
use hiqdev\hiart\QueryBuilderInterface;
15
use hiqdev\hiart\RequestCreatorInterface;
16
use hiqdev\hiart\RequestErrorException;
17
18
/**
19
 * Auto Request.
20
 * Detects best available transport in the system.
21
 */
22
class Request implements RequestCreatorInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function __construct(QueryBuilderInterface $builder, Query $query)
28
    {
29 3
        $this->builder = $builder;
0 ignored issues
show
Bug Best Practice introduced by
The property builder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30 3
        $this->query = $query;
0 ignored issues
show
Bug Best Practice introduced by
The property query does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31 3
    }
32
33
    protected $detectedClass;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function createRequest()
39
    {
40 3
        if ($this->detectedClass === null) {
41 3
            $this->detectedClass = $this->detectClass();
42
        }
43
44 3
        return new $this->detectedClass($this->builder, $this->query);
45
    }
46
47
    public $tryClasses = [
48
        \hiqdev\hiart\guzzle\Request::class,
0 ignored issues
show
Bug introduced by
The type hiqdev\hiart\guzzle\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
        \hiqdev\hiart\httpclient\Request::class,
0 ignored issues
show
Bug introduced by
The type hiqdev\hiart\httpclient\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
        \hiqdev\hiart\curl\Request::class,
51
        \hiqdev\hiart\stream\Request::class,
52
    ];
53
54 3
    public function detectClass()
55
    {
56 3
        foreach ($this->tryClasses as $class) {
57 3
            if (class_exists($class) && $class::isSupported()) {
58 3
                return $class;
59
            }
60
        }
61
62
        throw new RequestErrorException('could not auto detect Request class');
0 ignored issues
show
Bug introduced by
The call to hiqdev\hiart\RequestErrorException::__construct() has too few arguments starting with request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        throw /** @scrutinizer ignore-call */ new RequestErrorException('could not auto detect Request class');

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
63
    }
64
}
65