Completed
Push — master ( 0a5acd...43aa97 )
by Guilherme Luiz Argentino
05:40
created

correios::uninstall()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 0
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/** MODULO ADAPTADO POR ODLANIER
4
 * @author Odlanier de Souza Mendes
5
 * @copyright Dlani
6
 * @email [email protected]
7
 * @version 3.0
8
 * */
9
if (!defined('_PS_VERSION_'))
10
    exit;
11
12
class correios extends CarrierModule {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
14
    public $id_carrier;
15
    private $_urlWebservice = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?wsdl";
16
    private $_html = '';
0 ignored issues
show
Unused Code introduced by
The property $_html is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
    private $_postErrors = array();
0 ignored issues
show
Unused Code introduced by
The property $_postErrors is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
    private $_factorys = array(
0 ignored issues
show
Unused Code introduced by
The property $_factorys is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        "soapclient" => "SOAP Client",
20
        "nusoap" => "NuSoap"
21
    );
22
    private $_factory = "soapclient";
23
    public $servicos_todos = array(
24
        '04510' => 'PAC',# era '41106' => 'PAC',
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
        '04014' => 'SEDEX', # era '40010' => 'SEDEX',
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
        '40215' => 'SEDEX 10',
27
        '40290' => 'SEDEX HOJE',
28
            //'81019' => 'E-SEDEX', 
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
            //'44105' => 'MALOTE',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
            //'41017' => 'NORMAL', 
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
            //'40045' => 'SEDEX A COBRAR', 
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
    );
33
    private $_moduleName = 'correios';
34
35
    function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
        $this->name = 'correios';
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
        $this->tab = 'shipping_logistics';
0 ignored issues
show
Bug introduced by
The property tab does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
        $this->version = '3.0';
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
        $this->author = 'Dlani Mendes';
0 ignored issues
show
Bug introduced by
The property author does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
        $this->limited_countries = array('br');
0 ignored issues
show
Bug introduced by
The property limited_countries does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
42
        parent::__construct();
43
44
        /* The parent construct is required for translations */
45
        $this->page = basename(__file__, '.php');
0 ignored issues
show
Bug introduced by
The property page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
        $this->displayName = $this->l('Frete Correios');
0 ignored issues
show
Bug introduced by
The property displayName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Unused Code introduced by
The call to correios::l() has too many arguments starting with 'Frete Correios'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
Are you sure the assignment to $this->displayName is correct as $this->l('Frete Correios') (which targets CarrierModule::l()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
47
        $this->description = 'Painel de Controle dos Frete Correios.';
0 ignored issues
show
Bug introduced by
The property description does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
    }
49
50
    function install() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
51
        if (parent::install() == false or
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class CarrierModule as the method install() does only exist in the following sub-classes of CarrierModule: correios. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
52
                $this->registerHook('updateCarrier') == false or
0 ignored issues
show
Bug introduced by
The method registerHook() does not seem to exist on object<correios>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
53
                $this->registerHook('extraCarrier') == false or
0 ignored issues
show
Bug introduced by
The method registerHook() does not seem to exist on object<correios>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
54
                $this->registerHook('beforeCarrier') == false)
0 ignored issues
show
Bug introduced by
The method registerHook() does not seem to exist on object<correios>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
            return false;
56
57
        $this->installCarriers();
58
59
        return true;
60
    }
61
62
    /**
63
     * 
64
     */
65
    private function installCarriers() {
66
        $configBase = array(
67
            'id_tax_rules_group' => 0,
68
            'active' => true,
69
            'deleted' => 0,
70
            'shipping_handling' => false,
71
            'range_behavior' => 0,
72
            'delay' => array("br" => "Entrega pelos Correios."),
73
            'id_zone' => 1,
74
            'is_module' => true,
75
            'shipping_external' => true,
76
            'external_module_name' => $this->_moduleName,
77
            'need_range' => true,
78
            'url' => Tools::getHttpHost(true) . "/modules/correios/rastreio.php?objeto=@",
79
        );
80
81
        $arrayConfigs = array();
82
        foreach ($this->servicos_todos as $codServico => $servico)
83
            $arrayConfigs[] = array(
84
                "name" => "Correios - $servico",
85
                "cod_servico" => $codServico
86
            );
87
88
        foreach ($arrayConfigs as $config) {
89
            $config = array_merge($configBase, $config);
90
            $this->installExternalCarrier($config);
0 ignored issues
show
Documentation introduced by
$config is of type array<string,integer|boo..."br":"string"}>|string>, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
91
        }
92
    }
93
94
    /**
95
     * 
96
     * @param type $config
97
     * @return boolean
98
     */
99
    public function installExternalCarrier($config) {
100
        $check = Db::getInstance()->executeS("SELECT id_carrier FROM " . _DB_PREFIX_ . "carrier WHERE name = '" . $config['name'] . "' ");
101
        if (is_array($check) && !empty($check))
102
            return Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 0), 'UPDATE', ' name = "' . $config['name'] . '" ');
103
104
        $carrier = new Carrier();
105
        $carrier->name = $config['name'];
0 ignored issues
show
Bug introduced by
The property name does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
106
        $carrier->url = $config['url'];
0 ignored issues
show
Bug introduced by
The property url does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
107
        $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
0 ignored issues
show
Bug introduced by
The property id_tax_rules_group does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
        $carrier->id_zone = $config['id_zone'];
0 ignored issues
show
Bug introduced by
The property id_zone does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
109
        $carrier->active = $config['active'];
0 ignored issues
show
Bug introduced by
The property active does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
110
        $carrier->deleted = $config['deleted'];
0 ignored issues
show
Bug introduced by
The property deleted does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
111
        $carrier->delay = $config['delay'];
0 ignored issues
show
Bug introduced by
The property delay does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
112
        $carrier->shipping_handling = $config['shipping_handling'];
0 ignored issues
show
Bug introduced by
The property shipping_handling does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
113
        $carrier->range_behavior = $config['range_behavior'];
0 ignored issues
show
Bug introduced by
The property range_behavior does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
114
        $carrier->is_module = $config['is_module'];
0 ignored issues
show
Bug introduced by
The property is_module does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
115
        $carrier->shipping_external = $config['shipping_external'];
0 ignored issues
show
Bug introduced by
The property shipping_external does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
116
        $carrier->external_module_name = $config['external_module_name'];
0 ignored issues
show
Bug introduced by
The property external_module_name does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
117
        $carrier->need_range = $config['need_range'];
0 ignored issues
show
Bug introduced by
The property need_range does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
118
119
        $languages = Language::getLanguages(true);
120
        foreach ($languages as $language) {
121
            $carrier->delay[(int) $language['id_lang']] = $config['delay']['br'];
122
        }
123
124
        if ($carrier->add()) {
0 ignored issues
show
Bug introduced by
The method add() does not seem to exist on object<Carrier>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
            $groups = Group::getGroups(true);
126
            foreach ($groups as $group)
127
                Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) ($carrier->id), 'id_group' => (int) ($group['id_group'])), 'INSERT');
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
128
129
            $rangePrice = new RangePrice();
130
            $rangePrice->id_carrier = $carrier->id;
131
            $rangePrice->delimiter1 = '0';
132
            $rangePrice->delimiter2 = '0';
133
            $rangePrice->add();
134
135
            $rangeWeight = new RangeWeight();
136
            $rangeWeight->id_carrier = $carrier->id;
137
            $rangeWeight->delimiter1 = '0';
138
            $rangeWeight->delimiter2 = '30';
139
            $rangeWeight->add();
140
141
            $zones = Zone::getZones(true);
142
            foreach ($zones as $zone) {
143
                Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) ($carrier->id), 'id_zone' => (int) ($zone['id_zone'])), 'INSERT');
144
                Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) ($carrier->id), 'id_range_price' => (int) ($rangePrice->id), 'id_range_weight' => NULL, 'id_zone' => (int) ($zone['id_zone']), 'price' => '0'), 'INSERT');
145
                Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) ($carrier->id), 'id_range_price' => NULL, 'id_range_weight' => (int) ($rangeWeight->id), 'id_zone' => (int) ($zone['id_zone']), 'price' => '0'), 'INSERT');
146
            }
147
148
            Configuration::updateValue("PS_CORREIOS_CARRIER_{$carrier->id}", $config['cod_servico']);
0 ignored issues
show
Bug introduced by
The method updateValue() does not exist on Configuration. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
149
150
            // Copy Logo
151
            if (!copy(dirname(__FILE__) . '/logos/' . $config['cod_servico'] . '.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'))
152
                return false;
153
154
            // Return ID Carrier
155
            return (int) ($carrier->id);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return (int) $carrier->id; (integer) is incompatible with the return type documented by correios::installExternalCarrier of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
156
        }
157
        return false;
158
    }
159
160
    /**
161
     * 
162
     * @return boolean
163
     */
164
    public function uninstall() {
165
        // Uninstall Carriers
166
        $result = Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 1), 'UPDATE', ' name LIKE "Correios%" ');
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
167
168
        if (!Configuration::deleteByName('PS_CORREIOS_CEP_ORIG'))
0 ignored issues
show
Bug introduced by
The method deleteByName() does not exist on Configuration. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
169
            return false;
170
171
        if (!parent::uninstall() OR !$this->unregisterHook('updateCarrier'))
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class CarrierModule as the method uninstall() does only exist in the following sub-classes of CarrierModule: correios. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
Bug introduced by
The method unregisterHook() does not seem to exist on object<correios>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
172
            return false;
173
174
        return true;
175
    }
176
177
    /**
178
     * 
179
     * @return type
180
     */
181
    public function getContent() {
0 ignored issues
show
Coding Style introduced by
getContent uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
182
        $output = '<h2>' . $this->displayName . '</h2>';
183
        if (Tools::isSubmit('submitcarrinho_correios')) {
184
            Configuration::updateValue('PS_CORREIOS_CEP_ORIG', intval($_POST['cep']));
0 ignored issues
show
Bug introduced by
The method updateValue() does not exist on Configuration. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
185
186
            $output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->
187
                            l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
0 ignored issues
show
Unused Code introduced by
The call to correios::l() has too many arguments starting with 'Confirmation'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to correios::l() has too many arguments starting with 'Settings updated'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
188
        }
189
        if (Tools::isSubmit('factory')) {
190
            Configuration::updateValue('PS_CORREIOS_FACTORY', $_POST['factory']);
0 ignored issues
show
Bug introduced by
The method updateValue() does not exist on Configuration. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
191
192
            $output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->
193
                            l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
0 ignored issues
show
Unused Code introduced by
The call to correios::l() has too many arguments starting with 'Confirmation'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to correios::l() has too many arguments starting with 'Settings updated'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
194
        }
195
196
        return $output . $this->displayForm();
197
    }
198
199
    /**
200
     * 
201
     * @return type
202
     */
203
    public function displayForm() {
0 ignored issues
show
Coding Style introduced by
displayForm uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
204
        $conf = Configuration::getMultiple(array('PS_CORREIOS_CEP_ORIG'));
205
        $cep_orig = array_key_exists('cep', $_POST) ? $_POST['cep'] : (array_key_exists('PS_CORREIOS_CEP_ORIG', $conf) ? $conf['PS_CORREIOS_CEP_ORIG'] : '');
206
        include (dirname(__file__) . "/form_config.php");
207
        return $form_config;
0 ignored issues
show
Bug introduced by
The variable $form_config does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
208
    }
209
210
    /**
211
     * 
212
     * @param type $params
213
     * @param type $shipping_cost
214
     * @return boolean
215
     */
216
    public function getOrderShippingCost($params, $shipping_cost) {
217
        $carrier = new Carrier();
0 ignored issues
show
Unused Code introduced by
$carrier is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
218
        $chave = Configuration::get("PS_CORREIOS_CARRIER_{$this->id_carrier}");
219
        $address = new Address($params->id_address_delivery);
0 ignored issues
show
Unused Code introduced by
The call to Address::__construct() has too many arguments starting with $params->id_address_delivery.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
220
221
        $sCepDestino = preg_replace("/([^0-9])/", "", $address->postcode);
222
223
        $paramsCorreios = array(
224
            "sCepDestino" => $sCepDestino,
225
            "nVlPeso" => (string) $params->getTotalWeight(),
226
            "nCdServico" => $chave,
227
        );
228
229
        $this->getPriceWebService($paramsCorreios);
0 ignored issues
show
Documentation introduced by
$paramsCorreios is of type array<string,string|null...ervico":"string|null"}>, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
230
        $custoFrete = $this->getPriceWebService($paramsCorreios);
0 ignored issues
show
Documentation introduced by
$paramsCorreios is of type array<string,string|null...ervico":"string|null"}>, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
231
232
        if ($custoFrete === false || $custoFrete === 0.0)
233
            return false;
234
235
        return $custoFrete + $shipping_cost;
236
    }
237
238
    /**
239
     * 
240
     * @param type $params
241
     * @return type
242
     */
243
    public function getOrderShippingCostExternal($params) {
244
        return $this->getOrderShippingCost($params, 0);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
245
    }
246
247
    /**
248
     * 
249
     * @param type $params
250
     */
251
    public function hookupdateCarrier($params) {
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
252
        
253
    }
254
255
    /**
256
     * 
257
     * @global type $smarty
258
     * @param type $params
259
     * @return type
260
     */
261
    public function hookbeforeCarrier($params) {
262
        global $smarty;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
263
        $address = new Address($params['cart']->id_address_delivery);
0 ignored issues
show
Unused Code introduced by
The call to Address::__construct() has too many arguments starting with $params['cart']->id_address_delivery.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
264
        $smarty->assign(array(
265
            "sCepDestino" => $address->postcode
266
        ));
267
        return $this->display(__file__, 'extra_carrier.tpl');
0 ignored issues
show
Bug introduced by
The method display() does not exist on correios. Did you maybe mean displayForm()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
268
    }
269
270
    /**
271
     * 
272
     * @param type $params
273
     */
274
    public function hookextraCarrier($params) {
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
275
        
276
    }
277
278
    /**
279
     * 
280
     * @param type $params
281
     * @return type
282
     */
283
    private function getPriceWebService($params) {
284
        $paramsBase = array(
285
            "nCdEmpresa" => "",
286
            "sDsSenha" => "",
287
            "sCepOrigem" => str_pad(Configuration::get('PS_CORREIOS_CEP_ORIG'), 8, "0", STR_PAD_LEFT),
288
            "nCdFormato" => "1",
289
            "nVlComprimento" => "30",
290
            "nVlAltura" => "8",
291
            "nVlLargura" => "30",
292
            "nVlDiametro" => "0",
293
            "sCdMaoPropria" => "N",
294
            "nVlValorDeclarado" => "0",
295
            "sCdAvisoRecebimento" => "N"
296
        );
297
        $params = array_merge($paramsBase, $params);
298
        $hash = ( implode("|", $params) );
299
        $getInCache = $this->getCache($hash);
0 ignored issues
show
Documentation introduced by
$hash is of type string, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
300
301
        if ($getInCache) {
302
            $return = $getInCache;
303
        } else {
304
            $this->_factory = Configuration::get("PS_CORREIOS_FACTORY");
305
            $method = "getPreco" . ucfirst(strtolower($this->_factory));
306
            
307
            $return = $this->$method($params, $hash);
308
            $this->setCache($hash, $return);
0 ignored issues
show
Documentation introduced by
$hash is of type string, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
309
        }
310
        return $return;
311
    }
312
313
    /**
314
     * 
315
     * @global type $smarty
316
     * @param type $idCarrier
317
     * @param type $sCepDestino
318
     * @return type
319
     */
320
    public function getPrazoDeEntrega($idCarrier, $sCepDestino) {
321
        global $smarty;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
322
        $Carrier = new Carrier($idCarrier);
0 ignored issues
show
Unused Code introduced by
The call to Carrier::__construct() has too many arguments starting with $idCarrier.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
323
324
        $params = array(
325
            "sCepOrigem" => str_pad(Configuration::get('PS_CORREIOS_CEP_ORIG'), 8, "0", STR_PAD_LEFT),
326
            "nCdServico" => Configuration::get("PS_CORREIOS_CARRIER_{$idCarrier}"),
327
            "sCepDestino" => $sCepDestino,
328
        );
329
330
        $this->_factory = Configuration::get("PS_CORREIOS_FACTORY");
331
        $method = "getPrazo" . ucfirst(strtolower($this->_factory));
332
        $dias = $this->$method($params);
333
334
        $smarty->assign(array(
335
            "nomeServico" => $Carrier->name,
0 ignored issues
show
Bug introduced by
The property name does not seem to exist in Carrier.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
336
            "dias" => $dias
337
        ));
338
339
        return $this->display(__file__, 'prazo_de_entrega.tpl');
0 ignored issues
show
Bug introduced by
The method display() does not exist on correios. Did you maybe mean displayForm()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
340
    }
341
342
    private function getPrazoSoapclient($params) {
343
        try {
344
            $client = new SoapClient($this->_urlWebservice);
345
            $result = $client->CalcPrazo($params);
346
            if (intval($result->CalcPrazoResult->Servicos->cServico->Erro) !== 0)
347
                return false;
348
            else
349
                return (integer) $result->CalcPrazoResult->Servicos->cServico->PrazoEntrega;
350
        } catch (Exception $e) {
351
            return false;
352
        }
353
    }
354
355
    private function getPrazoNusoap($params) {
356
        require_once('vendor/lib/nusoap.php');
357
        $nusoap = new nusoap_client($this->_urlWebservice, 'wsdl');
358
        $nusoap->setUseCURL(true);
359
        $result = $nusoap->call("CalcPrazo", $params);
360
        if (intval($result['CalcPrazoResult']['Servicos']['cServico']['Erro']) !== 0) {
361
            return false;
362
        } else {
363
            return (integer) str_replace(",", ".", $result['CalcPrazoResult']['Servicos']['cServico']['PrazoEntrega']);
364
        }
365
    }
366
367
    /**
368
     * 
369
     * @param type $name
370
     * @param type $value
371
     */
372
    private function setCache($name, $value) {
373
        if (_PS_CACHE_ENABLED_)
374
            Cache::getInstance()->setQuery($name, $value);
375
    }
376
377
    /**
378
     * 
379
     * @param type $name
380
     * @return boolean
381
     */
382
    private function getCache($name) {
383
        if (_PS_CACHE_ENABLED_)
384
            return Cache::getInstance()->get(md5($name));
385
        return false;
386
    }
387
388
    /**
389
     * 
390
     * @param type $params
391
     * @param type $hash
392
     * @return boolean
393
     */
394
    private function getPrecoSoapclient($params, $hash) {
395
        try {
396
            $client = new SoapClient($this->_urlWebservice);
397
        } catch (Exception $e) {
398
            return false;
399
        }
400
        $result = $client->CalcPreco($params);
401
        var_dump ($result);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($result); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
402
        if (intval($result->CalcPrecoResult->Servicos->cServico->Erro) !== 0) {
403
            $this->setCache($hash, false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
404
            return false;
405
        } else {
406
            return (float) str_replace(",", ".", $result->CalcPrecoResult->Servicos->cServico->Valor);
407
        }
408
    }
409
410
    /**
411
     * 
412
     * @param type $params
413
     * @param type $hash
414
     * @return boolean
415
     */
416
    private function getPrecoNusoap($params, $hash) {
417
        require_once('vendor/lib/nusoap.php');
418
        $nusoap = new nusoap_client($this->_urlWebservice, 'wsdl');
419
        $nusoap->setUseCURL(true);
420
        $result = $nusoap->call("CalcPreco", $params);
421
        if (intval($result['CalcPrecoResult']['Servicos']['cServico']['Erro']) !== 0) {
422
            $this->setCache($hash, false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a object<type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
423
            return false;
424
        } else {
425
            return (float) str_replace(",", ".", $result['CalcPrecoResult']['Servicos']['cServico']['Valor']);
426
        }
427
    }
428
429
}
430
431
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
432