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.

Request::cancel()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 2
1
<?php
2
3
namespace Lexik\Bundle\PayboxBundle\Paybox\System\Cancellation;
4
5
use Lexik\Bundle\PayboxBundle\Paybox\AbstractRequest;
6
use Lexik\Bundle\PayboxBundle\Transport\TransportInterface;
7
8
/**
9
 * Class Request
10
 *
11
 * @package Lexik\Bundle\PayboxBundle\Paybox\System\Cancellation
12
 *
13
 * @author Fabien Pomerol <[email protected]>
14
 */
15
class Request extends AbstractRequest
16
{
17
    /**
18
     * @var TransportInterface This is how
19
     * you will point to Paybox (via cURL or Shell)
20
     */
21
    protected $transport;
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param array              $parameters
27
     * @param array              $servers
28
     * @param TransportInterface $transport
29
     */
30
    public function __construct(array $parameters, array $servers, TransportInterface $transport = null)
31
    {
32
        parent::__construct($parameters, $servers['system']);
33
34
        $this->transport = $transport;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 View Code Duplication
    protected function initGlobals(array $parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this->globals = array(
43
            'production'          => isset($parameters['production']) ? $parameters['production'] : false,
44
            'currencies'          => $parameters['currencies'],
45
            'site'                => $parameters['site'],
46
            'rank'                => $parameters['rank'],
47
            'login'               => $parameters['login'],
48
            'hmac_key'            => $parameters['hmac']['key'],
49
            'hmac_algorithm'      => $parameters['hmac']['algorithm'],
50
            'hmac_signature_name' => $parameters['hmac']['signature_name'],
51
        );
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function initParameters()
58
    {
59
        $this->setParameter('VERSION',     '001');
60
        $this->setParameter('TYPE',        '001');
61
        $this->setParameter('SITE',        $this->globals['site']);
62
        $this->setParameter('MACH',        sprintf('%03d', $this->globals['rank']));
63
        $this->setParameter('IDENTIFIANT', $this->globals['login']);
64
    }
65
66
    /**
67
     * Returns all parameters set for a payment.
68
     *
69
     * @return array
70
     */
71 View Code Duplication
    public function getParameters()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        if (null === $this->getParameter('HMAC')) {
74
            $this->setParameter('TIME', date('c'));
75
            $this->setParameter('HMAC', strtoupper($this->computeHmac()));
76
        }
77
78
        $resolver = new ParameterResolver();
79
80
        return $resolver->resolve($this->parameters);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getUrl()
87
    {
88
        $server = $this->getServer();
89
90
        return sprintf(
91
            '%s://%s%s',
92
            $server['protocol'],
93
            $server['host'],
94
            $server['cancellation_path']
95
        );
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     *
101
     * @param string $reference
102
     * @param string $subscriptionId
103
     *
104
     * @throws \RuntimeException On cURL error
105
     *
106
     * @return string The html of the temporary form
107
     */
108
    public function cancel($reference = null, $subscriptionId = null)
109
    {
110
        if ($reference) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $reference of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
111
          $this->setParameter('REFERENCE', $reference);
112
        }
113
114
        if ($subscriptionId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $subscriptionId of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
115
          $this->setParameter('ABONNEMENT', $subscriptionId);
116
        }
117
118
        $this->transport->setEndpoint($this->getUrl());
119
120
        return $this->transport->call($this);
121
    }
122
}
123