Method test_api_key
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function test_api_key($api_key)
{
delete_transient('vindi_merchant');
$url = $this->base_path() . 'merchant';
Method request
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function request($endpoint, $method = 'POST', $data = array(), $data_to_log = null)
{
$url = sprintf('%s%s', $this->base_path(), $endpoint);
$body = $this->build_body($data);
Function test_api_key
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function test_api_key($api_key)
{
delete_transient('vindi_merchant');
$url = $this->base_path() . 'merchant';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function check_response
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function check_response($response)
{
if (isset($response['errors']) && !empty($response['errors'])) {
foreach ($response['errors'] as $error) {
$message = $this->get_error_message($error);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid unused private fields such as '$recentRequest'. Open
private $recentRequest;
- Read upRead up
- Exclude checks
UnusedPrivateField
Since: 0.2
Detects when a private field is declared and/or assigned a value, but not used.
Example
class Something
{
private static $FOO = 2; // Unused
private $i = 5; // Unused
private $j = 6;
public function addOne()
{
return $this->j++;
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield
The property $current_plan is not named in camelCase. Open
class VindiApi
{
/**
* @var string
*/
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $last_error is not named in camelCase. Open
class VindiApi
{
/**
* @var string
*/
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $accept_bank_slip is not named in camelCase. Open
class VindiApi
{
/**
* @var string
*/
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $errors_list is not named in camelCase. Open
class VindiApi
{
/**
* @var string
*/
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Inline control structures are not allowed Open
if (false === array_key_exists($error_identifier, $this->errors_list))
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
$this->logger->log(sprintf("[Request #%s]: Novo Request para a API.\n%s %s\n%s", $request_id, $method, $url, $data_to_log));
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$this->logger->log(sprintf("[Request #%s]: Nova Resposta da API.\n%s\n%s", $request_id, $status, print_r($response['body'], true)));
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$this->logger->log(sprintf("[Request #%s]: Nova Resposta da API.\n%s\n%s", $request_id, $status, print_r($response['body'], true)));
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
$this->logger->log(sprintf('[Request #%s]: Erro ao recuperar corpo do request! %s', $request_id, print_r($response, true)));
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
$this->logger->log(sprintf("[Request #%s]: Novo Request para a API.\n%s %s\n%s", $request_id, $method, $url, $data_to_log));
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
$this->logger->log(sprintf('[Request #%s]: Erro ao recuperar corpo do request! %s', $request_id, print_r($response, true)));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->sandbox = $sandbox;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if ('yes' === $this->sandbox) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function __construct($key, VindiLogger $logger, $sandbox)
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $key;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $recentRequest;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $current_plan;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private function build_body($data)
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $last_error = '';
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
);
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!empty($data)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function test_api_key($api_key)
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
delete_transient('vindi_merchant');
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$status = $response['response']['code'] . ' ' . $response['response']['message'];
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!$response_body) {
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private function get_auth_header()
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private function get_error_message($error)
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$data_to_log = 'API Authorization Test';
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
foreach ($response_body_array['errors'] as $error) {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
delete_transient('vindi_payment_methods');
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->logger->log(sprintf("[Request #%s]: Nova Resposta da API.\n%s\n%s", $request_id, $status, print_r($response['body'], true)));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $body;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->logger->log(sprintf("[Request #%s]: Novo Request para a API.\n%s %s\n%s", $request_id, $method, $url, $data_to_log));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$response_body_array = json_decode($response_body, true);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->logger->log(sprintf("[Request #%s]: Novo Request para a API.\n%s %s\n%s", $request_id, $method, $url, $data_to_log));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'timeout' => 60,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$status = sprintf('%s %s', $response['response']['code'], $response['response']['message']);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function request($endpoint, $method = 'POST', $data = array(), $data_to_log = null)
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return 'https://app.vindi.com.br/api/v1/';
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->key = $key;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
$this->last_error = $message;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
set_transient('vindi_merchant', $response_body_array['merchant'], 1 * HOUR_IN_SECONDS);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$body = $this->build_body($data);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!$this->check_response($response_body_array)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $accept_bank_slip;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->logger = $logger;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
return $error_identifier;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return false;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (isset($response_body_array['errors']) && !empty($response_body_array['errors'])) {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
$message = $this->get_error_message($error);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (is_wp_error($response)) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$url = $this->base_path() . 'merchant';
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 8 Open
if ('unauthorized' == $error['id'] and 'authorization' == $error['parameter']) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$url = sprintf('%s%s', $this->base_path(), $endpoint);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'headers' => array(
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $sandbox;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $errors_list = array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$body = null;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'headers' => [
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
],
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!$response_body) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'body' => $body,
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$this->logger->log(sprintf("[Request #%s]: Erro ao fazer request! %s", $request_id, print_r($response, true)));
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return 'https://sandbox-app.vindi.com.br/api/v1/';
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$body = null;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!empty($data)) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$error_identifier = sprintf('%s|%s', $error_id, $error_parameter);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$response = wp_remote_post($url, [
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $logger;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$body = json_encode($data);
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return true;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$response_body = wp_remote_retrieve_body($response);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return false;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $body;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$body = json_encode($data);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return sprintf('Basic %s', base64_encode($this->key . ":"));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'method' => $method,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'timeout' => 60,
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (is_wp_error($response)) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$response_body = wp_remote_retrieve_body($response);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$this->logger->log(sprintf('[Request #%s]: Erro ao recuperar corpo do request! %s', $request_id, print_r($response, true)));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function base_path()
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
delete_transient('vindi_plans');
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 10 Open
return $error['id'];
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private function convert_body_to_json($data)
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$error_id = empty($error['id']) ? '' : $error['id'];
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$method = 'GET';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$this->logger->log(sprintf("[Request #%s]: Erro ao fazer request! %s", $request_id, print_r($response, true)));
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$response_body_array = json_decode($response_body, true);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $response_body_array;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
if (false === array_key_exists($error_identifier, $this->errors_list))
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return false;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$response = wp_remote_post($url, array(
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return false;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$error_parameter = empty($error['parameter']) ? '' : $error['parameter'];
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return __($this->errors_list[$error_identifier], VINDI);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$data_to_log = null !== $data_to_log ? $this->build_body($data_to_log) : $body;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$this->logger->log(sprintf('[Request #%s]: Erro ao recuperar corpo do request! %s', $request_id, print_r($response, true)));
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return false;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$request_id = rand();
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'sslverify' => true,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
]);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->logger->log(sprintf("[Request #%s]: Nova Resposta da API.\n%s\n%s", $request_id, $status, print_r($response['body'], true)));
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$request_id = rand();
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'method' => $method,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'sslverify' => true,
- Exclude checks