| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 11 | public function testYamlWriter() |
||
| 12 | { |
||
| 13 | $writer = new YamlWriter(); |
||
| 14 | $entities = [ |
||
| 15 | 'Level1.Level2.EntityName' => 'Text', |
||
| 16 | 'Level1.OtherEntityName' => 'Other Text', |
||
| 17 | 'Level1.Plurals' => [ |
||
| 18 | 'context' => 'Some ignored context', |
||
| 19 | 'one' => 'An item', |
||
| 20 | 'other' => '{count} items', |
||
| 21 | ], |
||
| 22 | 'Level1.PluralString1' => 'An item|{count} items', |
||
| 23 | 'Level1.PluralString2' => [ |
||
| 24 | 'context' => 'Another ignored context', |
||
| 25 | 'default' => 'An item|{count} items', |
||
| 26 | ], |
||
| 27 | // Some near-false-positives for plurals |
||
| 28 | 'Level1.NotPlural1' => 'Not a plural|string', // no count |
||
| 29 | 'Level1.NotPlural2' => 'Not|a|plural|string{count}', // unexpected number |
||
| 30 | 'Level1.NotPlural3' => 'Not a plural string {count}', // no pipe |
||
| 31 | 'Level1.BoolTest' => 'True', |
||
| 32 | 'Level1.FlagTest' => 'No', |
||
| 33 | 'Level1.TextTest' => 'Maybe', |
||
| 34 | 'Template.ss.Key' => 'Template var', |
||
| 35 | 'TopLevel' => 'The Top', |
||
| 36 | ]; |
||
| 37 | $yaml = <<<YAML |
||
| 38 | de: |
||
| 39 | Level1: |
||
| 40 | BoolTest: 'True' |
||
| 41 | FlagTest: 'No' |
||
| 42 | Level2.EntityName: Text |
||
| 43 | NotPlural1: 'Not a plural|string' |
||
| 44 | NotPlural2: 'Not|a|plural|string{count}' |
||
| 45 | NotPlural3: 'Not a plural string {count}' |
||
| 46 | OtherEntityName: 'Other Text' |
||
| 47 | PluralString1: |
||
| 48 | one: 'An item' |
||
| 49 | other: '{count} items' |
||
| 50 | PluralString2: |
||
| 51 | one: 'An item' |
||
| 52 | other: '{count} items' |
||
| 53 | Plurals: |
||
| 54 | one: 'An item' |
||
| 55 | other: '{count} items' |
||
| 56 | TextTest: Maybe |
||
| 57 | Template.ss: |
||
| 58 | Key: 'Template var' |
||
| 59 | TopLevel: 'The Top' |
||
| 60 | |||
| 61 | YAML; |
||
| 62 | $this->assertEquals($yaml, Convert::nl2os($writer->getYaml($entities, 'de'))); |
||
| 63 | } |
||
| 64 | } |
||
| 65 |