Conditions | 2 |
Paths | 2 |
Total Lines | 65 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
81 | public function testGetSeriesForPost() |
||
82 | { |
||
83 | $testPostData = [ |
||
84 | [ |
||
85 | 'id' => rand(1, 100), |
||
86 | 'title' => 'test one', |
||
87 | 'category' => 'test category', |
||
88 | 'path' => 'test-one', |
||
89 | 'display' => 1, |
||
90 | ], |
||
91 | [ |
||
92 | 'id' => rand(101, 200), |
||
93 | 'title' => 'test two', |
||
94 | 'category' => 'test category', |
||
95 | 'path' => 'test-two', |
||
96 | 'display' => 1, |
||
97 | ], |
||
98 | ]; |
||
99 | |||
100 | $testSeriesData = [ |
||
101 | [ |
||
102 | 'id' => rand(1, 100), |
||
103 | 'title' => 'test one', |
||
104 | 'description' => 'test description', |
||
105 | ], |
||
106 | ]; |
||
107 | |||
108 | $testSeriesPostData = [ |
||
109 | [ |
||
110 | 'series' => reset($testSeriesData)['id'], |
||
111 | 'post' => $testPostData[0]['id'], |
||
112 | 'order' => 1, |
||
113 | ], |
||
114 | [ |
||
115 | 'series' => reset($testSeriesData)['id'], |
||
116 | 'post' => $testPostData[1]['id'], |
||
117 | 'order' => 2, |
||
118 | ], |
||
119 | ]; |
||
120 | |||
121 | array_walk($testPostData, [$this, 'insertPostData']); |
||
122 | array_walk($testSeriesData, [$this, 'insertSeriesData']); |
||
123 | array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']); |
||
124 | |||
125 | $repository = new MysqlSeriesRepository(self::$connection); |
||
126 | $data = $repository->getSeriesForPost(reset($testPostData)['id']); |
||
127 | |||
128 | $this->assertNotFalse($data); |
||
129 | $this->assertInternalType('array', $data); |
||
130 | foreach ($testPostData as $key => $testPostRow) { |
||
131 | $this->assertInternalType('array', $data[$key]); |
||
132 | $this->assertArrayHasKey('series_title', $data[$key]); |
||
133 | $this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']); |
||
134 | $this->assertArrayHasKey('series_description', $data[$key]); |
||
135 | $this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']); |
||
136 | $this->assertArrayHasKey('post', $data[$key]); |
||
137 | $this->assertEquals($testPostRow['id'], $data[$key]['post']); |
||
138 | $this->assertArrayHasKey('title', $data[$key]); |
||
139 | $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
||
140 | $this->assertArrayHasKey('category', $data[$key]); |
||
141 | $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
||
142 | $this->assertArrayHasKey('path', $data[$key]); |
||
143 | $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
||
144 | } |
||
145 | } |
||
146 | |||
227 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.