| Conditions | 1 |
| Paths | 1 |
| Total Lines | 66 |
| Code Lines | 40 |
| 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 |
||
| 42 | public function testSign() |
||
| 43 | { |
||
| 44 | $expectedSignature = 'foobar'; |
||
| 45 | |||
| 46 | // Configure payload |
||
| 47 | |||
| 48 | $headerParameters = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock(); |
||
| 49 | |||
| 50 | $headerParameters->expects($this->once()) |
||
| 51 | ->method('jsonSerialize'); |
||
| 52 | |||
| 53 | $this->encoder->expects($this->at(0)) |
||
| 54 | ->method('encode'); |
||
| 55 | |||
| 56 | $header = $this->getMockBuilder('Emarref\Jwt\Token\Header')->getMock(); |
||
| 57 | |||
| 58 | $header->expects($this->once()) |
||
| 59 | ->method('getParameters') |
||
| 60 | ->will($this->returnValue($headerParameters)); |
||
| 61 | |||
| 62 | // Configure payload |
||
| 63 | |||
| 64 | $claims = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock(); |
||
| 65 | |||
| 66 | $claims->expects($this->once()) |
||
| 67 | ->method('jsonSerialize'); |
||
| 68 | |||
| 69 | $payload = $this->getMockBuilder('Emarref\Jwt\Token\Payload')->getMock(); |
||
| 70 | |||
| 71 | $payload->expects($this->once()) |
||
| 72 | ->method('getClaims') |
||
| 73 | ->will($this->returnValue($claims)); |
||
| 74 | |||
| 75 | $this->encoder->expects($this->at(1)) |
||
| 76 | ->method('encode'); |
||
| 77 | |||
| 78 | // Configure token |
||
| 79 | |||
| 80 | $token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock(); |
||
| 81 | |||
| 82 | $token->expects($this->once()) |
||
| 83 | ->method('getHeader') |
||
| 84 | ->will($this->returnValue($header)); |
||
| 85 | |||
| 86 | $token->expects($this->once()) |
||
| 87 | ->method('getPayload') |
||
| 88 | ->will($this->returnValue($payload)); |
||
| 89 | |||
| 90 | $this->encryption->expects($this->once()) |
||
| 91 | ->method('getAlgorithmName') |
||
| 92 | ->will($this->returnValue('alg')); |
||
| 93 | |||
| 94 | $this->encryption->expects($this->once()) |
||
| 95 | ->method('encrypt') |
||
| 96 | ->will($this->returnValue($expectedSignature)); |
||
| 97 | |||
| 98 | $token->expects($this->once()) |
||
| 99 | ->method('addHeader') |
||
| 100 | ->with(new Algorithm('alg')); |
||
| 101 | |||
| 102 | $token->expects($this->once()) |
||
| 103 | ->method('setSignature') |
||
| 104 | ->with($expectedSignature); |
||
| 105 | |||
| 106 | $this->signer->sign($token); |
||
| 107 | } |
||
| 108 | } |
||
| 109 |