Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
69 | public function testParse() |
||
70 | { |
||
71 | $all = [ |
||
72 | 'testBlogEntryId' => [ |
||
73 | 'src' => 'blog/2017/2017-03-19-TestBlogbeitrag.md' |
||
74 | ], |
||
75 | 'testBlogEntryId1' => [ |
||
76 | 'src' => 'blog/2017/2017-03-18-TestBlogbeitrag1.md', |
||
77 | ], |
||
78 | 'testPageId' => [ |
||
79 | 'src' => 'pages/testpage.md', |
||
80 | ], |
||
81 | 'anotherId' => [ |
||
82 | 'src' => 'pages/anotherpage.md', |
||
83 | ], |
||
84 | 'testDraftBlogEntryId' => [ |
||
85 | 'src' => 'blog/2017/2017-03-20-TestBlogbeitragDraft.md', |
||
86 | ], |
||
87 | 'testDraftPageId' => [ |
||
88 | 'src' => 'pages/testpage-draft.md', |
||
89 | ], |
||
90 | ]; |
||
91 | |||
92 | $blogEntryByCreated = [ |
||
93 | '2017-03-19T06:30:00' => 'testBlogEntryId', |
||
94 | '2017-03-18T06:30:00' => 'testBlogEntryId1', |
||
95 | ]; |
||
96 | $blogEntryTags = [ |
||
97 | 'tdd' => [ |
||
98 | '2017-03-19T06:30:00' => 'testBlogEntryId', |
||
99 | '2017-03-18T06:30:00' => 'testBlogEntryId1', |
||
100 | ], |
||
101 | 'markdown' => [ |
||
102 | '2017-03-19T06:30:00' => 'testBlogEntryId' |
||
103 | ], |
||
104 | 'php' => [ |
||
105 | '2017-03-19T06:30:00' => 'testBlogEntryId' |
||
106 | ], |
||
107 | 'zend' => [ |
||
108 | '2017-03-18T06:30:00' => 'testBlogEntryId1' |
||
109 | ] |
||
110 | ]; |
||
111 | $pagesByCreated = [ |
||
112 | '2017-03-22T04:30:00' => 'anotherId', |
||
113 | '2017-03-19T05:30:00' => 'testPageId', |
||
114 | ]; |
||
115 | |||
116 | $actual = $this->parser->__invoke(); |
||
117 | |||
118 | $this->assertEquals($all, $actual['all']); |
||
119 | $this->assertSame($blogEntryByCreated, $actual['content_types']['blogEntry']['all']); |
||
120 | $this->assertSame($blogEntryTags, $actual['content_types']['blogEntry']['tags']); |
||
121 | $this->assertSame($pagesByCreated, $actual['content_types']['page']['all']); |
||
122 | } |
||
123 | } |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.