correios::getPrazoSoapclient()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 5
nop 1
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
ccs 0
cts 8
cp 0
crap 12
1
0 ignored issues
show
Security Bug introduced by
It is not recommended to output anything before PHP's opening tag in non-template files.
Loading history...
2
<?php
3
4
/** MODULO ADAPTADO POR ODLANIER
5
 * @author Odlanier de Souza Mendes
6
 * @copyright Dlani
7
 * @email [email protected]
8
 * @version 3.0
9
 * */
10
if (!defined('_PS_VERSION_'))
11
    exit;
12
13
class correios extends CarrierModule {
14
15
    public $id_carrier;
16
    private $_urlWebservice = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?wsdl";
17
    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...
18
    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...
19
    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...
20
        "soapclient" => "SOAP Client",
21
        "nusoap" => "NuSoap"
22
    );
23
    private $_factory = "soapclient";
24
    public $servicos_todos = array(
25
        '04510' => 'PAC',# era '41106' => 'PAC',
26
        '04014' => 'SEDEX', # era '40010' => 'SEDEX',
27
        '40215' => 'SEDEX 10',
28
        '40290' => 'SEDEX HOJE',
29
            //'81019' => 'E-SEDEX', 
30
            //'44105' => 'MALOTE',
31
            //'41017' => 'NORMAL', 
32
            //'40045' => 'SEDEX A COBRAR', 
33
    );
34
    private $_moduleName = 'correios';
35
36 6
    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...
37 6
        $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...
38 6
        $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...
39 6
        $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...
40 6
        $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...
41 6
        $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...
42
43 6
        parent::__construct();
44
45
        /* The parent construct is required for translations */
46 6
        $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...
47 6
        $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...
48 6
        $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...
49 6
    }
50
51
    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...
52
        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...
53
                $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...
54
                $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...
55
                $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...
56
            return false;
57
58
        $this->installCarriers();
59
60
        return true;
61
    }
62
63
    /**
64
     * 
65
     */
66
    private function installCarriers() {
67
        $configBase = array(
68
            'id_tax_rules_group' => 0,
69
            'active' => true,
70
            'deleted' => 0,
71
            'shipping_handling' => false,
72
            'range_behavior' => 0,
73
            'delay' => array("br" => "Entrega pelos Correios."),
74
            'id_zone' => 1,
75
            'is_module' => true,
76
            'shipping_external' => true,
77
            'external_module_name' => $this->_moduleName,
78
            'need_range' => true,
79
            'url' => Tools::getHttpHost(true) . "/modules/correios/rastreio.php?objeto=@",
80
        );
81
82
        $arrayConfigs = array();
83
        foreach ($this->servicos_todos as $codServico => $servico)
84
            $arrayConfigs[] = array(
85
                "name" => "Correios - $servico",
86
                "cod_servico" => $codServico
87
            );
88
89
        foreach ($arrayConfigs as $config) {
90
            $config = array_merge($configBase, $config);
91
            $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...
92
        }
93
    }
94
95
    /**
96
     * 
97
     * @param type $config
98
     * @return boolean
99
     */
100
    public function installExternalCarrier($config) {
101
        $check = Db::getInstance()->executeS("SELECT id_carrier FROM " . _DB_PREFIX_ . "carrier WHERE name = '" . $config['name'] . "' ");
102
        if (is_array($check) && !empty($check))
103
            return Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 0), 'UPDATE', ' name = "' . $config['name'] . '" ');
104
105
        $carrier = new Carrier();
106
        $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...
107
        $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...
108
        $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...
109
        $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...
110
        $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...
111
        $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...
112
        $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...
113
        $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...
114
        $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...
115
        $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...
116
        $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...
117
        $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...
118
        $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...
119
120
        $languages = Language::getLanguages(true);
121
        foreach ($languages as $language) {
122
            $carrier->delay[(int) $language['id_lang']] = $config['delay']['br'];
123
        }
124
125
        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...
126
            $groups = Group::getGroups(true);
127
            foreach ($groups as $group)
128
                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...
129
130
            $rangePrice = new RangePrice();
131
            $rangePrice->id_carrier = $carrier->id;
132
            $rangePrice->delimiter1 = '0';
133
            $rangePrice->delimiter2 = '0';
134
            $rangePrice->add();
135
136
            $rangeWeight = new RangeWeight();
137
            $rangeWeight->id_carrier = $carrier->id;
138
            $rangeWeight->delimiter1 = '0';
139
            $rangeWeight->delimiter2 = '30';
140
            $rangeWeight->add();
141
142
            $zones = Zone::getZones(true);
143
            foreach ($zones as $zone) {
144
                Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) ($carrier->id), 'id_zone' => (int) ($zone['id_zone'])), 'INSERT');
145
                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');
146
                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');
147
            }
148
149
            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...
150
151
            // Copy Logo
152
            if (!copy(dirname(__FILE__) . '/logos/' . $config['cod_servico'] . '.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'))
153
                return false;
154
155
            // Return ID Carrier
156
            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...
157
        }
158
        return false;
159
    }
160
161
    /**
162
     * 
163
     * @return boolean
164
     */
165
    public function uninstall() {
166
        // Uninstall Carriers
167
        $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...
168
169
        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...
170
            return false;
171
172
        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...
173
            return false;
174
175
        return true;
176
    }
177
178
    /**
179
     * 
180
     * @return type
181
     */
182 1
    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...
183 1
        $output = '<h2>' . $this->displayName . '</h2>';
184 1
        if (Tools::isSubmit('submitcarrinho_correios')) {
185
            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...
186
187
            $output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->
188
                            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...
189
        }
190 1
        if (Tools::isSubmit('factory')) {
191
            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...
192
193
            $output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->
194
                            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...
195
        }
196
197 1
        return $output . $this->displayForm();
198
    }
199
200
    /**
201
     * 
202
     * @return type
203
     */
204 1
    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...
205 1
        $conf = Configuration::getMultiple(array('PS_CORREIOS_CEP_ORIG'));
206 1
        $cep_orig = array_key_exists('cep', $_POST) ? $_POST['cep'] : (array_key_exists('PS_CORREIOS_CEP_ORIG', $conf) ? $conf['PS_CORREIOS_CEP_ORIG'] : '');
207 1
        include (dirname(__file__) . "/form_config.php");
208 1
        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...
209
    }
210
211
    /**
212
     * 
213
     * @param type $params
214
     * @param type $shipping_cost
215
     * @return boolean
216
     */
217 4
    public function getOrderShippingCost($params, $shipping_cost) {
218 4
        $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...
219 4
        $chave = Configuration::get("PS_CORREIOS_CARRIER_{$this->id_carrier}");
220 4
        $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...
221
222 4
        $sCepDestino = preg_replace("/([^0-9])/", "", $address->postcode);
223
224
        $paramsCorreios = array(
225 4
            "sCepDestino" => $sCepDestino,
226 4
            "nVlPeso" => (string) $params->getTotalWeight(),
227 4
            "nCdServico" => $chave,
228
        );
229
230 4
        $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 4
        $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...
232
233 4
        if ($custoFrete === false || $custoFrete === 0.0)
234
            return false;
235
236 4
        return $custoFrete + $shipping_cost;
237
    }
238
239
    /**
240
     * 
241
     * @param type $params
242
     * @return type
243
     */
244
    public function getOrderShippingCostExternal($params) {
245
        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...
246
    }
247
248
    /**
249
     * 
250
     * @param type $params
251
     */
252
    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...
253
        
254
    }
255
256
    /**
257
     * 
258
     * @global type $smarty
259
     * @param type $params
260
     * @return type
261
     */
262
    public function hookbeforeCarrier($params) {
263
        global $smarty;
264
        $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...
265
        $smarty->assign(array(
266
            "sCepDestino" => $address->postcode
267
        ));
268
        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...
269
    }
270
271
    /**
272
     * 
273
     * @param type $params
274
     */
275
    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...
276
        
277
    }
278
279
    /**
280
     * 
281
     * @param type $params
282
     * @return type
283
     */
284 4
    private function getPriceWebService($params) {
285
        $paramsBase = array(
286 4
            "nCdEmpresa" => "",
287 4
            "sDsSenha" => "",
288 4
            "sCepOrigem" => str_pad(Configuration::get('PS_CORREIOS_CEP_ORIG'), 8, "0", STR_PAD_LEFT),
289 4
            "nCdFormato" => "1",
290 4
            "nVlComprimento" => "30",
291 4
            "nVlAltura" => "8",
292 4
            "nVlLargura" => "30",
293 4
            "nVlDiametro" => "0",
294 4
            "sCdMaoPropria" => "N",
295 4
            "nVlValorDeclarado" => "0",
296 4
            "sCdAvisoRecebimento" => "N"
297
        );
298 4
        $params = array_merge($paramsBase, $params);
299 4
        $hash = ( implode("|", $params) );
300 4
        $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...
301
302 4
        if ($getInCache) {
303
            $return = $getInCache;
304
        } else {
305 4
            $this->_factory = Configuration::get("PS_CORREIOS_FACTORY");
306 4
            $method = "getPreco" . ucfirst(strtolower($this->_factory));
307
            
308 4
            $return = $this->$method($params, $hash);
309 4
            $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...
310
        }
311 4
        return $return;
312
    }
313
314
    /**
315
     * 
316
     * @global type $smarty
317
     * @param type $idCarrier
318
     * @param type $sCepDestino
319
     * @return type
320
     */
321
    public function getPrazoDeEntrega($idCarrier, $sCepDestino) {
322
        global $smarty;
323
        $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...
324
325
        $params = array(
326
            "sCepOrigem" => str_pad(Configuration::get('PS_CORREIOS_CEP_ORIG'), 8, "0", STR_PAD_LEFT),
327
            "nCdServico" => Configuration::get("PS_CORREIOS_CARRIER_{$idCarrier}"),
328
            "sCepDestino" => $sCepDestino,
329
        );
330
331
        $this->_factory = Configuration::get("PS_CORREIOS_FACTORY");
332
        $method = "getPrazo" . ucfirst(strtolower($this->_factory));
333
        $dias = $this->$method($params);
334
335
        $smarty->assign(array(
336
            "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...
337
            "dias" => $dias
338
        ));
339
340
        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...
341
    }
342
343
    private function getPrazoSoapclient($params) {
344
        try {
345
            $client = new SoapClient($this->_urlWebservice);
346
            $result = $client->CalcPrazo($params);
347
            if (intval($result->CalcPrazoResult->Servicos->cServico->Erro) !== 0)
348
                return false;
349
            else
350
                return (integer) $result->CalcPrazoResult->Servicos->cServico->PrazoEntrega;
351
        } catch (Exception $e) {
352
            return false;
353
        }
354
    }
355
356
    private function getPrazoNusoap($params) {
357
        require_once('vendor/lib/nusoap.php');
358
        $nusoap = new nusoap_client($this->_urlWebservice, 'wsdl');
359
        $nusoap->setUseCURL(true);
360
        $result = $nusoap->call("CalcPrazo", $params);
361
        if (intval($result['CalcPrazoResult']['Servicos']['cServico']['Erro']) !== 0) {
362
            return false;
363
        } else {
364
            return (integer) str_replace(",", ".", $result['CalcPrazoResult']['Servicos']['cServico']['PrazoEntrega']);
365
        }
366
    }
367
368
    /**
369
     * 
370
     * @param type $name
371
     * @param type $value
372
     */
373 4
    private function setCache($name, $value) {
374 4
        if (_PS_CACHE_ENABLED_)
375
            Cache::getInstance()->setQuery($name, $value);
376 4
    }
377
378
    /**
379
     * 
380
     * @param type $name
381
     * @return boolean
382
     */
383 4
    private function getCache($name) {
384 4
        if (_PS_CACHE_ENABLED_)
385
            return Cache::getInstance()->get(md5($name));
386 4
        return false;
387
    }
388
389
    /**
390
     * 
391
     * @param type $params
392
     * @param type $hash
393
     * @return boolean
394
     */
395 4
    private function getPrecoSoapclient($params, $hash) {
396
        try {
397 4
            $client = new SoapClient($this->_urlWebservice);
398
        } catch (Exception $e) {
399
            return false;
400
        }
401 4
        $result = $client->CalcPreco($params);
402
        # var_dump ($result);
403 4
        if (intval($result->CalcPrecoResult->Servicos->cServico->Erro) !== 0) {
404
            $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...
405
            return false;
406
        } else {
407 4
            return (float) str_replace(",", ".", $result->CalcPrecoResult->Servicos->cServico->Valor);
408
        }
409
    }
410
411
    /**
412
     * 
413
     * @param type $params
414
     * @param type $hash
415
     * @return boolean
416
     */
417
    private function getPrecoNusoap($params, $hash) {
418
        require_once('vendor/lib/nusoap.php');
419
        $nusoap = new nusoap_client($this->_urlWebservice, 'wsdl');
420
        $nusoap->setUseCURL(true);
421
        $result = $nusoap->call("CalcPreco", $params);
422
        if (intval($result['CalcPrecoResult']['Servicos']['cServico']['Erro']) !== 0) {
423
            $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...
424
            return false;
425
        } else {
426
            return (float) str_replace(",", ".", $result['CalcPrecoResult']['Servicos']['cServico']['Valor']);
427
        }
428
    }
429
430
}
431
432
?>
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...