| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 69 | 
| Code Lines | 17 | 
| 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  | 
            ||
| 25 | public function testBuildPipeline()  | 
            ||
| 26 |     { | 
            ||
| 27 |         $analyticsManager = $this->getContainer()->get('graviton.analytics.analytics_manager'); | 
            ||
| 28 | $buildPipeline = $this->getPrivateClassMethod(get_class($analyticsManager), 'buildPipeline');  | 
            ||
| 29 | $mapper = new JsonMapper();  | 
            ||
| 30 |         $date = new \DateTime('-4 years'); | 
            ||
| 31 |         $year = $date->format('Y'); | 
            ||
| 32 |         $expect = '[{"$match":{"created_year":{"$gte":'.$year.'}}},{"$group":{"_id":"app-count","count":{"$sum":1}}}]'; | 
            ||
| 33 | |||
| 34 | $definitionA = json_decode(  | 
            ||
| 35 |             '{ | 
            ||
| 36 | "collection": "App",  | 
            ||
| 37 | "route": "app",  | 
            ||
| 38 | "type": "object",  | 
            ||
| 39 |               "aggregate": { | 
            ||
| 40 |                 "$match": { | 
            ||
| 41 |                   "created_year": { | 
            ||
| 42 | "$gte": "PARSE_DATE(-4 years|Y)"  | 
            ||
| 43 | }  | 
            ||
| 44 | },  | 
            ||
| 45 |                 "$group": { | 
            ||
| 46 | "_id": "app-count",  | 
            ||
| 47 |                   "count": { | 
            ||
| 48 | "$sum": 1  | 
            ||
| 49 | }  | 
            ||
| 50 | }  | 
            ||
| 51 | },  | 
            ||
| 52 |               "schema": {} | 
            ||
| 53 | }  | 
            ||
| 54 | '  | 
            ||
| 55 | );  | 
            ||
| 56 | |||
| 57 | $modelA = $mapper->map($definitionA, new AnalyticModel());  | 
            ||
| 58 | $resultA = json_encode($buildPipeline->invokeArgs($analyticsManager, [$modelA]));  | 
            ||
| 59 | $this->assertEquals($expect, $resultA);  | 
            ||
| 60 | |||
| 61 | // Pipeline  | 
            ||
| 62 | $definitionB = json_decode(  | 
            ||
| 63 |             '{ | 
            ||
| 64 | "collection": "App",  | 
            ||
| 65 | "route": "app",  | 
            ||
| 66 | "type": "object",  | 
            ||
| 67 | "pipeline": [  | 
            ||
| 68 |                 { | 
            ||
| 69 |                   "$match": { | 
            ||
| 70 |                     "created_year": { | 
            ||
| 71 | "$gte": "PARSE_DATE(-4 years|Y)"  | 
            ||
| 72 | }  | 
            ||
| 73 | }  | 
            ||
| 74 | },  | 
            ||
| 75 |                 { | 
            ||
| 76 |                   "$group": { | 
            ||
| 77 | "_id": "app-count",  | 
            ||
| 78 |                     "count": { | 
            ||
| 79 | "$sum": 1  | 
            ||
| 80 | }  | 
            ||
| 81 | }  | 
            ||
| 82 | }  | 
            ||
| 83 | ],  | 
            ||
| 84 |               "schema": {} | 
            ||
| 85 | }  | 
            ||
| 86 | '  | 
            ||
| 87 | );  | 
            ||
| 88 | |||
| 89 | $modelB = $mapper->map($definitionB, new AnalyticModel());  | 
            ||
| 90 | |||
| 91 | $resultB = json_encode($buildPipeline->invokeArgs($analyticsManager, [$modelB]));  | 
            ||
| 92 | $this->assertEquals($expect, $resultB);  | 
            ||
| 93 | }  | 
            ||
| 94 | }  | 
            ||
| 95 |