| 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 |
||
| 52 | public function testFindByPath() |
||
| 53 | { |
||
| 54 | $test_active_post = array( |
||
| 55 | 'title' => 'test findByPath active', |
||
| 56 | 'path' => 'test-findbypath-active', |
||
| 57 | 'category' => 'test-category', |
||
| 58 | 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
||
| 59 | 'body' => 'test content', |
||
| 60 | 'display' => 1 |
||
| 61 | ); |
||
| 62 | |||
| 63 | $this->connections->getDefault()->perform(" |
||
| 64 | INSERT INTO jpemeric_blog.post |
||
| 65 | (title, path, category, date, body, display) |
||
| 66 | VALUES |
||
| 67 | (:title, :path, :category, :date, :body, :display)", |
||
| 68 | $test_active_post); |
||
| 69 | |||
| 70 | $active_post = $this->newMysqlPostRepository()->findByPath( |
||
| 71 | $test_active_post['category'], |
||
| 72 | $test_active_post['path'] |
||
| 73 | ); |
||
| 74 | $this->assertSame($test_active_post['title'], $active_post['title']); |
||
| 75 | |||
| 76 | $test_inactive_post = array( |
||
| 77 | 'title' => 'test findByPath inactive', |
||
| 78 | 'path' => 'test-findbypath-inactive', |
||
| 79 | 'category' => 'test-category', |
||
| 80 | 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
||
| 81 | 'body' => 'test content', |
||
| 82 | 'display' => 0 |
||
| 83 | ); |
||
| 84 | |||
| 85 | $this->connections->getDefault()->perform(" |
||
| 86 | INSERT INTO jpemeric_blog.post |
||
| 87 | (title, path, category, date, body, display) |
||
| 88 | VALUES |
||
| 89 | (:title, :path, :category, :date, :body, :display)", |
||
| 90 | $test_inactive_post); |
||
| 91 | |||
| 92 | $inactive_post = $this->newMysqlPostRepository()->findByPath( |
||
| 93 | $test_inactive_post['category'], |
||
| 94 | $test_inactive_post['path'] |
||
| 95 | ); |
||
| 96 | $this->assertFalse($inactive_post); |
||
| 97 | |||
| 98 | $nonexistant_post = $this->newMysqlPostRepository()->findByPath( |
||
| 99 | 'test-category', |
||
| 100 | 'test-findbypath-nonexistant' |
||
| 101 | ); |
||
| 102 | $this->assertFalse($nonexistant_post); |
||
| 103 | } |
||
| 104 | |||
| 119 |
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.