Passed
Pull Request — master (#192)
by Florian
02:05
created

UpgradeSchema::upgrade()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 74
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 49
nc 16
nop 2
dl 0
loc 74
rs 8.8016
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Setup;
28
29
use Magento\Framework\DB\Ddl\Table;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\DB\Ddl\Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Magento\Framework\Setup\ModuleContextInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Setup\ModuleContextInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Magento\Framework\Setup\SchemaSetupInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Setup\SchemaSetupInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Magento\Framework\Setup\UpgradeSchemaInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Setup\UpgradeSchemaInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Payone\Core\Setup\Tables\Api;
34
use Payone\Core\Setup\Tables\PaymentBan;
35
use Payone\Core\Setup\Tables\Transactionstatus;
36
37
/**
38
 * Magento script for updating the database after the initial installation
39
 */
40
class UpgradeSchema extends BaseSchema implements UpgradeSchemaInterface
41
{
42
    /**
43
     * Upgrade method
44
     *
45
     * @param  SchemaSetupInterface $setup
46
     * @param  ModuleContextInterface $context
47
     * @return void
48
     */
49
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
50
    {
51
        if (version_compare($context->getVersion(), '1.3.0', '<')) {// pre update version is lower than 1.3.0
52
            $this->addTable($setup, \Payone\Core\Setup\Tables\CheckedAddresses::getData());
53
54
            $setup->getConnection('checkout')->addColumn(
55
                $setup->getTable('quote_address'),
56
                'payone_addresscheck_score',
57
                [
58
                    'type' => Table::TYPE_TEXT,
59
                    'length' => 1,
60
                    'nullable' => false,
61
                    'default' => '',
62
                    'comment' => 'AddressCheck Person Status Score (G, Y, R)'
63
                ]
64
            );
65
            $setup->getConnection('checkout')->addColumn(
66
                $setup->getTable('quote_address'),
67
                'payone_protect_score',
68
                [
69
                    'type' => Table::TYPE_TEXT,
70
                    'length' => 1,
71
                    'nullable' => false,
72
                    'default' => '',
73
                    'comment' => 'Consumerscore Status Score (G, Y, R)'
74
                ]
75
            );
76
        }
77
        if (!$setup->getConnection()->isTableExists($setup->getTable(PaymentBan::TABLE_PAYMENT_BAN))) {
78
            $this->addTable($setup, PaymentBan::getData());
79
        }
80
        if (version_compare($context->getVersion(), '2.3.0', '<=')) {
81
            $setup->getConnection()->modifyColumn(
82
                $setup->getTable('payone_protocol_api'),
83
                'mid', ['type' => Table::TYPE_INTEGER, 'default' => '0']
84
            );
85
            $setup->getConnection()->modifyColumn(
86
                $setup->getTable('payone_protocol_api'),
87
                'aid', ['type' => Table::TYPE_INTEGER, 'default' => '0']
88
            );
89
            $setup->getConnection()->modifyColumn(
90
                $setup->getTable('payone_protocol_api'),
91
                'portalid', ['type' => Table::TYPE_INTEGER, 'default' => '0']
92
            );
93
        }
94
95
        /*
96
         * add index to payone_protocol_api::txid to speed up transaction status calls
97
         */
98
        if (version_compare($context->getVersion(), '2.3.1', '<=')) {
99
100
            $connection = $setup->getConnection();
101
            $protocolApiTable = $connection->getTableName(Api::TABLE_PROTOCOL_API);
102
            $indexField = 'txid';
103
104
            $connection->addIndex(
105
                $protocolApiTable,
106
                $connection->getIndexName($protocolApiTable, $indexField),
107
                $indexField
108
            );
109
110
            $transactionStatusTable = $connection->getTableName(Transactionstatus::TABLE_PROTOCOL_TRANSACTIONSTATUS);
111
            $indexFieldTxid = 'txid';
112
            $indexFieldCustomerid = 'customerid';
113
114
            $connection->addIndex(
115
                $transactionStatusTable,
116
                $connection->getIndexName($transactionStatusTable, $indexFieldTxid),
117
                $indexFieldTxid
118
            );
119
            $connection->addIndex(
120
                $transactionStatusTable,
121
                $connection->getIndexName($transactionStatusTable, $indexFieldCustomerid),
122
                $indexFieldCustomerid
123
            );
124
        }
125
    }
126
}
127