| Conditions | 1 |
| Paths | 1 |
| Total Lines | 116 |
| Code Lines | 111 |
| 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 |
||
| 13 | public function testRearrangeArray() |
||
| 14 | { |
||
| 15 | $oldJson = <<<'JSON' |
||
| 16 | [ |
||
| 17 | { |
||
| 18 | "name": "warehouse_code", |
||
| 19 | "in": "query", |
||
| 20 | "type": "string", |
||
| 21 | "required": false |
||
| 22 | }, |
||
| 23 | { |
||
| 24 | "name": "simple_skus", |
||
| 25 | "in": "query", |
||
| 26 | "type": "array", |
||
| 27 | "items": { |
||
| 28 | "type": "string" |
||
| 29 | }, |
||
| 30 | "collectionFormat": "multi", |
||
| 31 | "required": true |
||
| 32 | }, |
||
| 33 | { |
||
| 34 | "name": "seller_id", |
||
| 35 | "in": "query", |
||
| 36 | "type": "integer", |
||
| 37 | "format": "int64", |
||
| 38 | "required": false |
||
| 39 | }, |
||
| 40 | { |
||
| 41 | "name": "oms_code", |
||
| 42 | "in": "query", |
||
| 43 | "type": "string", |
||
| 44 | "required": false |
||
| 45 | } |
||
| 46 | ] |
||
| 47 | JSON; |
||
| 48 | |||
| 49 | $newJson = <<<'JSON' |
||
| 50 | [ |
||
| 51 | { |
||
| 52 | "name": "warehouse_code", |
||
| 53 | "in": "query", |
||
| 54 | "type": "string64", |
||
| 55 | "x-go-name": "WarehouseCode", |
||
| 56 | "x-go-type": "string" |
||
| 57 | }, |
||
| 58 | { |
||
| 59 | "name": "oms_code", |
||
| 60 | "in": "query", |
||
| 61 | "type": "string", |
||
| 62 | "x-go-name": "OmsCode", |
||
| 63 | "x-go-type": "string" |
||
| 64 | }, |
||
| 65 | { |
||
| 66 | "name": "simple_skus", |
||
| 67 | "in": "query", |
||
| 68 | "type": "array", |
||
| 69 | "required": true, |
||
| 70 | "items": { |
||
| 71 | "type": "string" |
||
| 72 | }, |
||
| 73 | "collectionFormat": "multi", |
||
| 74 | "x-go-name": "SimpleSKUs", |
||
| 75 | "x-go-type": "[]string" |
||
| 76 | }, |
||
| 77 | { |
||
| 78 | "name": "seller_id", |
||
| 79 | "in": "query", |
||
| 80 | "type": "integer", |
||
| 81 | "format": "int64", |
||
| 82 | "x-go-name": "SellerID", |
||
| 83 | "x-go-type": "uint64" |
||
| 84 | } |
||
| 85 | ] |
||
| 86 | JSON; |
||
| 87 | |||
| 88 | $expectedJson = <<<'JSON' |
||
| 89 | [ |
||
| 90 | { |
||
| 91 | "name": "warehouse_code", |
||
| 92 | "in": "query", |
||
| 93 | "type": "string64", |
||
| 94 | "x-go-name": "WarehouseCode", |
||
| 95 | "x-go-type": "string" |
||
| 96 | }, |
||
| 97 | { |
||
| 98 | "name": "simple_skus", |
||
| 99 | "in": "query", |
||
| 100 | "type": "array", |
||
| 101 | "items": { |
||
| 102 | "type": "string" |
||
| 103 | }, |
||
| 104 | "collectionFormat": "multi", |
||
| 105 | "required": true, |
||
| 106 | "x-go-name": "SimpleSKUs", |
||
| 107 | "x-go-type": "[]string" |
||
| 108 | }, |
||
| 109 | { |
||
| 110 | "name": "seller_id", |
||
| 111 | "in": "query", |
||
| 112 | "type": "integer", |
||
| 113 | "format": "int64", |
||
| 114 | "x-go-name": "SellerID", |
||
| 115 | "x-go-type": "uint64" |
||
| 116 | }, |
||
| 117 | { |
||
| 118 | "name": "oms_code", |
||
| 119 | "in": "query", |
||
| 120 | "type": "string", |
||
| 121 | "x-go-name": "OmsCode", |
||
| 122 | "x-go-type": "string" |
||
| 123 | } |
||
| 124 | ] |
||
| 125 | JSON; |
||
| 126 | |||
| 127 | $m = new JsonDiff(json_decode($oldJson), json_decode($newJson), JsonDiff::REARRANGE_ARRAYS); |
||
| 128 | $this->assertSame($expectedJson, json_encode($m->getRearranged(), JSON_PRETTY_PRINT)); |
||
| 129 | } |
||
| 388 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.