Conditions | 1 |
Paths | 1 |
Total Lines | 52 |
Code Lines | 31 |
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 |
||
43 | public function testFindByPath() |
||
44 | { |
||
45 | $test_active_post = array( |
||
46 | 'title' => 'test findByPath active', |
||
47 | 'path' => 'test-findbypath-active', |
||
48 | 'category' => 'test-category', |
||
49 | 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
||
50 | 'body' => 'test content', |
||
51 | 'display' => 1 |
||
52 | ); |
||
53 | |||
54 | $this->connections->getDefault()->perform(" |
||
55 | INSERT INTO jpemeric_blog.post |
||
56 | (title, path, category, date, body, display) |
||
57 | VALUES |
||
58 | (:title, :path, :category, :date, :body, :display)", |
||
59 | $test_active_post); |
||
60 | |||
61 | $active_post = $this->newMysqlPostRepository()->findByPath( |
||
62 | $test_active_post['category'], |
||
63 | $test_active_post['path'] |
||
64 | ); |
||
65 | $this->assertSame($test_active_post['title'], $active_post['title']); |
||
66 | |||
67 | $test_inactive_post = array( |
||
68 | 'title' => 'test findByPath inactive', |
||
69 | 'path' => 'test-findbypath-inactive', |
||
70 | 'category' => 'test-category', |
||
71 | 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
||
72 | 'body' => 'test content', |
||
73 | 'display' => 0 |
||
74 | ); |
||
75 | |||
76 | $this->connections->getDefault()->perform(" |
||
77 | INSERT INTO jpemeric_blog.post |
||
78 | (title, path, category, date, body, display) |
||
79 | VALUES |
||
80 | (:title, :path, :category, :date, :body, :display)", |
||
81 | $test_inactive_post); |
||
82 | |||
83 | $inactive_post = $this->newMysqlPostRepository()->findByPath( |
||
84 | $test_inactive_post['category'], |
||
85 | $test_inactive_post['path'] |
||
86 | ); |
||
87 | $this->assertFalse($inactive_post); |
||
88 | |||
89 | $nonexistant_post = $this->newMysqlPostRepository()->findByPath( |
||
90 | 'test-category', |
||
91 | 'test-findbypath-nonexistant' |
||
92 | ); |
||
93 | $this->assertFalse($nonexistant_post); |
||
94 | } |
||
95 | |||
110 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.