| Conditions | 1 |
| Paths | 1 |
| Total Lines | 130 |
| Code Lines | 114 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 47 | public function testRender() |
||
| 48 | { |
||
| 49 | $page = new \Suricate\Page(); |
||
| 50 | $this->assertEquals( |
||
| 51 | '<!DOCTYPE html>' . |
||
| 52 | '<html lang="en">' . |
||
| 53 | '<head>' . |
||
| 54 | '<title></title>' . |
||
| 55 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 56 | '</head>' . |
||
| 57 | '<body>' . |
||
| 58 | '</body>' . |
||
| 59 | '</html>', |
||
| 60 | $page->render() |
||
| 61 | ); |
||
| 62 | |||
| 63 | $page->setTitle('My Pageé'); |
||
| 64 | $this->assertEquals( |
||
| 65 | '<!DOCTYPE html>' . |
||
| 66 | '<html lang="en">' . |
||
| 67 | '<head>' . |
||
| 68 | '<title>My Pageé</title>' . |
||
| 69 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 70 | '</head>' . |
||
| 71 | '<body>' . |
||
| 72 | '</body>' . |
||
| 73 | '</html>', |
||
| 74 | $page->render() |
||
| 75 | ); |
||
| 76 | |||
| 77 | $page->addHtmlClass('class1'); |
||
| 78 | $page->addHtmlClass('class2'); |
||
| 79 | |||
| 80 | $this->assertEquals( |
||
| 81 | '<!DOCTYPE html>' . |
||
| 82 | '<html lang="en" class="class1 class2">' . |
||
| 83 | '<head>' . |
||
| 84 | '<title>My Pageé</title>' . |
||
| 85 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 86 | '</head>' . |
||
| 87 | '<body>' . |
||
| 88 | '</body>' . |
||
| 89 | '</html>', |
||
| 90 | $page->render() |
||
| 91 | ); |
||
| 92 | |||
| 93 | $page->addScript('script-id', 'http://scripturl.com'); |
||
| 94 | $page->addRss('rss-id', 'http://rssurl.com', 'RSS is not dead !'); |
||
| 95 | $page->addStylesheet('css-id', 'http://cssurl.com'); |
||
| 96 | $page->addMeta('metaname', 'metacontent'); |
||
| 97 | $page->addMetaProperty('metapropertyname', 'metapropertycontent'); |
||
| 98 | $page->addMetaLink('metalinkname', 'metalinktype', 'metalinkhref'); |
||
| 99 | |||
| 100 | $this->assertEquals( |
||
| 101 | '<!DOCTYPE html>' . |
||
| 102 | '<html lang="en" class="class1 class2">' . |
||
| 103 | '<head>' . |
||
| 104 | '<title>My Pageé</title>' . |
||
| 105 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 106 | '<meta name="metaname" content="metacontent">' . |
||
| 107 | '<meta property="metapropertyname" content="metapropertycontent">' . |
||
| 108 | '<link rel="metalinktype" href="metalinkhref">' . |
||
| 109 | '<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
||
| 110 | '<script type="text/javascript" src="http://scripturl.com"></script>' . |
||
| 111 | '<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">' . |
||
| 112 | '</head>' . |
||
| 113 | '<body>' . |
||
| 114 | '</body>' . |
||
| 115 | '</html>', |
||
| 116 | $page->render() |
||
| 117 | ); |
||
| 118 | |||
| 119 | $page->addScript('script-id', 'http://scripturl.com', true); |
||
| 120 | $this->assertEquals( |
||
| 121 | '<!DOCTYPE html>' . |
||
| 122 | '<html lang="en" class="class1 class2">' . |
||
| 123 | '<head>' . |
||
| 124 | '<title>My Pageé</title>' . |
||
| 125 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 126 | '<meta name="metaname" content="metacontent">' . |
||
| 127 | '<meta property="metapropertyname" content="metapropertycontent">' . |
||
| 128 | '<link rel="metalinktype" href="metalinkhref">' . |
||
| 129 | '<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
||
| 130 | '<script type="text/javascript" src="http://scripturl.com" async></script>' . |
||
| 131 | '<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">' . |
||
| 132 | '</head>' . |
||
| 133 | '<body>' . |
||
| 134 | '</body>' . |
||
| 135 | '</html>', |
||
| 136 | $page->render() |
||
| 137 | ); |
||
| 138 | |||
| 139 | $page->addScript('script-id', 'http://scripturl.com', false, true); |
||
| 140 | $this->assertEquals( |
||
| 141 | '<!DOCTYPE html>' . |
||
| 142 | '<html lang="en" class="class1 class2">' . |
||
| 143 | '<head>' . |
||
| 144 | '<title>My Pageé</title>' . |
||
| 145 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 146 | '<meta name="metaname" content="metacontent">' . |
||
| 147 | '<meta property="metapropertyname" content="metapropertycontent">' . |
||
| 148 | '<link rel="metalinktype" href="metalinkhref">' . |
||
| 149 | '<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
||
| 150 | '<script type="text/javascript" src="http://scripturl.com" defer></script>' . |
||
| 151 | '<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">'. |
||
| 152 | '</head>'. |
||
| 153 | '<body>'. |
||
| 154 | '</body>'. |
||
| 155 | '</html>', |
||
| 156 | $page->render() |
||
| 157 | ); |
||
| 158 | |||
| 159 | $page->addScript('script-id', 'http://scripturl.com', true, true); |
||
| 160 | $this->assertEquals( |
||
| 161 | '<!DOCTYPE html>' . |
||
| 162 | '<html lang="en" class="class1 class2">' . |
||
| 163 | '<head>' . |
||
| 164 | '<title>My Pageé</title>' . |
||
| 165 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . |
||
| 166 | '<meta name="metaname" content="metacontent">' . |
||
| 167 | '<meta property="metapropertyname" content="metapropertycontent">' . |
||
| 168 | '<link rel="metalinktype" href="metalinkhref">' . |
||
| 169 | '<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all">' . |
||
| 170 | '<script type="text/javascript" src="http://scripturl.com" async defer></script>' . |
||
| 171 | '<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" title="RSS is not dead !">' . |
||
| 172 | '</head>' . |
||
| 173 | '<body>' . |
||
| 174 | '</body>' . |
||
| 175 | '</html>', |
||
| 176 | $page->render() |
||
| 177 | ); |
||
| 180 |