Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 43 |
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 |
||
68 | public function testValidationOfTradeAssetOwnership() { |
||
69 | $this->draft->draft_id = 1; |
||
70 | |||
71 | $tradeAsset1 = new TradeAsset(); |
||
72 | $tradeAsset1->player = new Pick(); |
||
73 | $tradeAsset1->player->player_id = 1; |
||
74 | $tradeAsset1->player->draft_id = 1; |
||
75 | |||
76 | $tradeAsset2 = new TradeAsset(); |
||
77 | $tradeAsset2->player = new Pick(); |
||
78 | $tradeAsset2->player->player_id = 2; |
||
79 | $tradeAsset2->player->draft_id = 1; |
||
80 | |||
81 | $tradeAsset1->oldmanager_id = 3; |
||
82 | $tradeAsset2->oldmanager_id = 2; |
||
83 | |||
84 | $this->trade->manager1_id = 1; |
||
85 | $this->trade->manager2_id = 2; |
||
86 | |||
87 | $this->trade->trade_assets[] = $tradeAsset1; |
||
88 | $this->trade->trade_assets[] = $tradeAsset2; |
||
89 | |||
90 | $result = $this->sut->IsTradeValid($this->draft, $this->trade); |
||
91 | |||
92 | $this->assertFalse($result->success); |
||
93 | $this->assertContains("Asset #1 does not belong to either manager.", $result->errors); |
||
94 | //Added since the addition of an AND condition instead of OR in the validator: |
||
95 | $this->assertNotContains("Asset #2 does not belong to either manager.", $result->errors); |
||
96 | |||
97 | $tradeAsset1->oldmanager_id = 1; |
||
98 | $tradeAsset2->oldmanager_id = 4; |
||
99 | |||
100 | $this->trade->trade_assets = array(); |
||
101 | $this->trade->trade_assets[] = $tradeAsset1; |
||
102 | $this->trade->trade_assets[] = $tradeAsset2; |
||
103 | |||
104 | $result = $this->sut->IsTradeValid($this->draft, $this->trade); |
||
105 | |||
106 | $this->assertFalse($result->success); |
||
107 | $this->assertContains("Asset #2 does not belong to either manager.", $result->errors); |
||
108 | |||
109 | $tradeAsset1->player->draft_id = 2; |
||
110 | |||
111 | $this->trade->trade_assets = array(); |
||
112 | $this->trade->trade_assets[] = $tradeAsset1; |
||
113 | $this->trade->trade_assets[] = $tradeAsset2; |
||
114 | |||
115 | $result = $this->sut->IsTradeValid($this->draft, $this->trade); |
||
116 | |||
117 | $this->assertFalse($result->success); |
||
118 | $this->assertContains("Asset #1 does not belong to draft #1", $result->errors); |
||
119 | |||
120 | $tradeAsset1->player->draft_id = 1; |
||
121 | $tradeAsset2->player->draft_id = 38; |
||
122 | |||
123 | $this->trade->trade_assets = array(); |
||
124 | $this->trade->trade_assets[] = $tradeAsset1; |
||
125 | $this->trade->trade_assets[] = $tradeAsset2; |
||
126 | |||
127 | $result = $this->sut->IsTradeValid($this->draft, $this->trade); |
||
128 | |||
129 | $this->assertFalse($result->success); |
||
130 | $this->assertContains("Asset #2 does not belong to draft #1", $result->errors); |
||
131 | } |
||
132 | |||
179 | } |
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.