| Conditions | 1 |
| Paths | 1 |
| Total Lines | 160 |
| Code Lines | 113 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 25 | public function testFoo() |
||
| 26 | { |
||
| 27 | $handlers = $this->initParser(); |
||
| 28 | $handlers = $handlers->getHandlers(); |
||
| 29 | |||
| 30 | $tag = new Tag('[url=example.org]', $handlers); |
||
| 31 | |||
| 32 | $this->assertEquals('url', $tag->getName()); |
||
| 33 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 34 | $this->assertEquals(array('href' => 'example.org'), $tag->getAttributes()); |
||
| 35 | $this->assertEquals('[url=example.org]', $tag->getRawData()); |
||
| 36 | $this->assertEquals(true, $tag->isValid()); |
||
| 37 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 38 | |||
| 39 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 40 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 41 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 42 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 43 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | $tag = new Tag('[url="example.org"]', $handlers); |
||
| 48 | |||
| 49 | $this->assertEquals('url', $tag->getName()); |
||
| 50 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 51 | $this->assertEquals(array('href' => 'example.org'), $tag->getAttributes()); |
||
| 52 | $this->assertEquals('[url="example.org"]', $tag->getRawData()); |
||
| 53 | $this->assertEquals(true, $tag->isValid()); |
||
| 54 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 55 | |||
| 56 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 57 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 58 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 59 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 60 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | $tag = new Tag('[url href="example.org"]', $handlers); |
||
| 65 | |||
| 66 | $this->assertEquals('url', $tag->getName()); |
||
| 67 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 68 | $this->assertEquals(array('href' => 'example.org'), $tag->getAttributes()); |
||
| 69 | $this->assertEquals('[url href="example.org"]', $tag->getRawData()); |
||
| 70 | $this->assertEquals(true, $tag->isValid()); |
||
| 71 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 72 | |||
| 73 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 74 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 75 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 76 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 77 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | $tag = new Tag('[url="example.org" title="This is a test"]', $handlers); |
||
| 82 | |||
| 83 | $this->assertEquals('url', $tag->getName()); |
||
| 84 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 85 | $this->assertEquals(array('href' => 'example.org', 'title' => 'This is a test'), $tag->getAttributes()); |
||
| 86 | $this->assertEquals('[url="example.org" title="This is a test"]', $tag->getRawData()); |
||
| 87 | $this->assertEquals(true, $tag->isValid()); |
||
| 88 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 89 | |||
| 90 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 91 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 92 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 93 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 94 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | $tag = new Tag('[url href="example.org" title="This is a test"]', $handlers); |
||
| 99 | |||
| 100 | $this->assertEquals('url', $tag->getName()); |
||
| 101 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 102 | $this->assertEquals('href,title', implode(',', array_keys($tag->getAttributes()))); |
||
| 103 | $this->assertEquals(array('href' => 'example.org', 'title' => 'This is a test'), $tag->getAttributes()); |
||
| 104 | $this->assertEquals('[url href="example.org" title="This is a test"]', $tag->getRawData()); |
||
| 105 | $this->assertEquals(true, $tag->isValid()); |
||
| 106 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 107 | |||
| 108 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 109 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 110 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 111 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 112 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | $tag = new Tag('[url title="This is a test" href="example.org"]', $handlers); |
||
| 117 | |||
| 118 | $this->assertEquals('url', $tag->getName()); |
||
| 119 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 120 | $this->assertEquals('href,title', implode(',', array_keys($tag->getAttributes()))); |
||
| 121 | $this->assertEquals(array('href' => 'example.org', 'title' => 'This is a test'), $tag->getAttributes()); |
||
| 122 | $this->assertEquals('[url title="This is a test" href="example.org"]', $tag->getRawData()); |
||
| 123 | $this->assertEquals(true, $tag->isValid()); |
||
| 124 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 125 | |||
| 126 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 127 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 128 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 129 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 130 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 131 | |||
| 132 | |||
| 133 | |||
| 134 | $tag = new Tag("[url title=\"This is a test\" \n\t href=\"example.org\"\n ]", $handlers); |
||
| 135 | |||
| 136 | $this->assertEquals('url', $tag->getName()); |
||
| 137 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 138 | $this->assertEquals('href,title', implode(',', array_keys($tag->getAttributes()))); |
||
| 139 | $this->assertEquals(array('href' => 'example.org', 'title' => 'This is a test'), $tag->getAttributes()); |
||
| 140 | $this->assertEquals("[url title=\"This is a test\" \n\t href=\"example.org\"\n ]", $tag->getRawData()); |
||
| 141 | $this->assertEquals(true, $tag->isValid()); |
||
| 142 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 143 | |||
| 144 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 145 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 146 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 147 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 148 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 149 | |||
| 150 | |||
| 151 | |||
| 152 | $tag = new Tag("[URl tItLE=\"This is a test\" \n\t HRef=\"example.org\"\n ]", $handlers); |
||
| 153 | |||
| 154 | $this->assertEquals('url', $tag->getName()); |
||
| 155 | $this->assertEquals(false, $tag->isClosingTag()); |
||
| 156 | $this->assertEquals('href,title', implode(',', array_keys($tag->getAttributes()))); |
||
| 157 | $this->assertEquals(array('href' => 'example.org', 'title' => 'This is a test'), $tag->getAttributes()); |
||
| 158 | $this->assertEquals("[URl tItLE=\"This is a test\" \n\t HRef=\"example.org\"\n ]", $tag->getRawData()); |
||
| 159 | $this->assertEquals(true, $tag->isValid()); |
||
| 160 | $this->assertEquals(true, $tag->isOfType(Parser::TAG_INLINE)); |
||
| 161 | |||
| 162 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_OUTLINE)); |
||
| 163 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_PRE)); |
||
| 164 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_SINGLE)); |
||
| 165 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_CLEAR_CONTENT)); |
||
| 166 | $this->assertEquals(false, $tag->isOfType(Parser::TAG_FORCE_PARAGRAPHS)); |
||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | $tag = new Tag('[ url="example.org"]', $handlers); |
||
| 171 | $this->assertEquals(false, $tag->isValid()); |
||
| 172 | |||
| 173 | $tag = new Tag('[url = "example.org" ]', $handlers); |
||
| 174 | $this->assertEquals(true, $tag->isValid()); |
||
| 175 | |||
| 176 | $tag = new Tag('[/ url]', $handlers); |
||
| 177 | $this->assertEquals(false, $tag->isValid()); |
||
| 178 | |||
| 179 | $tag = new Tag('[/url ]', $handlers); |
||
| 180 | $this->assertEquals(true, $tag->isValid()); |
||
| 181 | |||
| 182 | $tag = new Tag('[/uRL ]', $handlers); |
||
| 183 | $this->assertEquals(true, $tag->isValid()); |
||
| 184 | } |
||
| 185 | } |
||
| 186 |