| Conditions | 2 |
| Paths | 2 |
| Total Lines | 61 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 71 | public function resultIncludesErrorMessagesCreatedByJsonSchema() |
||
| 72 | { |
||
| 73 | $value = (object)[ |
||
| 74 | 'foo' => (object)[ |
||
| 75 | 'blah' => 'one' |
||
| 76 | ], |
||
| 77 | 'bar' => (object)[] |
||
| 78 | ]; |
||
| 79 | $validator = new Validator(); |
||
| 80 | $schema = (object)[ |
||
| 81 | 'type' => 'object', |
||
| 82 | 'required' => ['foo', 'bar'], |
||
| 83 | 'properties' => (object)[ |
||
| 84 | 'foo' => (object)[ |
||
| 85 | 'type' => 'object', |
||
| 86 | 'properties' => (object)[ |
||
| 87 | 'blah' => (object)[ |
||
| 88 | 'type' => 'integer' |
||
| 89 | ] |
||
| 90 | ] |
||
| 91 | ], |
||
| 92 | 'bar' => (object)[ |
||
| 93 | 'type' => 'object', |
||
| 94 | 'required' => ['blah'], |
||
| 95 | 'properties' => (object)[ |
||
| 96 | 'blah' => (object)[ |
||
| 97 | 'type' => 'string' |
||
| 98 | ] |
||
| 99 | ] |
||
| 100 | ] |
||
| 101 | ] |
||
| 102 | ]; |
||
| 103 | $validator->check($value, $schema); |
||
| 104 | $errors = $validator->getErrors(); |
||
| 105 | |||
| 106 | $exception = new InvalidParametersException('Nope', $errors); |
||
| 107 | |||
| 108 | $mock = $this->refBuilder; |
||
| 109 | /** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
||
| 110 | $mock |
||
| 111 | ->expects($this->exactly(2)) |
||
| 112 | ->method('buildSpecificationLink') |
||
| 113 | ->willReturnOnConsecutiveCalls('http://1.net/1', 'http://2.net/2'); |
||
| 114 | |||
| 115 | $vndError = $this->factory->create( |
||
| 116 | $this->createSimpleRequest(), |
||
| 117 | $exception |
||
| 118 | ); |
||
| 119 | |||
| 120 | $resources = $vndError->getResources(); |
||
| 121 | $this->assertArrayHasKey('errors', $resources); |
||
| 122 | $errorResources = $resources['errors']; |
||
| 123 | $this->assertSame(count($errors), count($errorResources)); |
||
| 124 | |||
| 125 | $resources = array_values($errorResources); |
||
| 126 | |||
| 127 | foreach ($errors as $i => $spec) { |
||
| 128 | $data = $resources[$i]->getData(); |
||
| 129 | $this->assertContains($spec['message'], $data['message']); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 141 |