Create   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A newDnsZone() 0 10 1
A newDns() 0 11 1
A createPageRule() 0 33 1
1
<?php
2
3
namespace Integrations\Connectors\Cloudflare;
4
5
use Log;
6
use App\Models\User;
7
use Cloudflare\Zone\Pagerules;
8
use Cloudflare\Zone\Dns;
9
10
class Create extends Cloudflare
11
{
12
    public function newDnsZone(Project $project)
13
    {
14
        // Create a new DNS record
15
        $endpoint = new \Cloudflare\API\Endpoints\Zones($this->_connection);
0 ignored issues
show
Unused Code introduced by
$endpoint is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
16
        $name = '';
17
        $jumpStart = false;
18
        $organizationID = '';
19
        $dns = '';
20
        return  $dns->addZone($name, $jumpStart, $organizationID);
0 ignored issues
show
Bug introduced by
The method addZone cannot be called on $dns (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
21
    }
22
23
    public function newDns(Project $project)
24
    {
25
        // Create a new DNS record
26
        $endpoint = new \Cloudflare\API\Endpoints\DNS($this->_connection);
0 ignored issues
show
Unused Code introduced by
$endpoint is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
        $zoneID = '';
28
        $type = '';
29
        $name = '';
30
        $content = '';
31
        $ttl = 0;
32
        return  $dns->addRecord($zoneID, $type, $name, $content, $ttl);
0 ignored issues
show
Bug introduced by
The variable $dns does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
33
    }
34
35
    public function createPageRule()
36
    {
37
        $endpoint = new \Cloudflare\API\Endpoints\PageRules($this->_connection);
38
        // Define your targets
39
        // Currently you can only specify one URL per page rule but this implementation matches the API
40
        // so I am leaving it for now in the assumption they are planning to add multiple targets.
41
        // PageRulesTargets
42
        $target = [
0 ignored issues
show
Unused Code introduced by
$target is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
            [
44
                'target' => 'url',
45
                'constraint' =>
46
                [
47
                    'operator' => 'matches',
48
                    'value' => 'http://example.co.uk/*'
49
                ]
50
            ]
51
        ];
52
    
53
        // Define your actions
54
        // Each action is held within it's own array.
55
        // PageRulesActions
56
        $actions = [
57
            [
58
                'id' => 'always_online',
59
                'value' => 'on'
60
            ]
61
        ];
62
63
        $active = true;
64
        $priority = null; //int
65
    
66
        $endpoint->createPageRule($zoneID, $targets, $actions, $active, $priority);
0 ignored issues
show
Bug introduced by
The variable $zoneID does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $targets does not exist. Did you mean $target?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
67
    }
68
}
69