| Conditions | 11 |
| Paths | 40 |
| Total Lines | 69 |
| Code Lines | 57 |
| 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 |
||
| 103 | public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset |
||
| 104 | { |
||
| 105 | if (!isIntegerPositive($items_per_page)){ |
||
| 106 | $items_per_page=10; |
||
| 107 | } |
||
| 108 | $result=DealsResultset::createInstance(); |
||
| 109 | if (!$this->checkLogin()) { |
||
| 110 | return $result; |
||
| 111 | } |
||
| 112 | $arrResult = array(); |
||
| 113 | $jsonVouchers = file_get_contents("https://api.tradedoubler.com/1.0/vouchers.json;dateOutputFormat=iso8601?token=".$_ENV['TRADEDOUBLER_TOKEN']); |
||
| 114 | $arrVouchers = json_decode($jsonVouchers, true); |
||
| 115 | |||
| 116 | foreach($arrVouchers as $voucher) { |
||
| 117 | $Deal = Deal::createInstance(); |
||
| 118 | $Deal->setValues($voucher, [ |
||
| 119 | 'id' => 'deal_ID' , |
||
| 120 | 'programId' => 'merchant_ID' , |
||
| 121 | 'code' => 'code' , |
||
| 122 | 'updateDate' => 'update_date' , |
||
| 123 | 'publishStartDate' => 'publish_start_date' , |
||
| 124 | 'publishEndDate' => 'publish_end_date' , |
||
| 125 | 'startDate' => 'start_date' , |
||
| 126 | 'endDate' => 'end_date' , |
||
| 127 | 'title' => 'name' , |
||
| 128 | 'shortDescription' => 'short_description' , |
||
| 129 | 'description' => 'description' , |
||
| 130 | 'voucherTypeId' => 'deal_type' , |
||
| 131 | 'defaultTrackUri' => 'default_track_uri' , |
||
| 132 | 'landingUrl' => 'landing_url' , |
||
| 133 | 'discountAmount' => 'discount_amount' , |
||
| 134 | 'isPercentage' => 'is_percentage' , |
||
| 135 | 'publisherInformation' => 'information' , |
||
| 136 | 'languageId' => 'language' , |
||
| 137 | 'exclusive' => 'is_exclusive' , |
||
| 138 | 'siteSpecific' => 'is_site_specific' , |
||
| 139 | 'currencyId' => 'currency_initial' , |
||
| 140 | 'logoPath' => 'logo_path' , |
||
| 141 | ]); |
||
| 142 | switch ($voucher['voucherTypeId']) { |
||
| 143 | case 1: |
||
| 144 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
||
| 145 | break; |
||
| 146 | case 2: |
||
| 147 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
||
| 148 | break; |
||
| 149 | case 3: |
||
| 150 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_ARTICLE; |
||
| 151 | break; |
||
| 152 | case 4: |
||
| 153 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_SHIPPING; |
||
| 154 | break; |
||
| 155 | case 5: |
||
| 156 | $Deal->deal_type = \Oara\Utilities::OFFER_TYPE_LOTTERY; |
||
| 157 | break; |
||
| 158 | } |
||
| 159 | |||
| 160 | if($merchantID > 0) { |
||
| 161 | if($voucher['programId'] == $merchantID) { |
||
| 162 | $arrResult[] = $Deal; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | else { |
||
| 166 | $arrResult[] = $Deal; |
||
| 167 | } |
||
| 168 | } |
||
| 169 | $result->deals[]=$arrResult; |
||
| 170 | return $result; |
||
| 171 | } |
||
| 172 | |||
| 237 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.