| Conditions | 3 |
| Paths | 3 |
| Total Lines | 86 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 declare(strict_types=1); |
||
| 207 | function main() |
||
| 208 | { |
||
| 209 | @mkdir(__DIR__ . '/../docs/'); |
||
| 210 | @mkdir(__DIR__ . '/../docs/kitchensink/'); |
||
| 211 | $path = __DIR__ . '/../Formularium/Frontend/'; |
||
| 212 | $dir = scandir($path); |
||
| 213 | if ($dir === false) { |
||
| 214 | echo 'Cannot find frontend'; |
||
| 215 | return 1; |
||
| 216 | } |
||
| 217 | $frameworks = array_diff($dir, array('.', '..')); |
||
| 218 | $index = <<<EOF |
||
| 219 | <!DOCTYPE html> |
||
| 220 | <html> |
||
| 221 | <head> |
||
| 222 | <head> |
||
| 223 | <meta charset="UTF-8"> |
||
| 224 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||
| 225 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
||
| 226 | |||
| 227 | <title>Formularium Kitchen Sink</title> |
||
| 228 | <meta property="og:title" content="Formularium"> |
||
| 229 | <meta property="og:locale" content="en_US"> |
||
| 230 | <meta name="description" content="Form validation and generation for PHP with custom frontend generators"> |
||
| 231 | <meta property="og:description" content="Form validation and generation for PHP with custom frontend generators"> |
||
| 232 | <link rel="canonical" href="https://corollarium.github.io/Formularium/"> |
||
| 233 | <meta property="og:url" content="https://corollarium.github.io/Formularium/"> |
||
| 234 | <meta property="og:site_name" content="Formularium"> |
||
| 235 | <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> |
||
| 236 | </head> |
||
| 237 | <body> |
||
| 238 | <div class="container"> |
||
| 239 | <h1>Formularium Examples</h1> |
||
| 240 | <p>These files are all automatically generated from the same data models, using different frameworks.</p> |
||
| 241 | |||
| 242 | <div> |
||
| 243 | EOF; |
||
| 244 | $frameworks = [ |
||
| 245 | ['framework' => ['HTML', 'HTMLValidation', 'Quill'], 'template' => 'base'], |
||
| 246 | ['framework' => ['HTML', 'HTMLValidation', 'Bulma', 'Quill'], 'template' => 'bulma'], |
||
| 247 | ['framework' => ['HTML', 'HTMLValidation', 'Bootstrap', 'Quill'], 'template' => 'base'], |
||
| 248 | ['framework' => ['HTML', 'HTMLValidation', 'Bootstrap', 'Quill', 'Parsley'], 'template' => 'base'], |
||
| 249 | ['framework' => ['HTML', 'HTMLValidation', 'Bootstrap', 'Vue', 'Vuelidate'], 'template' => 'base'], |
||
| 250 | ['framework' => ['HTML', 'HTMLValidation', 'Bootstrapvue', 'Vue'], 'template' => 'base'], |
||
| 251 | ['framework' => ['HTML', 'HTMLValidation', 'Materialize'], 'template' => 'base'], |
||
| 252 | ['framework' => ['HTML', 'HTMLValidation', 'Bulma', 'Quill', 'Vue'], 'template' => 'bulma'], |
||
| 253 | ['framework' => ['HTML', 'HTMLValidation', 'Bootstrap', 'Vue'], 'template' => 'base'], |
||
| 254 | ['framework' => ['HTML', 'HTMLValidation', 'Buefy', 'Vue'], 'template' => 'bulma'], |
||
| 255 | ['framework' => ['HTML', 'HTMLValidation', 'React'], 'template' => 'base'], |
||
| 256 | ['framework' => ['HTML', 'HTMLValidation', 'Bootstrap', 'React'], 'template' => 'base'], |
||
| 257 | ['framework' => ['HTML', 'HTMLValidation', 'Vuetify', 'Vue'], 'template' => 'base'], |
||
| 258 | ]; |
||
| 259 | foreach ($frameworks as $f) { |
||
| 260 | $name = join('', $f['framework']); |
||
| 261 | $prettyName = join(' + ', array_slice($f['framework'], 2)); |
||
| 262 | echo "Building $name...\n"; |
||
| 263 | |||
| 264 | $index .= "<h2>$prettyName</h2><ul>"; |
||
| 265 | |||
| 266 | $html = generateBase($f['framework'], $f['template'] . '_demo.html'); |
||
| 267 | $filename = __DIR__ . '/../docs/kitchensink/demo_' . $name . '.html'; |
||
| 268 | file_put_contents($filename, $html); |
||
| 269 | $index .= "<li><a href='{$filename}'>Basic example</a></li>"; |
||
| 270 | |||
| 271 | $html = generateElements($f['framework'], $f['template'] . '_demo.html'); |
||
| 272 | $filename = __DIR__ . '/../docs/kitchensink/elements_' . $name . '.html'; |
||
| 273 | file_put_contents($filename, $html); |
||
| 274 | $index .= "<li><a href='{$filename}'>Elements</a></li>"; |
||
| 275 | |||
| 276 | $html = kitchenSink($f['framework'], $f['template'] . '_demo.html'); |
||
| 277 | $filename = __DIR__ . '/../docs/kitchensink/editable_' . $name . '.html'; |
||
| 278 | file_put_contents($filename, $html); |
||
| 279 | $index .= "<li><a href='{$filename}'>Editable (all types)</a></li>"; |
||
| 280 | |||
| 281 | // $html = kitchenSink($f['framework'], $f['template']); |
||
| 282 | // file_put_contents(__DIR__ . '/../docs/kitchensink/' . $name . '.html', $html); |
||
| 283 | |||
| 284 | $index .= "</ul>"; |
||
| 285 | } |
||
| 286 | $index .= "</div> |
||
| 287 | <footer> |
||
| 288 | <a href='https://github.com/Corollarium/Formularium/'>Source code</a> and <a href='https://corollarium.github.io/Formularium/'>Documentation</a> |
||
| 289 | </footer> |
||
| 290 | </div> |
||
| 291 | </body></html>"; |
||
| 292 | file_put_contents(__DIR__ . '/../docs/kitchensink/index.html', $index); |
||
| 293 | } |
||
| 296 |