Install_Helper_OnlinePayment   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 17.39 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 8
loc 46
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setProvider() 0 8 1
A createAndAttachToOrder() 4 9 2
A createInEurAndAttachToInvoice() 4 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
class Install_Helper_OnlinePayment {
3
    
4
    private $kernel;
5
    private $db;
6
7
    public function __construct($kernel, $db) {
8
        $this->kernel = $kernel;
9
        $this->db = $db;
10
    }
11
    
12
    public function setProvider() 
13
    {
14
        require_once 'Intraface/modules/onlinepayment/OnlinePayment.php';
15
        $onlinepayment = new OnlinePayment($this->kernel);
16
        $onlinepayment->setProvider(array('provider_key' => 2));
17
        $onlinepayment = OnlinePayment::factory($this->kernel);
18
        $onlinepayment->setSettings(array('merchant_id' => '12345678', 'md5_secret' => 'qqqaaasss'));
0 ignored issues
show
Unused Code introduced by
The call to OnlinePaymentDefault::setSettings() has too many arguments starting with array('merchant_id' => '...secret' => 'qqqaaasss').

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...
19
    }
20
    
21
    
22
    public function createAndAttachToOrder() {
23
        
24
        require_once 'Intraface/modules/onlinepayment/OnlinePayment.php';
25
        $onlinepayment = new OnlinePayment($this->kernel);
26 View Code Duplication
        if (!$onlinepayment->save(array('belong_to' => 'order', 'belong_to_id' => 1, 'transaction_number' => 111, 'transaction_status' => '000', 'amount' => 200))) {
27
            echo $onlinepayment->error->view();
0 ignored issues
show
Bug introduced by
The property error does not seem to exist in OnlinePayment.

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...
28
            die;
0 ignored issues
show
Coding Style Compatibility introduced by
The method createAndAttachToOrder() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
29
        }
30
    }
31
    
32
    public function createInEurAndAttachToInvoice() {
33
        
34
        require_once 'Intraface/modules/currency/Currency/Gateway.php';
35
        $doctrine = Doctrine_Manager::connection(DB_DSN);
36
        $gateway = new Intraface_modules_currency_Currency_Gateway($doctrine);
37
        $currency = $gateway->findByIsoCode('Eur');
38
        
39
        require_once 'Intraface/modules/onlinepayment/OnlinePayment.php';
40
        $onlinepayment = new OnlinePayment($this->kernel);
41 View Code Duplication
        if (!$onlinepayment->save(array('belong_to' => 'invoice', 'belong_to_id' => 1, 'transaction_number' => 111, 'transaction_status' => '000', 'amount' => 100, 'currency' => $currency))) {
42
            echo $onlinepayment->error->view();
0 ignored issues
show
Bug introduced by
The property error does not seem to exist in OnlinePayment.

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...
43
            die;
0 ignored issues
show
Coding Style Compatibility introduced by
The method createInEurAndAttachToInvoice() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
44
        }
45
    }
46
    
47
}
48
?>
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...
49