Conditions | 3 |
Paths | 3 |
Total Lines | 63 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
21 | public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) |
||
22 | { |
||
23 | if(version_compare($context->getVersion(), '1.1.0') < 0) { |
||
24 | $tableName = $setup->getTable('stockbase_product_images'); |
||
25 | if (!$setup->getConnection()->isTableExists($tableName)) { |
||
26 | $table = $setup->getConnection() |
||
27 | ->newTable($tableName) |
||
28 | ->setComment('Stockbase product images') |
||
29 | ->addColumn( |
||
30 | 'id', |
||
31 | Table::TYPE_BIGINT, |
||
32 | null, |
||
33 | ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], |
||
34 | 'Image ID' |
||
35 | ) |
||
36 | ->addColumn( |
||
37 | 'ean', |
||
38 | Table::TYPE_BIGINT, |
||
39 | null, |
||
40 | ['identity' => false, 'unsigned' => true, 'nullable' => false], |
||
41 | 'International/European Article Number' |
||
42 | ) |
||
43 | ->addColumn( |
||
44 | 'product_id', |
||
45 | Table::TYPE_BIGINT, |
||
46 | null, |
||
47 | ['identity' => false, 'unsigned' => true, 'nullable' => false], |
||
48 | 'Magento Product ID' |
||
49 | ) |
||
50 | ->addColumn( |
||
51 | 'image', |
||
52 | Table::TYPE_TEXT, |
||
53 | null, |
||
54 | ['nullable' => false], |
||
55 | 'Image' |
||
56 | ) |
||
57 | ->addColumn( |
||
58 | 'timestamp', |
||
59 | Table::TYPE_DATETIME, |
||
60 | null, |
||
61 | ['nullable' => false], |
||
62 | 'Latest Sync' |
||
63 | ) |
||
64 | ->addIndex( |
||
65 | $setup->getIdxName($tableName, ['product_id']), |
||
66 | ['product_id'], |
||
67 | ['type' => AdapterInterface::INDEX_TYPE_INDEX] |
||
68 | ) |
||
69 | ->addIndex( |
||
70 | $setup->getIdxName($tableName, ['ean']), |
||
71 | ['ean'], |
||
72 | ['type' => AdapterInterface::INDEX_TYPE_INDEX] |
||
73 | ) |
||
74 | ->addIndex( |
||
75 | $setup->getIdxName($tableName, ['timestamp']), |
||
76 | ['timestamp'], |
||
77 | ['type' => AdapterInterface::INDEX_TYPE_INDEX] |
||
78 | ); |
||
79 | $setup->getConnection()->createTable($table); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | } |
||
84 | |||
86 |