Skip to content

Commit

Permalink
Merge pull request #785 from ebanx/quality/refactor-wc-ebanx-helper
Browse files Browse the repository at this point in the history
Remove require command from WC_EBANX_Helper and start use a namespace
  • Loading branch information
Ruanito authored May 17, 2019
2 parents b114f9f + 0be2819 commit 0a3b9ff
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions controllers/class-wc-ebanx-api-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}

use EBANX\Plugin\Services\WC_EBANX_Constants;
use EBANX\Plugin\Services\WC_EBANX_Helper;

/**
* Class WC_EBANX_Api_Controller
Expand Down
1 change: 1 addition & 0 deletions gateways/class-wc-ebanx-credit-card-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Ebanx\Benjamin\Models\Configs\CreditCardConfig;
use Ebanx\Benjamin\Models\Country;
use EBANX\Plugin\Services\WC_EBANX_Constants;
use EBANX\Plugin\Services\WC_EBANX_Helper;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
1 change: 1 addition & 0 deletions gateways/class-wc-ebanx-gateway.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use EBANX\Plugin\Services\WC_EBANX_Constants;
use EBANX\Plugin\Services\WC_EBANX_Helper;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
2 changes: 1 addition & 1 deletion gateways/class-wc-ebanx-global-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
if ( ! in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) {
wp_die( 'Sorry, but this plugin requires the Woocommerce plugin to be installed and active.', null, array( 'back_link' => true ) );
}
require_once WC_EBANX_SERVICES_DIR . 'class-wc-ebanx-helper.php';
}

use EBANX\Plugin\Services\WC_EBANX_Constants;
use EBANX\Plugin\Services\WC_EBANX_Notice;
use EBANX\Plugin\Services\WC_EBANX_Helper;

/**
* Class WC_EBANX_Global_Gateway
Expand Down
1 change: 1 addition & 0 deletions gateways/class-wc-ebanx-new-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Ebanx\Benjamin\Models\Currency;
use EBANX\Plugin\Services\WC_EBANX_Constants;
use EBANX\Plugin\Services\WC_EBANX_Errors;
use EBANX\Plugin\Services\WC_EBANX_Helper;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?php

namespace EBANX\Plugin\Services;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! defined( 'IS_TEST' ) ) {
require_once WC_EBANX_GATEWAYS_DIR . 'class-wc-ebanx-global-gateway.php';
require_once WC_EBANX_VENDOR_DIR . 'autoload.php';
}

use RuntimeException as RuntimeException;
use Ebanx\Benjamin\Services\Gateways\CreditCard;
use Ebanx\Benjamin\Models\Configs\Config;
use Ebanx\Benjamin\Models\Configs\CreditCardConfig;
use EBANX\Plugin\Services\WC_EBANX_Constants;

/**
* Class WC_EBANX_Helper
*/
abstract class WC_EBANX_Helper {

/**
Expand All @@ -30,8 +27,8 @@ public static function flatten( array $array ) {
$return = array();
array_walk_recursive(
$array, function( $value ) use ( &$return ) {
$return[] = $value;
}
$return[] = $value;
}
);

return $return;
Expand All @@ -43,7 +40,7 @@ public static function flatten( array $array ) {
* @return string
*/
public static function get_integration_key() {
$config = new WC_EBANX_Global_Gateway();
$config = new \WC_EBANX_Global_Gateway();

return 'yes' === $config->settings['sandbox_mode_enabled'] ? $config->settings['sandbox_private_key'] : $config->settings['live_private_key'];
}
Expand Down Expand Up @@ -169,7 +166,7 @@ public static function get_instalments_by_country( $country_abbr ) {
* @return bool
*/
public static function should_apply_taxes() {
$configs = new WC_EBANX_Global_Gateway();
$configs = new \WC_EBANX_Global_Gateway();

return $configs->get_setting_or_default( 'add_iof_to_local_amount_enabled', 'yes' ) === 'yes';
}
Expand All @@ -179,7 +176,7 @@ public static function should_apply_taxes() {
*
* @return array
*/
public static function plugin_check( WC_EBANX_Global_Gateway $configs ) {
public static function plugin_check( \WC_EBANX_Global_Gateway $configs ) {
global $wpdb;

$all_plugins = get_plugins();
Expand Down
1 change: 1 addition & 0 deletions services/class-wc-ebanx-payment-adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ebanx\Benjamin\Models\Payment;
use Ebanx\Benjamin\Models\Person;
use EBANX\Plugin\Services\WC_EBANX_Constants;
use EBANX\Plugin\Services\WC_EBANX_Helper;

/**
* Class WC_EBANX_Payment_Adapter
Expand Down
2 changes: 1 addition & 1 deletion services/loggers/class-wc-ebanx-logger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once WC_EBANX_SERVICES_DIR . 'class-wc-ebanx-helper.php';
use EBANX\Plugin\Services\WC_EBANX_Helper;

/**
* Abstract logger class, responsible to persist log on database
Expand Down
2 changes: 1 addition & 1 deletion templates/ebanx-credit-card-ar/card-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<?php
$input_type = 'checkbox';
$save_card_text = 'Guarda esta tarjeta para compras futuras.';
if ( WC_EBANX_Helper::checkout_contains_subscription() ) {
if ( EBANX\Plugin\Services\WC_EBANX_Helper::checkout_contains_subscription() ) {
$input_type = 'hidden';
$save_card_text = null;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/ebanx-credit-card-br/card-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<?php
$input_type = 'checkbox';
$save_card_text = 'Salvar este cartão para compras futuras';
if ( WC_EBANX_Helper::checkout_contains_subscription() ) {
if ( EBANX\Plugin\Services\WC_EBANX_Helper::checkout_contains_subscription() ) {
$input_type = 'hidden';
$save_card_text = null;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/ebanx-credit-card-co/card-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<?php
$input_type = 'checkbox';
$save_card_text = 'Guarda esta tarjeta para compras futuras.';
if ( WC_EBANX_Helper::checkout_contains_subscription() ) {
if ( EBANX\Plugin\Services\WC_EBANX_Helper::checkout_contains_subscription() ) {
$input_type = 'hidden';
$save_card_text = null;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/ebanx-credit-card-mx/card-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<?php
$input_type = 'checkbox';
$save_card_text = 'Guarda esta tarjeta para compras futuras.';
if ( WC_EBANX_Helper::checkout_contains_subscription() ) {
if ( EBANX\Plugin\Services\WC_EBANX_Helper::checkout_contains_subscription() ) {
$input_type = 'hidden';
$save_card_text = null;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/instalments.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

if ( count( $instalments_terms ) > 1 ) : ?>
<section class="ebanx-form-row">
<?php if ( WC_EBANX_Helper::checkout_contains_subscription() ) : ?>
<?php if ( EBANX\Plugin\Services\WC_EBANX_Helper::checkout_contains_subscription() ) : ?>
<input type="hidden" name="ebanx-credit-card-installments" value="1" />
<?php else : ?>
<label for="ebanx-card-installments">
Expand Down
1 change: 1 addition & 0 deletions tests/unit/services/EbanxHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use EBANX\Plugin\Services\WC_EBANX_Helper;

class EbanxHelperTest extends TestCase {
public function setUp() {
Expand Down
1 change: 0 additions & 1 deletion woocommerce-gateway-ebanx.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ private static function include_log_classes() {
*/
private function includes() {
// Utils.
include_once WC_EBANX_SERVICES_DIR . 'class-wc-ebanx-helper.php';
include_once WC_EBANX_SERVICES_DIR . 'class-wc-ebanx-hooks.php';
include_once WC_EBANX_SERVICES_DIR . 'class-wc-ebanx-checker.php';
include_once WC_EBANX_SERVICES_DIR . 'class-wc-ebanx-flash.php';
Expand Down

0 comments on commit 0a3b9ff

Please sign in to comment.