Completed
Push — master ( 25f226...cc0a72 )
by Morgan
03:23
created

AbstractOrigin::ipInRange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Morphatic\AutoDeploy\Origins;
4
5
use Illuminate\Http\Request;
6
7
abstract class AbstractOrigin implements OriginInterface
8
{
9
    /**
10
     * The name of the origin.
11
     *
12
     * @var string
13
     */
14
    public $name;
15
16
    /**
17
     * The Request object associated with this webhook.
18
     *
19
     * @var Illuminate\Http\Request
20
     */
21
    public $request;
22
23 36
    public function __construct(Request $request)
1 ignored issue
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
24
    {
25 36
        $this->request = $request;
1 ignored issue
show
Documentation Bug introduced by
It seems like $request of type object<Illuminate\Http\Request> is incompatible with the declared type object<Morphatic\AutoDep...lluminate\Http\Request> of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26 36
    }
27
28
    /**
29
     * Determines whether or not the Request originated from the webhook origin.
30
     *
31
     * @param Illuminate\Http\Request $request The Request object
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
32
     *
33
     * @return bool Returns true if the request originated from this origin. False otherwise.
34
     */
35
    abstract public function originated();
0 ignored issues
show
Coding Style introduced by
function originated() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
36
37
    /**
38
     * Verifies the authenticity of a webhook request from the origin.
39
     *
40
     * @param Illuminate\Http\Request $request The Request object
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
     *
42
     * @return bool Returns true if the request is authentic. False otherwise.
43
     */
44
    abstract public function verify();
0 ignored issues
show
Coding Style introduced by
function verify() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
45
46
    /**
47
     * Gets the event the triggered the webhook request.
48
     *
49
     * @param Illuminate\Http\Request $request The Request object
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
50
     *
51
     * @return string The name of the event, e.g. push, release, create, etc.
52
     */
53
    abstract public function event();
54
55
    /**
56
     * Gets the URL to be cloned from.
57
     *
58
     * @param Illuminate\Http\Request $request The Request object
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
59
     *
60
     * @return string The URL of the repo.
61
     */
62
    abstract public function getRepoUrl();
63
64
    /**
65
     * Gets the ID of the commit that is to be cloned.
66
     *
67
     * @param Illuminate\Http\Request $request The Request object
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
68
     *
69
     * @return string The commit ID.
70
     */
71
    abstract public function getCommitId();
72
73
    /**
74
     * Determines if a target IP address is within a particular IP address range.
75
     *
76
     * @param string $target_ip The IP address to check
77
     * @param string $range_ip  The IP address defining the range
78
     * @param int    $cidr_mask The CIDR notation net mask defining the range
79
     *
80
     * @return bool True if the target IP falls within the specified range. Otherwise false.
81
     */
82 18
    protected function ipInRange($target_ip, $range_ip, $cidr_mask)
0 ignored issues
show
Coding Style introduced by
function ipInRange() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
$target_ip does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
83
    {
84 18
        $target = sprintf('%032b', ip2long($target_ip));
0 ignored issues
show
Coding Style introduced by
$target_ip does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
85 18
        $range = sprintf('%032b', ip2long($range_ip));
0 ignored issues
show
Coding Style introduced by
$range_ip does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
86
87 18
        return 0 === substr_compare($target, $range, 0, $cidr_mask);
0 ignored issues
show
Coding Style introduced by
$cidr_mask does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
88
    }
89
}
90