File Webhooks.php
has 367 lines of code (exceeds 250 allowed). Consider refactoring.
<?php
namespace VindiPaymentGateways;
use WC_Subscriptions_Manager;
The class VindiWebhooks has an overall complexity of 75 which is very high. The configured complexity threshold is 50.
class VindiWebhooks
{
* @var VindiSettings
*/
VindiWebhooks
has 26 functions (exceeds 20 allowed). Consider refactoring.
class VindiWebhooks
{
* @var VindiSettings
*/
Method bill_paid
has 30 lines of code (exceeds 25 allowed). Consider refactoring.
private function bill_paid($data)
{
try {
if (empty($data->bill->subscription)) {
$order = $this->find_order_by_id($data->bill->code);
Function bill_paid
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
private function bill_paid($data)
{
try {
if (empty($data->bill->subscription)) {
$order = $this->find_order_by_id($data->bill->code);
Avoid unused parameters such as '$data'.
private function test($data)
The method handle() contains an exit expression.
die('invalid access token');
The method handle() contains an exit expression.
die($e->getMessage());
Avoid using static access to class '\WC_Subscriptions_Manager' in method 'subscription_renew'.
WC_Subscriptions_Manager::prepare_renewal($subscription->id);
The method bill_paid uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$vindi_subscription_id = $data->bill->subscription->id;
$cycle = $data->bill->period->cycle;
$order = $this->find_order_by_subscription_and_cycle($vindi_subscription_id, $cycle);
}
The method bill_canceled uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
} else {
$vindi_subscription_id = $data->bill->subscription->id;
$cycle = $data->bill->period->cycle;
$order = $this->find_order_by_subscription_and_cycle($vindi_subscription_id, $cycle);
}
The property $vindi_settings is not named in camelCase.
class VindiWebhooks
{
* @var VindiSettings
*/
Avoid variables with short names like $id. Configured minimum length is 3.
private function find_order_by_id($id)
Avoid variables with short names like $id. Configured minimum length is 3.
private function find_bill_by_charge_id($id)
Opening brace indented incorrectly; expected 4 spaces, found 2
{
Opening brace indented incorrectly; expected 4 spaces, found 2
{
Opening brace indented incorrectly; expected 4 spaces, found 2
{
Blank line found at start of control structure
if ($vindi_subscription && isset($vindi_subscription['next_billing_at'])) {
Opening brace indented incorrectly; expected 4 spaces, found 2
{
Inline control structures are not allowed
if ('charge_underpay' !== $issue_type)
Inline control structures are not allowed
if (empty($subscription))
Inline control structures are not allowed
if (null == $body || empty($body->event))
Inline control structures are not allowed
if (empty($charge))
Inline control structures are not allowed
if ('open' !== $issue_status)
Inline control structures are not allowed
if (empty($order))
Inline control structures are not allowed
if ('charge' !== $item_type)
Inline control structures are not allowed
if (false === $query->have_posts())
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(sprintf(__('Pendência criada com o tipo "%s" não processada!', VINDI), $issue_type));
Line indented incorrectly; expected at least 8 spaces, found 6
$order->id,
Multi-line function call not indented correctly; expected 8 spaces but found 6
$issue_data->expected_amount,
Line indented incorrectly; expected 8 spaces, found 6
} catch (Exception $e) {
Line indented incorrectly; expected 8 spaces, found 6
}
Line indented incorrectly; expected at least 8 spaces, found 6
$this->vindi_settings = $vindi_settings;
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(__('Falha ao interpretar JSON do webhook: Evento do Webhook não encontrado!', VINDI));
Line indented incorrectly; expected 8 spaces, found 4
if (method_exists($this, $type)) {
Multi-line function call not indented correctly; expected 10 spaces but found 8
$renew_infos['cicle'],
Line indented incorrectly; expected at least 12 spaces, found 8
$subscription->get_last_order()
Line indented incorrectly; expected at least 12 spaces, found 6
));
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
$issue_type = $data->issue->issue_type;
Line indented incorrectly; expected at least 8 spaces, found 4
$issue_status = $data->issue->status;
Line indented incorrectly; expected 4 spaces, found 2
private function find_bill_by_charge_id($id)
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(sprintf(__('Cobrança #%s não encontrada!', VINDI), $id), 2);
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 12 spaces, found 8
__('Já existe o ciclo %s para a assinatura #%s pedido #%s!', VINDI),
Line indented incorrectly; expected 8 spaces, found 4
try {
Multi-line function call not indented correctly; expected 8 spaces but found 6
__('Divergencia de valores do Pedido #%s: Valor Esperado R$ %s, Valor Pago R$ %s.', VINDI),
Line indented incorrectly; expected 8 spaces, found 4
}
Multi-line function call not indented correctly; expected 10 spaces but found 8
$subscription->get_last_order()
Line indented incorrectly; expected at least 16 spaces, found 8
$order = $this->find_order_by_subscription_and_cycle($vindi_subscription_id, $cycle);
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(sprintf(__('Pendência criada com o item do tipo "%s" não processada!', VINDI), $item_type));
Line indented incorrectly; expected at least 8 spaces, found 4
if (empty($subscription))
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
$args = array(
Line indented incorrectly; expected at least 8 spaces, found 4
return $token === $this->vindi_settings->get_token();
Line indented incorrectly; expected at least 12 spaces, found 6
return $this->{$type}($data);
Line indented incorrectly; expected at least 12 spaces, found 8
$renew_infos['vindi_subscription_id'],
Line indented incorrectly; expected 4 spaces, found 2
private function validate_access_token($token)
Line indented incorrectly; expected at least 8 spaces, found 4
if ('charge' !== $item_type)
Line indented incorrectly; expected 4 spaces, found 2
private function process_event($body)
Line indented incorrectly; expected 4 spaces, found 2
private function test($data)
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(sprintf(__('Pedido #%s não encontrado!', VINDI), $id), 2);
Line indented incorrectly; expected at least 8 spaces, found 4
$this->vindi_settings->logger->log(__('Evento de teste do webhook.', VINDI));
Line indented incorrectly; expected at least 8 spaces, found 6
),
Multi-line function call not indented correctly; expected 8 spaces but found 6
$order->id,
Multi-line function call not indented correctly; expected 8 spaces but found 6
$issue_data->transaction_amount
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
));
Line indented incorrectly; expected at least 8 spaces, found 6
'post_status' => 'any',
Line indented incorrectly; expected at least 8 spaces, found 4
$vindi_subscription = $this->routes->getSubscription($data->bill->subscription->id);
Line indented incorrectly; expected 8 spaces, found 4
if ($vindi_subscription && isset($vindi_subscription['next_billing_at'])) {
Line indented incorrectly; expected at least 8 spaces, found 4
$data = $body->event->data;
Line indented incorrectly; expected at least 12 spaces, found 6
throw new Exception(sprintf(
Line indented incorrectly; expected at least 12 spaces, found 8
$renew_infos['cicle'],
Line indented incorrectly; expected at least 8 spaces, found 4
if ('charge_underpay' !== $issue_type)
Line indented incorrectly; expected at least 8 spaces, found 4
$bill = $this->find_bill_by_charge_id($item_id);
Line indented incorrectly; expected at least 8 spaces, found 4
));
Line indented incorrectly; expected at least 8 spaces, found 4
$subscription = wcs_get_subscription(end($sanitized_id));
Line indented incorrectly; expected at least 8 spaces, found 4
return $order;
Line indented incorrectly; expected at least 8 spaces, found 4
);
Line indented incorrectly; expected at least 8 spaces, found 6
'post_type' => 'shop_order',
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
$this->vindi_settings->logger->log(sprintf(__('Evento do webhook ignorado pelo plugin: ', VINDI), $type));
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected at least 8 spaces, found 4
$subscription = $this->find_subscription_by_id($renew_infos['wc_subscription_id']);
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(sprintf(__('Pendência criada com o status "%s" não processada!', VINDI), $issue_status));
Line indented incorrectly; expected at least 8 spaces, found 4
$order = $this->find_order_by_bill_id($bill->id);
Line indented incorrectly; expected at least 8 spaces, found 4
$order->add_order_note(sprintf(
Line indented incorrectly; expected 4 spaces, found 2
private $vindi_settings;
Line indented incorrectly; expected 8 spaces, found 6
try {
Line indented incorrectly; expected at least 12 spaces, found 6
$this->vindi_settings->logger->log(sprintf(__('Novo Evento processado: %s', VINDI), $type));
Line indented incorrectly; expected at least 8 spaces, found 6
'meta_key' => 'vindi_bill_id',
Line indented incorrectly; expected at least 8 spaces, found 4
return date('Y-m-d H:i:s', strtotime($date));
Line indented incorrectly; expected at least 16 spaces, found 8
$cycle = $data->bill->period->cycle;
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected 4 spaces, found 2
private function find_order_by_id($id)
Line indented incorrectly; expected at least 8 spaces, found 4
return wc_get_order($query->post->ID);
Line indented incorrectly; expected at least 8 spaces, found 4
));
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected 12 spaces, found 6
} else {
Line indented incorrectly; expected 12 spaces, found 6
}
Line indented incorrectly; expected at least 8 spaces, found 4
$item_type = strtolower($data->issue->item_type);
Line indented incorrectly; expected at least 8 spaces, found 6
'post_status' => 'any',
Line indented incorrectly; expected at least 8 spaces, found 6
),
Line indented incorrectly; expected 8 spaces, found 4
}
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
$type = $body->event->type;
Multi-line function call not indented correctly; expected 10 spaces but found 8
$renew_infos['vindi_subscription_id'],
Line indented incorrectly; expected 8 spaces, found 4
}
Line indented incorrectly; expected 12 spaces, found 6
if (empty($data->bill->subscription)) {
Line indented incorrectly; expected at least 16 spaces, found 8
$order = $this->find_order_by_id($data->bill->code);
Line indented incorrectly; expected at least 16 spaces, found 8
$vindi_subscription_id = $data->bill->subscription->id;
Line indented incorrectly; expected at least 12 spaces, found 6
$order->update_status('cancelled', __('Pagamento cancelado dentro da Vindi!', VINDI));
Line indented incorrectly; expected at least 8 spaces, found 4
$issue_data = $data->issue->data;
Line indented incorrectly; expected at least 8 spaces, found 4
return $subscription;
Line indented incorrectly; expected at least 8 spaces, found 4
$order = wc_get_order($id);
Line indented incorrectly; expected at least 8 spaces, found 6
throw new Exception(sprintf(__('Pedido com bill_id #%s não encontrado!', VINDI), $bill_id), 2);
Line indented incorrectly; expected at least 12 spaces, found 6
$next_billing_at = $vindi_subscription['next_billing_at'];
Line indented incorrectly; expected 12 spaces, found 6
if ($end_at != null && $next_billing_at > $end_at) {
Line indented incorrectly; expected at least 16 spaces, found 8
return false;
Line indented incorrectly; expected 4 spaces, found 2
private function format_date($date)
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected 4 spaces, found 2
private function bill_canceled($data)
Line indented incorrectly; expected 8 spaces, found 4
}
Line indented incorrectly; expected 4 spaces, found 2
private function issue_created($data)
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
$charge = $this->routes->getCharge($id);
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected at least 8 spaces, found 4
$query = $this->query_order_by_metas(array(
Line indented incorrectly; expected at least 12 spaces, found 6
$subscription->update_dates(array('end_date' => $end_date));
Line indented incorrectly; expected at least 8 spaces, found 6
$this->routes = $vindi_settings->routes;
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
if (null == $body || empty($body->event))
Line indented incorrectly; expected 4 spaces, found 2
}
Multi-line function call not indented correctly; expected 10 spaces but found 8
__('Já existe o ciclo %s para a assinatura #%s pedido #%s!', VINDI),
Line indented incorrectly; expected 8 spaces, found 4
if ($this->subscription_has_order_in_cycle($renew_infos['vindi_subscription_id'], $renew_infos['cycle'])) {
Line indented incorrectly; expected at least 8 spaces, found 4
if ('open' !== $issue_status)
Line indented incorrectly; expected 8 spaces, found 4
} catch (Exception $e) {
Line indented incorrectly; expected at least 8 spaces, found 4
$item_id = (int) $data->issue->item_id;
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected at least 8 spaces, found 6
__('Divergencia de valores do Pedido #%s: Valor Esperado R$ %s, Valor Pago R$ %s.', VINDI),
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 4
if (empty($charge))
Line indented incorrectly; expected at least 8 spaces, found 4
if (empty($order))
Line indented incorrectly; expected at least 8 spaces, found 6
'post_type' => 'shop_order',
Line indented incorrectly; expected at least 8 spaces, found 6
'meta_value' => $bill_id,
Line indented incorrectly; expected at least 12 spaces, found 6
$next_payment = $this->format_date($next_billing_at);
Line indented incorrectly; expected at least 12 spaces, found 6
$subscription = $this->find_subscription_by_id($data->bill->subscription->code);
Line indented incorrectly; expected at least 12 spaces, found 6
$subscription->update_dates(array('next_payment' => $next_payment));
Line indented incorrectly; expected 4 spaces, found 2
}
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 6
$issue_data->expected_amount,
Line indented incorrectly; expected at least 8 spaces, found 6
$issue_data->transaction_amount
Line indented incorrectly; expected at least 8 spaces, found 4
return (object) $charge['bill'];
Line indented incorrectly; expected at least 8 spaces, found 4
return wc_get_order($query->post->ID);
Line indented incorrectly; expected at least 8 spaces, found 6
array(
Line indented incorrectly; expected at least 8 spaces, found 4
return $query->have_posts();
Line indented incorrectly; expected at least 8 spaces, found 4
$args = array(
Line indented incorrectly; expected 12 spaces, found 6
}
Line indented incorrectly; expected at least 8 spaces, found 4
$query = $this->query_order_by_metas(array(
Line indented incorrectly; expected 4 spaces, found 2
private $routes;
Line indented incorrectly; expected at least 16 spaces, found 14
$order = $this->find_order_by_id($data->bill->code);
Line indented incorrectly; expected at least 8 spaces, found 4
if (false === $query->have_posts())
Line indented incorrectly; expected at least 8 spaces, found 4
$query = new WP_Query($args);
Line indented incorrectly; expected at least 8 spaces, found 4
);
Line indented incorrectly; expected at least 12 spaces, found 6
$end_date = $this->format_date($end_at);
Line indented incorrectly; expected at least 8 spaces, found 6
'meta_query' => $metas,
Line indented incorrectly; expected at least 4 spaces, found 2
{
Line indented incorrectly; expected at least 8 spaces, found 6
array(
Line indented incorrectly; expected at least 8 spaces, found 4
return new WP_Query($args);
Line indented incorrectly; expected at least 12 spaces, found 6
$end_at = $vindi_subscription['end_at'];
There are no issues that match your filters.