Method init_form_fields
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
function init_form_fields()
{
$url = admin_url(sprintf('admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', VINDI, $this->get_token()));
$logs_url = '<a href="' . $url . '" target="_blank">' . __('Ver Logs', VINDI) . '</a>';
$nfe_know_more = '<a href="http://atendimento.vindi.com.br/hc/pt-br/articles/204450944-Notas-fiscais" target="_blank">' . __('Saiba mais', VINDI) . '</a>';
Avoid unused local variables such as '$sand_box_article'. Open
$sand_box_article = '<a href="https://atendimento.vindi.com.br/hc/pt-br/articles/115012242388-Sandbox" target="_blank">' . __('Dúvidas?', VINDI) . '</a>';
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused private fields such as '$plugin'. Open
private $plugin;
- 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 method check_ssl uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return is_ssl();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method get_return_status uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return 'processing';
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method api_key_field uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
update_option('vindi_invalid_api_key', false);
$this->invalidApiKey = false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Visibility must be declared on method "init_form_fields" Open
function init_form_fields()
- Exclude checks
Visibility must be declared on method "__construct" Open
function __construct()
- Exclude checks
Visibility must be declared on method "checkKey" Open
function checkKey()
- Exclude checks
The 'get_is_active_sandbox()' method which returns a boolean should be named 'is...()' or 'has...()' Open
public function get_is_active_sandbox()
{
return $this->settings['sandbox'];
}
- Read upRead up
- Exclude checks
BooleanGetMethodName
Since: 0.2
Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.
Example
class Foo {
/**
* @return boolean
*/
public function getFoo() {} // bad
/**
* @return bool
*/
public function isFoo(); // ok
/**
* @return boolean
*/
public function getFoo($bar); // ok, unless checkParameterizedMethods=true
}
Source https://phpmd.org/rules/naming.html#booleangetmethodname
Line exceeds 120 characters; contains 126 characters Open
'description' => __('Ative esta opção para habilitar a comunicação com o ambiente Sandbox da Vindi.', VINDI),
- Exclude checks
Line exceeds 120 characters; contains 166 characters Open
'description' => sprintf(__('Envia informações de RG e Inscrição Estadual para Emissão de NFe\'s com nossos parceiros. %s', VINDI), $nfe_know_more),
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$prospects_url = '<a href="https://app.vindi.com.br/prospects/new" target="_blank">' . __('Não possui uma conta?', VINDI) . '</a>';
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$url = admin_url(sprintf('admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', VINDI, $this->get_token()));
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
$sand_box_article = '<a href="https://atendimento.vindi.com.br/hc/pt-br/articles/115012242388-Sandbox" target="_blank">' . __('Dúvidas?', VINDI) . '</a>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return sprintf('%s/index.php/wc-api/%s?token=%s',
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
'description' => __('Status que o pedido deverá ter após receber a confirmação de pagamento da Vindi.', VINDI),
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
'description' => sprintf(__('Ative esta opção para habilitar logs de depuração do servidor. %s', VINDI), $logs_url),
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
$nfe_know_more = '<a href="http://atendimento.vindi.com.br/hc/pt-br/articles/204450944-Notas-fiscais" target="_blank">' . __('Saiba mais', VINDI) . '</a>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function get_webhooks_url() {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $plugin;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (is_admin()) {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->form_fields = array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
global $woocommerce;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->api = new VindiApi($this->get_api_key(), $this->logger, $this->get_is_active_sandbox());
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
sprintf(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$url = admin_url(sprintf('admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', VINDI, $this->get_token()));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->init_settings();
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
$this->invalidApiKey = get_option( 'vindi_invalid_api_key', false );
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
function __construct()
- 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->routes = new VindiRoutes($this);
- 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 at least 8 spaces, found 4 Open
$prospects_url = '<a href="https://app.vindi.com.br/prospects/new" target="_blank">' . __('Não possui uma conta?', VINDI) . '</a>';
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $settings_tabs;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function settings_tab()
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 6 Open
'',
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'return_status' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $invalidApiKey;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->debug = $this->get_option('debug') == 'yes' ? true : false;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->woocommerce = $woocommerce;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->invalidApiKey = get_option( 'vindi_invalid_api_key', false );
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public static function add_settings_tab($settings_tabs)
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $logger;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function get_template($name, $args = array())
- 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
$nfe_know_more = '<a href="http://atendimento.vindi.com.br/hc/pt-br/articles/204450944-Notas-fiscais" target="_blank">' . __('Saiba mais', VINDI) . '</a>';
- Exclude checks
Line indented incorrectly; expected at least 10 spaces, found 4 Open
);
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $woocommerce;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $routes;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->token = sanitize_file_name(wp_hash(VINDI));
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$sand_box_article = '<a href="https://atendimento.vindi.com.br/hc/pt-br/articles/115012242388-Sandbox" target="_blank">' . __('Dúvidas?', VINDI) . '</a>';
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
$args,
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 6 Open
sprintf(
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 6 Open
)
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
function init_form_fields()
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $token;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'send_nfe_information' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'debug' => array(
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 6 Open
$args,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 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 6 Open
'api_key' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'testing' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->logger = new VindiLogger(VINDI, $this->debug);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->get_template('admin-settings.html.php', array('settings' => $this));
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 6 Open
$name,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
)
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'vindi_synchronism' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return 'text';
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
private $debug;
- 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->dependencies = new VindiDependencies;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$settings_tabs['settings_vindi'] = __('Vindi', VINDI);
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'shipping_and_tax_config' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'sandbox' => array(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(isset($this->settings['return_status'])) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return 'yes' === $this->settings['send_nfe_information'];
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function is_api_key_valid()
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Opening brace should be on a new line Open
public function get_webhooks_url() {
- 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
public function get_token()
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
include_once VINDI_SRC . 'views/invalid-api-key.php';
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return 'processing';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function send_nfe_information()
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return is_ssl();
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function get_return_status()
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $dependencies;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public $api;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->init_form_fields();
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $this->settings['sandbox'];
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if (!$api_key) {
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$this->invalidApiKey = get_option( 'vindi_invalid_api_key', 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
wc_get_template(
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
$name,
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
'',
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$logs_url = '<a href="' . $url . '" target="_blank">' . __('Ver Logs', VINDI) . '</a>';
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 6 Open
),
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
function checkKey()
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $this->settings['api_key'];
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
} else {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function api_key_field()
- 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
$api_key = $this->get_api_key();
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$this->api = new VindiApi($api_key, $this->logger, $this->get_is_active_sandbox());
- 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 get_is_active_sandbox()
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
update_option('vindi_invalid_api_key', true);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if($this->invalidApiKey) {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
include_once VINDI_SRC . 'views/invalid-api-key.php';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if(isset($this->settings['return_status'])) {
- 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 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 at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
update_option('vindi_invalid_api_key', false);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
return sprintf('%s/index.php/wc-api/%s?token=%s',
- Exclude checks
Closing brace indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return 'yes' === $this->settings['vindi_synchronism'];
- 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 8 spaces, found 4 Open
if ('unauthorized' === $this->api->test_api_key($api_key)) {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$this->invalidApiKey = true;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if ($this->get_is_active_sandbox()) {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($this->invalidApiKey) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 4 Open
);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
);
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function get_synchronism_status()
- 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 function get_api_key()
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return true;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function get_shipping_and_tax_config()
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return 'yes' === $this->settings['shipping_and_tax_config'];
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
return $this->settings['return_status'];
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
return $this->token;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
public function check_ssl()
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$this->invalidApiKey = false;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
} else {
- Exclude checks