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.

Curl   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 31
c 1
b 0
f 0
dl 0
loc 83
ccs 26
cts 28
cp 0.9286
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A execute() 0 10 1
A _setDefaultHeaders() 0 5 1
A getData() 0 16 2
1
<?php
0 ignored issues
show
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "Curl.php" doesn't match the expected filename "curl.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace RattfieldNz\Shodan\Libraries\Curl;
4
5
use Curl\Curl as PhpCurl;
6
use RattfieldNz\Shodan\Libraries\Data\Data;
7
8
/**
9
 * Class Curl.
10
 *
11
 * @category PHP
0 ignored issues
show
Coding Style Documentation introduced by
@category tag is not allowed in class comment
Loading history...
12
 *
13
 * @author  Rob Attfield <[email protected]>
0 ignored issues
show
Coding Style Documentation introduced by
@author tag is not allowed in class comment
Loading history...
14
 * @license https://github.com/rattfieldnz/shodan/blob/master/LICENSE MIT
0 ignored issues
show
Coding Style Documentation introduced by
@license tag is not allowed in class comment
Loading history...
15
 */
0 ignored issues
show
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
16
class Curl
17
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class Curl
Loading history...
18
    private $_data;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
19
    private $_defaultHeaders;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
20
    private $_timeout;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
21
    private $_curl;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before member var; 0 found
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
22
23
    /**
24
     * Curl constructor.
25
     *
26
     * Set the needed properties to do a CURL request.
27
     *
28
     * @param Data $data    Data to use when executing cURL.
29
     * @param int  $timeout Timeout in seconds to complete a CURL request. Default is 10.
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
30
     *
31
     * @throws \ErrorException Will throw an exception if PHP ext-curl is not installed.
32
     */
33 4
    public function __construct(Data $data, int $timeout = 10)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$timeout" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$timeout"; expected 0 but found 1
Loading history...
34
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
35 4
        if (!extension_loaded('curl')) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
36
            throw new \ErrorException(
37
                'The cURL extensions is not loaded, make sure you have installed the cURL extension: https://php.net/manual/curl.setup.php'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38
            );
39
        }
40
41 4
        $this->_curl = new PhpCurl();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42 4
        $this->_data = $data;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
43 4
        $this->_timeout = $timeout;
44 4
        $this->_setDefaultHeaders();
45 4
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
46
47
    /**
48
     * Execute a CURL request, and return current object for further processing.
49
     *
50
     * @return PhpCurl
51
     */
52 3
    public function execute(): PhpCurl
53
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
54 3
        $this->_curl->setOpt(CURLOPT_RETURNTRANSFER, true);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
55 3
        $this->_curl->setOpt(CURLOPT_CONNECTTIMEOUT, $this->_timeout);
56 3
        $this->_curl->setOpt(CURLOPT_HTTPHEADER, $this->_defaultHeaders);
57 3
        $this->_curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
58 3
        $this->_curl->setOpt(CURLOPT_SSL_VERIFYHOST, false);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
59 3
        $this->_curl->get($this->_data->shodanApiUrl());
60
61 3
        return $this->_curl;
62
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end execute()
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
63
64
    /**
65
     * Get the data retrieved from executing CURL request, in JSON format.
66
     *
67
     * @return array
68
     *
69
     * @see \RattfieldNz\SafeUrls\Libraries\Curl\Curl->execute().
70
     */
71 3
    public function getData()
72
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
73 3
        $dataObject = $this->execute();
74
75 3
        $status = $dataObject->getHttpStatus();
76
77 3
        $response = $dataObject->error_code != 0 ?
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
Variable "error_code" is not in valid camel caps format
Loading history...
Coding Style introduced by
Operator != prohibited; use !== instead
Loading history...
Coding Style introduced by
Expected 1 space after "?"; newline found
Loading history...
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement must be declared on a single line
Loading history...
78 1
            ['message' => $dataObject->error_message] :
0 ignored issues
show
Coding Style introduced by
Short array syntax is not allowed
Loading history...
Coding Style introduced by
Variable "error_message" is not in valid camel caps format
Loading history...
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
79 3
            json_decode($dataObject->response, true);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
Bug introduced by
It seems like $dataObject->response can also be of type boolean and null; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

79
            json_decode(/** @scrutinizer ignore-type */ $dataObject->response, true);
Loading history...
80
81
        $data = [
0 ignored issues
show
Coding Style introduced by
Short array syntax is not allowed
Loading history...
82 3
            'status'   => $status,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 17 spaces, but found 12.
Loading history...
83 3
            'response' => $response,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 17 spaces, but found 12.
Loading history...
84
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 16 space(s), but found 8.
Loading history...
85
86 3
        return $data;
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getData()
Loading history...
88
89
    /**
90
     * Sets the default headers to use for CURL request.
91
     *
92
     * @return void
93
     */
94 4
    private function _setDefaultHeaders(): void
95
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
96 4
        $this->_defaultHeaders = [
0 ignored issues
show
Coding Style introduced by
Short array syntax is not allowed
Loading history...
97
            'Content-Type: application/json',
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 34 spaces, but found 12.
Loading history...
98
            'Connection: Keep-Alive',
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 34 spaces, but found 12.
Loading history...
99
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 33 space(s), but found 8.
Loading history...
100 4
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end _setDefaultHeaders()
Loading history...
101
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
102