| Conditions | 7 |
| Paths | 3 |
| Total Lines | 53 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 25 | private function loadExif($exifValue, $expectCallRotateValue, $expectCallFlip) |
||
| 26 | { |
||
| 27 | $loader = new AutoRotateFilterLoader(); |
||
| 28 | |||
| 29 | // Mocks the image and makes it use the fake meta data. |
||
| 30 | $image = $this->getMockImage(); |
||
| 31 | |||
| 32 | if (method_exists('Imagine\Image\ImageInterface', 'metadata')) { |
||
| 33 | // Mocks the metadata and makes it return the expected exif value for the rotation. |
||
| 34 | // If $exifValue is null, it means the image doesn't contain any metadata. |
||
| 35 | $metaData = $this->getMockMetaData(); |
||
| 36 | |||
| 37 | $metaData |
||
| 38 | ->expects($this->atLeastOnce()) |
||
| 39 | ->method('offsetGet') |
||
| 40 | ->willReturn($exifValue); |
||
| 41 | |||
| 42 | if ($exifValue && $exifValue > '1' && $exifValue <= 8) { |
||
| 43 | $metaData |
||
| 44 | ->expects($this->once()) |
||
| 45 | ->method('offsetSet') |
||
| 46 | ->with($this->orientationKey, '1'); |
||
| 47 | } |
||
| 48 | |||
| 49 | $image |
||
| 50 | ->expects($this->atLeastOnce()) |
||
| 51 | ->method('metadata') |
||
| 52 | ->willReturn($metaData); |
||
| 53 | } else { |
||
| 54 | $jpg = file_get_contents(__DIR__.'/../../../Fixtures/assets/pixel_1x1_orientation_at_0x30.jpg'); |
||
| 55 | // The byte with orientation is at offset 0x30 for this image |
||
| 56 | $jpg[0x30] = chr((int) $exifValue); |
||
| 57 | |||
| 58 | $image |
||
| 59 | ->expects($this->once()) |
||
| 60 | ->method('get') |
||
| 61 | ->with('jpg') |
||
| 62 | ->will($this->returnValue($jpg)); |
||
| 63 | } |
||
| 64 | |||
| 65 | // Checks that rotate is called with $expectCallRotateValue, or not called at all if $expectCallRotateValue is null. |
||
| 66 | $image |
||
| 67 | ->expects($expectCallRotateValue !== null ? $this->once() : $this->never()) |
||
| 68 | ->method('rotate') |
||
| 69 | ->with($expectCallRotateValue); |
||
| 70 | |||
| 71 | // Checks that rotate is called if $expectCallFlip is true, not called if $expectCallFlip is false. |
||
| 72 | $image |
||
| 73 | ->expects($expectCallFlip ? $this->once() : $this->never()) |
||
| 74 | ->method('flipHorizontally'); |
||
| 75 | |||
| 76 | $loader->load($image); |
||
| 77 | } |
||
| 78 | |||
| 175 |