Conditions | 1 |
Paths | 1 |
Total Lines | 69 |
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 |
||
93 | public function postConstructor() |
||
94 | { |
||
95 | return [ |
||
96 | [ |
||
97 | null, |
||
98 | 'A Post', |
||
99 | 'Lorem ipsum', |
||
100 | new Author( |
||
101 | 'Davis', |
||
102 | '[email protected]', |
||
103 | 'Some string', |
||
104 | null, |
||
105 | new DateTime() |
||
106 | ), |
||
107 | [], |
||
108 | null, |
||
109 | Post::class, |
||
110 | 'no tags, no publish date', |
||
111 | ], |
||
112 | [ |
||
113 | Uuid::uuid4()->toString(), |
||
114 | 'A Post', |
||
115 | 'Lorem ipsum', |
||
116 | new Author( |
||
117 | 'Davis', |
||
118 | '[email protected]', |
||
119 | 'Some string', |
||
120 | null, |
||
121 | new DateTime() |
||
122 | ), |
||
123 | [new Tag('tag1', null), new Tag('tag2', null)], |
||
124 | null, |
||
125 | Post::class, |
||
126 | 'have tags, unpublished', |
||
127 | ], |
||
128 | [ |
||
129 | null, |
||
130 | 'A Post', |
||
131 | 'Lorem ipsum', |
||
132 | new Author( |
||
133 | 'Davis', |
||
134 | '[email protected]', |
||
135 | 'Some string', |
||
136 | null, |
||
137 | new DateTime() |
||
138 | ), |
||
139 | [], |
||
140 | new DateTime(), |
||
141 | Post::class, |
||
142 | 'no tags, published', |
||
143 | ], |
||
144 | [ |
||
145 | '', |
||
146 | 'A Post', |
||
147 | 'Lorem ipsum', |
||
148 | new Author( |
||
149 | 'Davis', |
||
150 | '[email protected]', |
||
151 | 'Some string', |
||
152 | null, |
||
153 | new DateTime() |
||
154 | ), |
||
155 | [new Tag('tag1', null), new Tag('tag2', null)], |
||
156 | new DateTime(), |
||
157 | Post::class, |
||
158 | 'tags, published (most common scenario)', |
||
159 | ] |
||
160 | ]; |
||
161 | } |
||
162 | |||
197 |