| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 103 | 
| Code Lines | 100 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 4 | ||
| Bugs | 0 | 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 | ||
| 70 |   public function testBlogSave(): void { | ||
| 71 | // No Admin. | ||
| 72 |     self::$ci->blogger->setBlog("test_blog"); | ||
| 73 | $_POST["action"] = "save"; | ||
| 74 | $_POST["title"] = "Hello Title"; | ||
| 75 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; | ||
| 76 | $this->assertEquals(self::$ci->blogger->savePost(), Blogger::CREATE); | ||
| 77 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again."; | ||
| 78 | $_POST["id"] = 1; | ||
| 79 | $this->assertEquals(self::$ci->blogger->savePost(), Blogger::EDIT); | ||
| 80 |     $this->assertTrue(self::$ci->blogger->renderPost("Hello-Title", null)); | ||
| 81 |     $post = self::$ci->blogger->getPost("Hello-Title", false); | ||
| 82 | $this->assertTrue(is_array($post)); | ||
| 83 |     $this->assertArrayHasKey("id", $post); | ||
| 84 |     $this->assertArrayHasKey("title", $post); | ||
| 85 |     $this->assertArrayHasKey("content", $post); | ||
| 86 |     $this->assertArrayHasKey("published", $post); | ||
| 87 |     $this->assertArrayHasKey("date_published", $post); | ||
| 88 |     $this->assertArrayHasKey("slug", $post); | ||
| 89 | $this->assertEquals(1, $post["id"], "Assert Post ID"); | ||
| 90 |     $this->assertEquals("Hello Title", $post["title"], "Assert Post Title"); | ||
| 91 |     $this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $post["content"]); | ||
| 92 |     $this->assertEquals("Hello-Title", $post["slug"]); | ||
| 93 | $this->assertEquals(0, $post["published"]); | ||
| 94 | $this->assertEquals(null, $post["date_published"]); | ||
| 95 | $_POST["action"] = "publish"; | ||
| 96 | $this->assertEquals(self::$ci->blogger->savePost(), Blogger::PUBLISH); | ||
| 97 |     $post = self::$ci->blogger->getPost("Hello-Title", false); | ||
| 98 | $this->assertTrue(is_array($post)); | ||
| 99 | $this->assertEquals(1, $post["published"]); | ||
| 100 | $this->assertNotEquals(null, $post["date_published"]); | ||
| 101 | $_POST["action"] = "createAndPublish"; | ||
| 102 | $_POST["title"] = "Hello Title 2"; | ||
| 103 | $_POST["editor"] = "Create and Published Post."; | ||
| 104 | unset($_POST["id"]); | ||
| 105 | $this->assertEquals(Blogger::CREATE_AND_PUBLISH, self::$ci->blogger->savePost()); | ||
| 106 |     $post = self::$ci->blogger->getPost("Hello-Title-2", false); | ||
| 107 | $this->assertTrue(is_array($post)); | ||
| 108 |     $this->assertArrayHasKey("id", $post); | ||
| 109 |     $this->assertArrayHasKey("title", $post); | ||
| 110 |     $this->assertArrayHasKey("content", $post); | ||
| 111 |     $this->assertArrayHasKey("published", $post); | ||
| 112 |     $this->assertArrayHasKey("date_published", $post); | ||
| 113 |     $this->assertArrayHasKey("slug", $post); | ||
| 114 | $this->assertEquals(2, $post["id"], "Assert Post ID"); | ||
| 115 |     $this->assertEquals("Hello Title 2", $post["title"], "Assert Post Title"); | ||
| 116 |     $this->assertEquals("Create and Published Post.", $post["content"]); | ||
| 117 |     $this->assertEquals("Hello-Title-2", $post["slug"]); | ||
| 118 | $this->assertEquals(1, $post["published"]); | ||
| 119 | $this->assertNotEquals(null, $post["date_published"]); | ||
| 120 | $this->assertEquals(Blogger::ABORT, self::$ci->blogger->savePost(), "No 2 blog posts can have the same title."); | ||
| 121 | // TODO: With Admin. | ||
| 122 |     self::$ci->blogger->setBlog("admin_test_blog"); | ||
| 123 | $_POST["action"] = "save"; | ||
| 124 | $_POST["title"] = "Admin Hello Title"; | ||
| 125 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; | ||
| 126 | unset($_POST["id"]); | ||
| 127 | $this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE); | ||
| 128 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again."; | ||
| 129 | $_POST["id"] = 1; | ||
| 130 | $this->assertEquals(self::$ci->blogger->savePost(1), Blogger::EDIT); | ||
| 131 |     $this->assertTrue(self::$ci->blogger->renderPost("Admin-Hello-Title", null)); | ||
| 132 |     $post = self::$ci->blogger->getPost("Admin-Hello-Title", false); | ||
| 133 | $this->assertTrue(is_array($post)); | ||
| 134 |     $this->assertArrayHasKey("id", $post); | ||
| 135 |     $this->assertArrayHasKey("title", $post); | ||
| 136 |     $this->assertArrayHasKey("content", $post); | ||
| 137 |     $this->assertArrayHasKey("published", $post); | ||
| 138 |     $this->assertArrayHasKey("date_published", $post); | ||
| 139 |     $this->assertArrayHasKey("slug", $post); | ||
| 140 | $this->assertEquals(1, $post["id"], "Assert Post ID"); | ||
| 141 |     $this->assertEquals("Admin Hello Title", $post["title"], "Assert Post Title"); | ||
| 142 |     $this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $post["content"]); | ||
| 143 |     $this->assertEquals("Admin-Hello-Title", $post["slug"]); | ||
| 144 | $this->assertEquals(0, $post["published"]); | ||
| 145 | $this->assertEquals(null, $post["date_published"]); | ||
| 146 | $_POST["action"] = "publish"; | ||
| 147 | $this->assertEquals(self::$ci->blogger->savePost(1), Blogger::PUBLISH); | ||
| 148 |     $post = self::$ci->blogger->getPost("Admin-Hello-Title", false); | ||
| 149 | $this->assertTrue(is_array($post)); | ||
| 150 | $this->assertEquals(1, $post["published"]); | ||
| 151 | $this->assertNotEquals(null, $post["date_published"]); | ||
| 152 | $_POST["action"] = "createAndPublish"; | ||
| 153 | $_POST["title"] = "Admin Hello Title 2"; | ||
| 154 | $_POST["editor"] = "Create and Published Post."; | ||
| 155 | unset($_POST["id"]); | ||
| 156 | $this->assertEquals(Blogger::CREATE_AND_PUBLISH, self::$ci->blogger->savePost(1)); | ||
| 157 |     $post = self::$ci->blogger->getPost("Admin-Hello-Title-2", false); | ||
| 158 | $this->assertTrue(is_array($post)); | ||
| 159 |     $this->assertArrayHasKey("id", $post); | ||
| 160 |     $this->assertArrayHasKey("title", $post); | ||
| 161 |     $this->assertArrayHasKey("content", $post); | ||
| 162 |     $this->assertArrayHasKey("published", $post); | ||
| 163 |     $this->assertArrayHasKey("date_published", $post); | ||
| 164 |     $this->assertArrayHasKey("slug", $post); | ||
| 165 |     $this->assertArrayHasKey("poster_id", $post); | ||
| 166 | $this->assertEquals(2, $post["id"], "Assert Post ID"); | ||
| 167 |     $this->assertEquals("Admin Hello Title 2", $post["title"], "Assert Post Title"); | ||
| 168 |     $this->assertEquals("Create and Published Post.", $post["content"]); | ||
| 169 |     $this->assertEquals("Admin-Hello-Title-2", $post["slug"]); | ||
| 170 | $this->assertEquals(1, $post["published"]); | ||
| 171 | $this->assertNotEquals(null, $post["date_published"]); | ||
| 172 | $this->assertEquals(Blogger::ABORT, self::$ci->blogger->savePost(1), "No 2 blog posts can have the same title."); | ||
| 173 | } | ||
| 195 |