Passed
Push — master ( 85716f...d04990 )
by John
05:03 queued 10s
created

AuthnetSim::getFingerprint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 15
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
c 0
b 0
f 0
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
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "AuthnetSim.php" doesn't match the expected filename "authnetsim.php"
Loading history...
2
3
declare(strict_types=1);
4
5
/**
0 ignored issues
show
Coding Style introduced by
Block comments must be started with /*
Loading history...
6
 * This file is part of the AuthnetJSON package.
7
 *
8
 * (c) John Conde <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Authnetjson;
15
16
use Exception;
17
18
/**
19
 * Wrapper to simplify the creation of SIM data
20
 *
21
 * @author    John Conde <[email protected]>
22
 * @copyright John Conde <[email protected]>
23
 * @license   http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0
24
 * @link      https://github.com/stymiee/authnetjson
25
 */
26
class AuthnetSim
27
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class AuthnetSim
Loading history...
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var string  Authorize.Net API login ID
30
     */
31
    private $login;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "login" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "login" must be prefixed with an underscore
Loading history...
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
34
     * @var string  Authorize.Net API signature key
35
     */
36
    private $signature;
0 ignored issues
show
Coding Style introduced by
Private member variable "signature" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "signature" must be prefixed with an underscore
Loading history...
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
39
     * @var string  URL endpoint for processing a transaction
40
     */
41
    private $url;
0 ignored issues
show
Coding Style introduced by
Private member variable "url" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "url" must be prefixed with an underscore
Loading history...
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @var int  Randomly generated number
45
     */
46
    private $sequence;
0 ignored issues
show
Coding Style introduced by
Private member variable "sequence" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "sequence" must be prefixed with an underscore
Loading history...
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @var int  Unix timestamp the request was made
50
     */
51
    private $timestamp;
0 ignored issues
show
Coding Style introduced by
Private member variable "timestamp" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "timestamp" must be prefixed with an underscore
Loading history...
52
53
    /**
54
     * Creates a SIM wrapper by setting the Authorize.Net credentials and URL of the endpoint to be used
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 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...
55
     * for the API call
56
     *
57
     * @param  string $login     Authorize.Net API login ID
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
58
     * @param  string $signature Authorize.Net API Transaction Key
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
59
     * @param  string $api_url   URL endpoint for processing a transaction
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
60
     * @throws Exception
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
introduced by
Comment missing for @throws tag in function comment
Loading history...
61
     */
62 1
    public function __construct($login, $signature, $api_url)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Type hint "string" missing for $login
Loading history...
Coding Style introduced by
Type hint "string" missing for $signature
Loading history...
Coding Style introduced by
Type hint "string" missing for $api_url
Loading history...
Coding Style introduced by
Variable "api_url" is not in valid camel caps format
Loading history...
63
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
64 1
        $this->login     = $login;
65 1
        $this->signature = $signature;
66 1
        $this->url       = $api_url;
0 ignored issues
show
Coding Style introduced by
Variable "api_url" is not in valid camel caps format
Loading history...
67 1
        $this->resetParameters();
68 1
    }
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 __construct()
Loading history...
69
70
    /**
71
     * Returns the hash for the SIM transaction
72
     *
73
     * @param  float $amount The amount of the transaction
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
74
     * @return string           Hash of five different unique transaction parameters
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
75
     * @throws AuthnetInvalidAmountException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
introduced by
Comment missing for @throws tag in function comment
Loading history...
76
     */
77 2
    public function getFingerprint(float $amount): string
78
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
79 2
        if (!filter_var($amount, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
80 1
            throw new AuthnetInvalidAmountException('You must enter a valid amount greater than zero.');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 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...
81
        }
82
83 1
        return strtoupper(
84 1
            hash_hmac('sha512',
85 1
                sprintf('%s^%s^%s^%s^',
86 1
                    $this->login,
87 1
                    $this->sequence,
88 1
                    $this->timestamp,
89 1
                    $amount
90
                ),
91 1
                hex2bin($this->signature)
92
            )
93
        );
94
    }
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 getFingerprint()
Loading history...
95
96
    /**
97
     * Returns the sequence generated for a transaction
98
     *
99
     * @return int Current sequence
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
100
     */
101 1
    public function getSequence(): int
102
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
103 1
        return $this->sequence;
104
    }
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 getSequence()
Loading history...
105
106
    /**
107
     * Returns the timestamp for a transaction
108
     *
109
     * @return int Current timestamp
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
110
     */
111 1
    public function getTimestamp(): int
112
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
113 1
        return $this->timestamp;
114
    }
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 getTimestamp()
Loading history...
115
116
    /**
117
     * Returns the account login ID
118
     *
119
     * @return string           API login ID
120
     */
121 1
    public function getLogin(): string
122
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
123 1
        return $this->login;
124
    }
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 getLogin()
Loading history...
125
126
    /**
127
     * Returns the url endpoint for the transaction
128
     *
129
     * @return string           url endpoint
130
     */
131 1
    public function getEndpoint(): string
132
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
133 1
        return $this->url;
134
    }
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 getEndpoint()
Loading history...
135
136
    /**
137
     * Resets the sequence and timestamp
138
     *
139
     * @throws Exception
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
140
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
141 1
    public function resetParameters(): void
142
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
143 1
        $this->sequence  = random_int(1, 1000);
144 1
        $this->timestamp = time();
145 1
    }
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 resetParameters()
Loading history...
146
}
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...
147