| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 39 |
| 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 |
||
| 27 | public function testFindHands() |
||
| 28 | { |
||
| 29 | // Test Royal Flush |
||
| 30 | $cards = [ |
||
| 31 | '13' => ['AS', 'KS', 'QS', 'JS', '10S', '9S', '8S'], |
||
| 32 | '13' => ['AD', 'KD', 'QD', 'JD', '10D', '9D', '8D'], |
||
| 33 | '13' => ['AC', 'KC', 'QC', 'JC', '10C', '9C', '8C'], |
||
| 34 | '13' => ['AH', 'KH', 'QH', 'JH', '10H', '9H', '8H'], |
||
| 35 | ]; |
||
| 36 | $this->runValidTest("Royal Flush", 5, $cards); |
||
| 37 | |||
| 38 | // Test Straight Flush |
||
| 39 | $cards = [ |
||
| 40 | '12' => ['KS', 'QS', 'JS', '10S', '9S', '8H', '7D'], |
||
| 41 | '11' => ['QS', 'JS', '10S', '9S', '8S', '7C', '2C'], |
||
| 42 | ]; |
||
| 43 | $this->runValidTest("Straight Flush", 5, $cards); |
||
| 44 | |||
| 45 | // Test Four of a kind |
||
| 46 | $cards = [ |
||
| 47 | '12' => ['KS', 'KD', 'KC', 'KH', '9S', '8S', '7D'], |
||
| 48 | ]; |
||
| 49 | $this->runValidTest("Four of a kind", 4, $cards); |
||
| 50 | |||
| 51 | // Test Full House |
||
| 52 | $cards = [ |
||
| 53 | '12' => ['KS', 'KD', 'KC', 'QD', 'QC', '8S', '7D'], |
||
| 54 | '13' => ['AD', 'AC', 'AH', '9D', '9H', '9C', 'JS'], |
||
| 55 | ]; |
||
| 56 | $this->runValidTest("Full House", 5, $cards); |
||
| 57 | |||
| 58 | // Test Flush |
||
| 59 | $cards = [ |
||
| 60 | '9' => ['10H', '8H', '7H', '3H', '5H', '8C', '7D'], |
||
| 61 | '8' => ['9D', '8D', '4D', '3D', '5D', '8C', '2H'], |
||
| 62 | ]; |
||
| 63 | $this->runValidTest("Flush", 5, $cards); |
||
| 64 | |||
| 65 | // Test Straight |
||
| 66 | $cards = [ |
||
| 67 | '6' => ['7H', '6S', '5H', '4C', '3H', 'JC', 'AD'], |
||
| 68 | '9' => ['10S', '9C', '8H', '7D', '6S', 'QC', '2D'], |
||
| 69 | '10' => ['JC', '10H', '9D', '8C', '7S', '5H', '3H'], |
||
| 70 | '12' => ['KD', 'QC', 'JS', '10S', '9S', '6H', '3D'], |
||
| 71 | '7' => ['8S', '7C', '6C', '5H', '4H', 'JC', '10H'], |
||
| 72 | '6' => ['AC', '2D', '3H', '4H', '5S', 'KS', '10D'], // straight from bottom |
||
| 73 | ]; |
||
| 74 | $this->runValidTest("Straight", 5, $cards); |
||
| 75 | |||
| 76 | // Test Three of a kind |
||
| 77 | $cards = [ |
||
| 78 | '11' => ['QS', 'QC', 'QD', 'JS', '6S', '7D', '9S'], |
||
| 79 | ]; |
||
| 80 | $this->runValidTest("Three of a kind", 3, $cards); |
||
| 81 | |||
| 82 | // Test Two Pairs |
||
| 83 | $cards = [ |
||
| 84 | '9' => ['10C', '10H', '2H', '2S', 'JC', '6C', '9D'], |
||
| 85 | ]; |
||
| 86 | $this->runValidTest("Two Pairs", 4, $cards); |
||
| 87 | |||
| 88 | // Test One Pair |
||
| 89 | $cards = [ |
||
| 90 | '9' => ['10C', '10H', 'KH', '2S', 'JC', '6C', '9D'], |
||
| 91 | ]; |
||
| 92 | $this->runValidTest("One Pair", 2, $cards); |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 111 |