CodebaseClient   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 75
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getTicketsFromIds() 0 22 3
A registerDeployment() 0 13 1
A updateTicketStatus() 0 13 1
1
<?php
2
3
namespace ParityBit\DeploymentNotifier\Clients;
4
5
use Curl\Curl;
6
use ParityBit\DeploymentNotifier\Deployment;
7
8
class CodebaseClient
9
{
10
    protected $curl;
11
    protected $codebaseProjectName;
12
    protected $repositoryName;
13
	protected $headers = [
14
        'Accept' => 'application/xml',
15
        'Content-type' => 'application/xml',
16
    ];
17
18
	const WEBSERVICE_URL = 'http://api3.codebasehq.com/';
19
20
    public function __construct(Curl $curl, $username, $password, $codebaseProjectName, $repositoryName = null)
21
    {
22
        $this->curl = $curl;
23
        $this->codebaseProjectName = $codebaseProjectName;
24
        $this->repositoryName = $repositoryName;
25
        foreach ($this->headers as $header => $value) {
26
            $this->curl->setHeader($header, $value);
27
        }
28
29
        $this->curl->setBasicAuthentication($username, $password);
30
    }
31
32
    public function getTicketsFromIds($ticketIds = [])
33
    {
34
        $this->curl->get(
35
            self::WEBSERVICE_URL . $this->codebaseProjectName . '/tickets',
36
            [
37
                'query' => 'id' . implode(',', $ticketIds)
38
            ]
39
        );
40
41
        if ($this->curl->error) {
42
            return [];
43
        }
44
        else {
45
            $tickets = simplexml_load_string($this->curl->response);
46
            $completed_ticket_names = [];
47
            foreach($tickets as $ticket) {
48
                $completed_ticket_names[] = (string) $ticket->summary;
49
            }
50
51
            return $completed_ticket_names;
52
        }
53
    }
54
55
    public function updateTicketStatus($ticketId, $newStatus)
56
    {
57
        $payload = "<ticket-note>
58
    <changes>
59
        <status-id>" . $newStatus . "</status-id>
60
    </changes>
61
</ticket-note>";
62
63
        $this->curl->post(
64
            self::WEBSERVICE_URL . $this->codebaseProjectName . '/tickets/' . $ticketId . '/notes',
65
            $payload
0 ignored issues
show
Documentation introduced by
$payload is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        );
67
    }
68
69
    public function registerDeployment(Deployment $deployment)
70
    {
71
        $payload = "<deployment>
72
  <revision>" . (string) $deployment->getCurrentVersion() . "</revision>
73
  <environment>" . (string) $deployment->getEnvironment() . "</environment>
74
  <servers>" . (string) $deployment->getServer() . "</servers>
75
</deployment>";
76
77
        $this->curl->post(
78
            self::WEBSERVICE_URL . $this->codebaseProjectName . '/' . $this->repositoryName . '/deployments',
79
            $payload
0 ignored issues
show
Documentation introduced by
$payload is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
        );
81
    }
82
}
83