vindi/vindi-woocommerce

View on GitHub
src/controllers/CustomerController.php

Summary

Maintainability
C
1 day
Test Coverage

Showing 159 of 159 total issues

Method update has 91 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function update($user_id, $order = null)
{
$vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);
if (!empty($vindi_customer_id)) {
$vindiUser = $this->routes->findCustomerById($vindi_customer_id);
Severity: Major
Found in src/controllers/CustomerController.php - About 3 hrs to fix

    Function update has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    function update($user_id, $order = null)
    {
    $vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);
    if (!empty($vindi_customer_id)) {
    $vindiUser = $this->routes->findCustomerById($vindi_customer_id);
    Severity: Minor
    Found in src/controllers/CustomerController.php - About 3 hrs to fix

    The class CustomerController has an overall complexity of 57 which is very high. The configured complexity threshold is 50.
    Open

    class CustomerController
    {
     
    /**
    * @var VindiSettings

    Method create has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function create($user_id, $order = null)
    {
     
    $customer = new WC_Customer($user_id);
     
     
    Severity: Major
    Found in src/controllers/CustomerController.php - About 2 hrs to fix

      Function create has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      function create($user_id, $order = null)
      {
       
      $customer = new WC_Customer($user_id);
       
       
      Severity: Minor
      Found in src/controllers/CustomerController.php - About 1 hr to fix

      The method create() has an NPath complexity of 589824. The configured NPath complexity threshold is 200.
      Open

      function create($user_id, $order = null)
      {
       
      $customer = new WC_Customer($user_id);
       
       

      The method update() has an NPath complexity of 38928384. The configured NPath complexity threshold is 200.
      Open

      function update($user_id, $order = null)
      {
      $vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);
      if (!empty($vindi_customer_id)) {
      $vindiUser = $this->routes->findCustomerById($vindi_customer_id);

      The method update() has a Cyclomatic Complexity of 30. The configured cyclomatic complexity threshold is 10.
      Open

      function update($user_id, $order = null)
      {
      $vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);
      if (!empty($vindi_customer_id)) {
      $vindiUser = $this->routes->findCustomerById($vindi_customer_id);

      The method create() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10.
      Open

      function create($user_id, $order = null)
      {
       
      $customer = new WC_Customer($user_id);
       
       

      The method create uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

      } else {
      // Pessoa física
      $cpf_or_cnpj = $order->get_meta('_billing_cpf');
      $notes = '';
       
       

      The property $vindi_settings is not named in camelCase.
      Open

      class CustomerController
      {
       
      /**
      * @var VindiSettings

      Visibility must be declared on method "__construct"
      Open

      function __construct(VindiSettings $vindi_settings)

      Visibility must be declared on method "create"
      Open

      function create($user_id, $order = null)

      Visibility must be declared on method "update"
      Open

      function update($user_id, $order = null)

      Blank line found at start of control structure
      Open

      if (empty($vindi_customer_id)) {

      Visibility must be declared on method "delete"
      Open

      function delete($user_id)

      Blank line found at start of control structure
      Open

      if (!$vindiUser) {

      Line exceeds 120 characters; contains 125 characters
      Open

      'neighborhood' => ($customer->get_meta('billing_neighborhood')) ? $customer->get_meta('billing_neighborhood') : '',

      Line exceeds 120 characters; contains 125 characters
      Open

      'neighborhood' => ($customer->get_meta('billing_neighborhood')) ? $customer->get_meta('billing_neighborhood') : '',

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      add_action('woocommerce_save_account_details', array($this, 'update'), 10, 1);

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if ($customer->get_billing_phone()) {

      Multi-line function call not indented correctly; expected 8 spaces but found 6
      Open

      array(

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

      {

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $notes = null;

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $cpf_or_cnpj = $order->get_meta('_billing_cnpj');

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $phones[] = array(

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      function create($user_id, $order = null)

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $metadata = array();

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $name = $order->get_billing_company();

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $notes = sprintf('Nome: %s %s', $order->get_billing_first_name(), $order->get_billing_last_name());

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $createdUser = $this->routes->createCustomer(

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      private $vindi_settings;

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $this->vindi_settings = $vindi_settings;

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if ($customer->get_meta('billing_cellphone')) {

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      if ($this->vindi_settings->send_nfe_information()) {

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

      $metadata['carteira_de_identidade'] = $order->get_meta('_billing_rg');

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      add_action('user_register', array($this, 'create'), 10, 1);

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $customer = new WC_Customer($user_id);

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'number' => preg_replace('/\D+/', '', '55' . $customer->get_billing_phone())

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      private $routes;

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      add_action('woocommerce_customer_save_address', array($this, 'update'), 10, 1);

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $user = $customer->get_data();

      Line indented incorrectly; expected 12 spaces, found 6
      Open

      } else {

      Line indented incorrectly; expected at least 10 spaces, found 4
      Open

      );

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $name = (!$user['first_name']) ? $user['display_name'] : $user['first_name'] . ' ' . $user['last_name'];

      Line indented incorrectly; expected 12 spaces, found 6
      Open

      if ('2' === $order->get_meta('_billing_persontype')) {

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      }

      Multi-line function call not indented correctly; expected 8 spaces but found 6
      Open

      )

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $cpf_or_cnpj = null;

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $phones[] = array(

      Line indented incorrectly; expected at least 16 spaces, found 6
      Open

      );

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if ($order && method_exists($order, 'needs_payment')) {

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $cpf_or_cnpj = $order->get_meta('_billing_cpf');

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      add_action('delete_user', array($this, 'delete'), 10, 1);

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $phones = [];

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'number' => preg_replace('/\D+/', '', '55' . $customer->get_meta('billing_cellphone'))

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      if ($this->vindi_settings->send_nfe_information()) {

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

      $metadata['inscricao_estadual'] = $order->get_meta('_billing_ie');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

      array(

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      return $this->create($user_id);

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if (empty($vindi_customer_id)) {

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      function __construct(VindiSettings $vindi_settings)

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

      {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'phone_type' => 'landline',

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $notes = '';

      Line indented incorrectly; expected at least 14 spaces, found 12
      Open

      update_user_meta($user_id, 'vindi_customer_id', $createdUser['id']);

      Line indented incorrectly; expected at least 12 spaces, found 4
      Open

      return $createdUser;

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $cpf_or_cnpj = null;

      Line indented incorrectly; expected at least 10 spaces, found 4
      Open

      );

      Line indented incorrectly; expected at least 16 spaces, found 6
      Open

      );

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if ($customer->get_billing_phone()) {

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

      {

      Multi-line function call not indented correctly; expected 8 spaces but found 6
      Open

      $vindi_customer_id

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

      $vindi_customer_id

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      function update($user_id, $order = null)

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $vindi_phones[$phone['phone_type']] = $phone['id'];

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'number' => preg_replace('/\D+/', '', '55' . $customer->get_meta('billing_cellphone'))

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

      $vindi_customer_id,

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      }

      Line indented incorrectly; expected at least 10 spaces, found 4
      Open

      );

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $metadata = null;

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'phone_type' => 'mobile',

      Line indented incorrectly; expected at least 16 spaces, found 6
      Open

      );

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      }

      Line indented incorrectly; expected 12 spaces, found 10
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $notes = null;

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if ($order && method_exists($order, 'needs_payment')) {

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      }

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $this->vindi_settings->logger->log(sprintf('Order rg -> %s', $order->get_meta('_billing_rg')));

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $this->routes = $vindi_settings->routes;

      Line indented incorrectly; expected 12 spaces, found 6
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

      )

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      foreach ($vindiUser['phones'] as $phone) {

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $landline = array(

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

      )

      Line indented incorrectly; expected at least 10 spaces, found 4
      Open

      return $deletedUser;

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if (empty($vindi_customer_id)) {

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $name = (!$user['first_name']) ? $user['display_name'] : $user['first_name'] . ' ' . $user['last_name'];

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $updatedUser = $this->routes->updateCustomer(

      Line indented incorrectly; expected at least 10 spaces, found 4
      Open

      return $updatedUser;

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      return;

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      return;

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $mobile = array(

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

      $metadata['inscricao_estadual'] = $order->get_meta('_billing_ie');

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

      $metadata['carteira_de_identidade'] = $order->get_meta('_billing_rg');

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $vindiUser = $this->routes->findCustomerById($vindi_customer_id);

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if (!$vindiUser) {

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $customer = new WC_Customer($user_id);

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $phones = $vindi_phones = [];

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'phone_type' => 'mobile',

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      if ($this->vindi_settings->send_nfe_information()) {

      Multi-line function call not indented correctly; expected 8 spaces but found 6
      Open

      $vindi_customer_id,

      Multi-line function call not indented correctly; expected 8 spaces but found 6
      Open

      array(

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      function delete($user_id)

      Line indented incorrectly; expected 4 spaces, found 2
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $user = $customer->get_data();

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $metadata = null;

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $name = $order->get_billing_company();

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $this->vindi_settings->logger->log(sprintf('Order cpf -> %s', $cpf_or_cnpj));

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'number' => preg_replace('/\D+/', '', '55' . $customer->get_billing_phone())

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $this->vindi_settings->logger->log(sprintf('Customer cpf -> %s', $customer->get_meta('billing_cpf')));

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $notes = '';

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

      array(

      Line indented incorrectly; expected 12 spaces, found 6
      Open

      }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $deletedUser = $this->routes->deleteCustomer(

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if (empty($vindi_customer_id)) {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if ($customer->get_meta('billing_cellphone')) {

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $cpf_or_cnpj = $order->get_meta('_billing_cnpj');

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $notes = sprintf('Nome: %s %s', $order->get_billing_first_name(), $order->get_billing_last_name());

      Line indented incorrectly; expected 16 spaces, found 8
      Open

      if ($this->vindi_settings->send_nfe_information()) {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      if (!$vindiUser) {

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

      $vindiUser = $this->routes->findCustomerById($vindi_customer_id);

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      return $this->create($user_id, $order);

      Line indented incorrectly; expected at least 16 spaces, found 6
      Open

      $phones[] = $mobile;

      Line indented incorrectly; expected at least 16 spaces, found 6
      Open

      );

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

      $cpf_or_cnpj = $order->get_meta('_billing_cpf');

      Multi-line function call not indented correctly; expected 8 spaces but found 6
      Open

      )

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

      {

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

      'phone_type' => 'landline',

      Line indented incorrectly; expected at least 16 spaces, found 6
      Open

      $phones[] = $landline;

      Line indented incorrectly; expected 8 spaces, found 4
      Open

      }

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

      $metadata = array();

      Line indented incorrectly; expected 12 spaces, found 6
      Open

      if ('2' === $order->get_meta('_billing_persontype')) {

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

      $vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);

      There are no issues that match your filters.

      Category
      Status