| Conditions | 25 |
| Paths | 12288 |
| Total Lines | 74 |
| Code Lines | 51 |
| 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 |
||
| 56 | public static function fromArray(array $config): self |
||
| 57 | { |
||
| 58 | $alipay = null; |
||
| 59 | if (isset($config['alipay']['default'])) { |
||
| 60 | $alipay = AlipayConfig::fromArray($config['alipay']['default']); |
||
| 61 | } elseif (isset($config['alipay']) && !isset($config['alipay']['default'])) { |
||
| 62 | // Handle case where alipay config might be provided directly |
||
| 63 | $firstKey = array_key_first($config['alipay']); |
||
| 64 | if (is_array($config['alipay'][$firstKey])) { |
||
| 65 | $alipay = AlipayConfig::fromArray($config['alipay'][$firstKey]); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | $wechat = null; |
||
| 70 | if (isset($config['wechat']['default'])) { |
||
| 71 | $wechat = WechatConfig::fromArray($config['wechat']['default']); |
||
| 72 | } elseif (isset($config['wechat']) && !isset($config['wechat']['default'])) { |
||
| 73 | $firstKey = array_key_first($config['wechat']); |
||
| 74 | if (is_array($config['wechat'][$firstKey])) { |
||
| 75 | $wechat = WechatConfig::fromArray($config['wechat'][$firstKey]); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | $unipay = null; |
||
| 80 | if (isset($config['unipay']['default'])) { |
||
| 81 | $unipay = UnipayConfig::fromArray($config['unipay']['default']); |
||
| 82 | } elseif (isset($config['unipay']) && !isset($config['unipay']['default'])) { |
||
| 83 | $firstKey = array_key_first($config['unipay']); |
||
| 84 | if (is_array($config['unipay'][$firstKey])) { |
||
| 85 | $unipay = UnipayConfig::fromArray($config['unipay'][$firstKey]); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $douyin = null; |
||
| 90 | if (isset($config['douyin']['default'])) { |
||
| 91 | $douyin = DouyinConfig::fromArray($config['douyin']['default']); |
||
| 92 | } elseif (isset($config['douyin']) && !isset($config['douyin']['default'])) { |
||
| 93 | $firstKey = array_key_first($config['douyin']); |
||
| 94 | if (is_array($config['douyin'][$firstKey])) { |
||
| 95 | $douyin = DouyinConfig::fromArray($config['douyin'][$firstKey]); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | $jsb = null; |
||
| 100 | if (isset($config['jsb']['default'])) { |
||
| 101 | $jsb = JsbConfig::fromArray($config['jsb']['default']); |
||
| 102 | } elseif (isset($config['jsb']) && !isset($config['jsb']['default'])) { |
||
| 103 | $firstKey = array_key_first($config['jsb']); |
||
| 104 | if (is_array($config['jsb'][$firstKey])) { |
||
| 105 | $jsb = JsbConfig::fromArray($config['jsb'][$firstKey]); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | $logger = isset($config['logger']) ? LoggerConfig::fromArray($config['logger']) : null; |
||
| 110 | $http = isset($config['http']) ? HttpConfig::fromArray($config['http']) : null; |
||
| 111 | |||
| 112 | // Store additional config that doesn't match known structures |
||
| 113 | $additional = []; |
||
| 114 | $knownKeys = ['alipay', 'wechat', 'unipay', 'douyin', 'jsb', 'logger', 'http']; |
||
| 115 | foreach ($config as $key => $value) { |
||
| 116 | if (!in_array($key, $knownKeys)) { |
||
| 117 | $additional[$key] = $value; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return new self( |
||
| 122 | alipay: $alipay, |
||
| 123 | wechat: $wechat, |
||
| 124 | unipay: $unipay, |
||
| 125 | douyin: $douyin, |
||
| 126 | jsb: $jsb, |
||
| 127 | logger: $logger, |
||
| 128 | http: $http, |
||
| 129 | additional: $additional, |
||
| 130 | ); |
||
| 133 |