| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 44 |
| 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 |
||
| 30 | public function testLazyLoadGet() |
||
| 31 | { |
||
| 32 | $loadersMap = array( |
||
| 33 | ExtractorInterface::FIELD_UNIQUE_ID => 'id', |
||
| 34 | ExtractorInterface::FIELD_USERNAME => 'profile' |
||
| 35 | ); |
||
| 36 | $normalizersMap = array( |
||
| 37 | ExtractorInterface::FIELD_UNIQUE_ID => ExtractorInterface::FIELD_UNIQUE_ID, |
||
| 38 | ExtractorInterface::FIELD_USERNAME => ExtractorInterface::FIELD_USERNAME |
||
| 39 | ); |
||
| 40 | $supports = array( |
||
| 41 | ExtractorInterface::FIELD_UNIQUE_ID, |
||
| 42 | ExtractorInterface::FIELD_USERNAME |
||
| 43 | ); |
||
| 44 | $fields = array( |
||
| 45 | ExtractorInterface::FIELD_UNIQUE_ID => 123 |
||
| 46 | ); |
||
| 47 | $constructorArgs = array( |
||
| 48 | $loadersMap, |
||
| 49 | $normalizersMap, |
||
| 50 | $supports, |
||
| 51 | $fields |
||
| 52 | ); |
||
| 53 | $methods = array( |
||
| 54 | 'idLoader', |
||
| 55 | 'uniqueIdNormalizer', |
||
| 56 | 'profileLoader', |
||
| 57 | 'usernameNormalizer' |
||
| 58 | ); |
||
| 59 | $profileData = array( |
||
| 60 | 'data' => array( |
||
| 61 | 'nickname' => 'johnnydonny' |
||
| 62 | ) |
||
| 63 | ); |
||
| 64 | $extractor = $this->getMockBuilder('\\OAuth\\UserData\\Extractor\\LazyExtractor') |
||
| 65 | ->setMethods($methods) |
||
| 66 | ->setConstructorArgs($constructorArgs) |
||
| 67 | ->getMock(); |
||
| 68 | $extractor->expects($this->never()) |
||
| 69 | ->method('idLoader'); |
||
| 70 | $extractor->expects($this->never()) |
||
| 71 | ->method('uniqueIdNormalizer'); |
||
| 72 | $extractor->expects($this->once()) |
||
| 73 | ->method('profileLoader') |
||
| 74 | ->with() |
||
| 75 | ->will($this->returnValue($profileData)); |
||
| 76 | $extractor->expects($this->once()) |
||
| 77 | ->method('usernameNormalizer') |
||
| 78 | ->with($profileData) |
||
| 79 | ->will($this->returnValue($profileData['data']['nickname'])); |
||
| 80 | /** |
||
| 81 | * @var \OAuth\UserData\Extractor\LazyExtractor $extractor |
||
| 82 | */ |
||
| 83 | $this->assertEquals(123, $extractor->getUniqueId()); // prefetched field, does not trigger loader and normalizer |
||
| 84 | $this->assertEquals('johnnydonny', $extractor->getUsername()); // triggers the loader and the normalizer |
||
| 85 | $this->assertEquals('johnnydonny', $extractor->getUsername()); // does not trigger them again |
||
| 86 | } |
||
| 87 | |||
| 94 |