| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 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 |
||
| 32 | protected function generateApplyData( $entityType ) { |
||
| 33 | $tests = array(); |
||
| 34 | |||
| 35 | // #0: add label |
||
| 36 | $a = self::newEntity( $entityType ); |
||
| 37 | $a->setLabel( 'en', 'Test' ); |
||
| 38 | |||
| 39 | $b = self::newEntity( $entityType ); |
||
| 40 | $b->setLabel( 'en', 'Test' ); |
||
| 41 | $b->setLabel( 'de', 'Test' ); |
||
| 42 | |||
| 43 | $tests[] = array( $a, $b ); |
||
| 44 | |||
| 45 | // #1: remove label |
||
| 46 | $a = self::newEntity( $entityType ); |
||
| 47 | $a->setLabel( 'en', 'Test' ); |
||
| 48 | $a->setLabel( 'de', 'Test' ); |
||
| 49 | |||
| 50 | $b = self::newEntity( $entityType ); |
||
| 51 | $b->setLabel( 'de', 'Test' ); |
||
| 52 | |||
| 53 | $tests[] = array( $a, $b ); |
||
| 54 | |||
| 55 | // #2: change label |
||
| 56 | $a = self::newEntity( $entityType ); |
||
| 57 | $a->setLabel( 'en', 'Test' ); |
||
| 58 | |||
| 59 | $b = self::newEntity( $entityType ); |
||
| 60 | $b->setLabel( 'en', 'Test!!!' ); |
||
| 61 | |||
| 62 | // #3: add description ------------------------------ |
||
| 63 | $a = self::newEntity( $entityType ); |
||
| 64 | $a->setDescription( 'en', 'Test' ); |
||
| 65 | |||
| 66 | $b = self::newEntity( $entityType ); |
||
| 67 | $b->setDescription( 'en', 'Test' ); |
||
| 68 | $b->setDescription( 'de', 'Test' ); |
||
| 69 | |||
| 70 | $tests[] = array( $a, $b ); |
||
| 71 | |||
| 72 | // #4: remove description |
||
| 73 | $a = self::newEntity( $entityType ); |
||
| 74 | $a->setDescription( 'en', 'Test' ); |
||
| 75 | $a->setDescription( 'de', 'Test' ); |
||
| 76 | |||
| 77 | $b = self::newEntity( $entityType ); |
||
| 78 | $b->setDescription( 'de', 'Test' ); |
||
| 79 | |||
| 80 | $tests[] = array( $a, $b ); |
||
| 81 | |||
| 82 | // #5: change description |
||
| 83 | $a = self::newEntity( $entityType ); |
||
| 84 | $a->setDescription( 'en', 'Test' ); |
||
| 85 | |||
| 86 | $b = self::newEntity( $entityType ); |
||
| 87 | $b->setDescription( 'en', 'Test!!!' ); |
||
| 88 | |||
| 89 | $tests[] = array( $a, $b ); |
||
| 90 | |||
| 91 | // #6: add alias ------------------------------ |
||
| 92 | $a = self::newEntity( $entityType ); |
||
| 93 | $a->setAliases( 'en', array( 'Foo', 'Bar' ) ); |
||
| 94 | |||
| 95 | $b = self::newEntity( $entityType ); |
||
| 96 | $b->setAliases( 'en', array( 'Foo', 'Bar', 'Quux' ) ); |
||
| 97 | |||
| 98 | $tests[] = array( $a, $b ); |
||
| 99 | |||
| 100 | // #7: add alias language |
||
| 101 | $a = self::newEntity( $entityType ); |
||
| 102 | $a->setAliases( 'en', array( 'Foo', 'Bar' ) ); |
||
| 103 | |||
| 104 | $b = self::newEntity( $entityType ); |
||
| 105 | $b->setAliases( 'en', array( 'Foo', 'Bar' ) ); |
||
| 106 | $b->setAliases( 'de', array( 'Quux' ) ); |
||
| 107 | |||
| 108 | $tests[] = array( $a, $b ); |
||
| 109 | |||
| 110 | // #8: remove alias |
||
| 111 | $a = self::newEntity( $entityType ); |
||
| 112 | $a->setAliases( 'en', array( 'Foo', 'Bar' ) ); |
||
| 113 | |||
| 114 | $b = self::newEntity( $entityType ); |
||
| 115 | $b->setAliases( 'en', array( 'Bar' ) ); |
||
| 116 | |||
| 117 | $tests[] = array( $a, $b ); |
||
| 118 | |||
| 119 | // #9: remove alias language |
||
| 120 | $a = self::newEntity( $entityType ); |
||
| 121 | $a->setAliases( 'en', array( 'Foo', 'Bar' ) ); |
||
| 122 | |||
| 123 | $b = self::newEntity( $entityType ); |
||
| 124 | |||
| 125 | $tests[] = array( $a, $b ); |
||
| 126 | return $tests; |
||
| 127 | } |
||
| 128 | |||
| 218 |