| Conditions | 11 |
| Paths | 9 |
| Total Lines | 75 |
| Code Lines | 44 |
| 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 |
||
| 65 | public function selectSite( |
||
| 66 | string $type, |
||
| 67 | ?string $country, |
||
| 68 | ?int $accountFlag |
||
| 69 | ): StoreSiteSelectorChoice |
||
| 70 | { |
||
| 71 | $appTouchSite = $accountFlag === self::ACCOUNT_FLAG; |
||
| 72 | |||
| 73 | if ($type === Validator::TYPE_ORDER && $appTouchSite) { |
||
| 74 | if (isset($this->appTouchOrderSiteMapping[$country])) { |
||
| 75 | return new StoreSiteSelectorChoice( |
||
| 76 | $country, |
||
|
|
|||
| 77 | $this->subscriptionSiteMapping[$country], |
||
| 78 | $appTouchSite |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | return new StoreSiteSelectorChoice( |
||
| 83 | self::GERMANY, |
||
| 84 | $this->appTouchOrderSiteMapping[self::GERMANY], |
||
| 85 | $appTouchSite |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($type === Validator::TYPE_ORDER) { |
||
| 90 | if (isset($this->orderSiteMapping[$country])) { |
||
| 91 | return new StoreSiteSelectorChoice( |
||
| 92 | $country, |
||
| 93 | $this->orderSiteMapping[$country], |
||
| 94 | $appTouchSite |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 98 | return new StoreSiteSelectorChoice( |
||
| 99 | $this->defaultOrderCountry, |
||
| 100 | $this->orderSiteMapping[$this->defaultOrderCountry], |
||
| 101 | $appTouchSite |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($type === Validator::TYPE_SUBSCRIPTION && $appTouchSite) { |
||
| 106 | if (isset($this->appTouchSubscriptionSiteMapping[$country])) { |
||
| 107 | return new StoreSiteSelectorChoice( |
||
| 108 | $country, |
||
| 109 | $this->subscriptionSiteMapping[$country], |
||
| 110 | $appTouchSite |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | return new StoreSiteSelectorChoice( |
||
| 115 | self::GERMANY, |
||
| 116 | $this->appTouchSubscriptionSiteMapping[self::GERMANY], |
||
| 117 | $appTouchSite |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($type === Validator::TYPE_SUBSCRIPTION) { |
||
| 122 | if (isset($this->subscriptionSiteMapping[$country])) { |
||
| 123 | return new StoreSiteSelectorChoice( |
||
| 124 | $country, |
||
| 125 | $this->subscriptionSiteMapping[$country], |
||
| 126 | $appTouchSite |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | return new StoreSiteSelectorChoice( |
||
| 131 | $this->defaultSubscriptionCountry, |
||
| 132 | $this->subscriptionSiteMapping[$this->defaultSubscriptionCountry], |
||
| 133 | $appTouchSite |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | |||
| 137 | throw new \RuntimeException(\sprintf( |
||
| 138 | 'Can not select site using (%s)', |
||
| 139 | \json_encode(['type' => $type, 'country' => $country, 'accountFlag' => $accountFlag]) |
||
| 140 | )); |
||
| 144 |