Conditions | 7 |
Paths | 13 |
Total Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
73 | protected function process() |
||
74 | { |
||
75 | |||
76 | // load the parent/child SKUs |
||
77 | $parentSku = $this->getValue(ColumnKeys::VARIANT_PARENT_SKU); |
||
78 | $childSku = $this->getValue(ColumnKeys::VARIANT_CHILD_SKU); |
||
79 | |||
80 | // query whether or not the super link has already been processed |
||
81 | if ($this->hasBeenProcessedRelation($parentSku, $childSku, RelationTypes::VARIANT_SUPER_LINK)) { |
||
82 | return; |
||
83 | } |
||
84 | |||
85 | try { |
||
86 | // try to load and map the parent ID |
||
87 | $this->parentId = $this->mapSku($parentSku); |
||
|
|||
88 | } catch (\Exception $e) { |
||
89 | throw $this->wrapException(array(ColumnKeys::VARIANT_PARENT_SKU), $e); |
||
90 | } |
||
91 | |||
92 | try { |
||
93 | // try to load and map the child ID |
||
94 | $this->childId = $this->mapChildSku($childSku); |
||
95 | } catch (\Exception $e) { |
||
96 | throw $this->wrapException(array(ColumnKeys::VARIANT_CHILD_SKU), $e); |
||
97 | } |
||
98 | |||
99 | try { |
||
100 | // prepare and persist the product super link |
||
101 | if ($productSuperLink = $this->initializeProductSuperLink($this->prepareProductSuperLinkAttributes())) { |
||
102 | $this->persistProductSuperLink($productSuperLink); |
||
103 | } |
||
104 | |||
105 | // mark the super link as processed |
||
106 | $this->addProcessedRelation($parentSku, $childSku, RelationTypes::VARIANT_SUPER_LINK); |
||
107 | } catch (\Exception $e) { |
||
108 | // prepare a more detailed error message |
||
109 | $message = $this->appendExceptionSuffix( |
||
110 | sprintf( |
||
111 | 'Super link with SKUs %s => %s can\'t be created', |
||
112 | $parentSku, |
||
113 | $childSku |
||
114 | ) |
||
115 | ); |
||
116 | |||
117 | // if we're NOT in debug mode, re-throw a more detailed exception |
||
118 | $wrappedException = $this->wrapException( |
||
119 | array(ColumnKeys::VARIANT_PARENT_SKU, ColumnKeys::VARIANT_CHILD_SKU), |
||
120 | new \Exception($message, null, $e) |
||
121 | ); |
||
122 | |||
123 | // query whether or not, debug mode is enabled |
||
124 | if ($this->isDebugMode()) { |
||
125 | // log a warning and return immediately |
||
126 | $this->getSystemLogger()->warning($wrappedException->getMessage()); |
||
127 | return; |
||
128 | } |
||
129 | |||
130 | // else, throw the exception |
||
131 | throw $wrappedException; |
||
132 | } |
||
133 | } |
||
134 | |||
202 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: