| Conditions | 5 |
| Paths | 12 |
| Total Lines | 108 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 24 | ||
| Bugs | 6 | Features | 2 |
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); |
||
| 68 | function kitchenSink($frameworkName, string $templateName) |
||
| 69 | { |
||
| 70 | $framework = FrameworkComposer::create($frameworkName); |
||
| 71 | $head = $framework->htmlHead(); |
||
| 72 | $footer = $framework->htmlFooter(); |
||
| 73 | |||
| 74 | /* |
||
| 75 | * kitchen sink fields |
||
| 76 | */ |
||
| 77 | $fields = []; |
||
| 78 | $datatypes = Formularium::getDatatypeNames(); |
||
| 79 | |||
| 80 | // make a default for all types |
||
| 81 | foreach ($datatypes as $d) { |
||
| 82 | try { |
||
| 83 | DatatypeFactory::factory($d); |
||
| 84 | $fields[$d] = [ |
||
| 85 | 'datatype' => $d, |
||
| 86 | 'renderable' => [ |
||
| 87 | Renderable::LABEL => 'Type ' . $d |
||
| 88 | ], |
||
| 89 | ]; |
||
| 90 | } catch (ClassNotFoundException $e) { |
||
| 91 | // Abstract class |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | /* |
||
| 96 | * basic demo fiels |
||
| 97 | */ |
||
| 98 | $basicFields = [ |
||
| 99 | 'myString' => [ |
||
| 100 | 'datatype' => 'string', |
||
| 101 | 'validators' => [ |
||
| 102 | MinLength::class => [ 'value' => 3], |
||
| 103 | MaxLength::class => [ 'value' => 30], |
||
| 104 | ], |
||
| 105 | 'renderable' => [ |
||
| 106 | Renderable::LABEL => 'Type string', |
||
| 107 | Renderable::COMMENT => 'Some text explaining this field', |
||
| 108 | Renderable::PLACEHOLDER => "Type here", |
||
| 109 | Renderable::SIZE => Renderable::SIZE_LARGE, |
||
| 110 | Renderable::ICON_PACK => 'fas', |
||
| 111 | Renderable::ICON => 'fa-check' |
||
| 112 | ], |
||
| 113 | ], |
||
| 114 | 'myInteger' => [ |
||
| 115 | 'datatype' => 'integer', |
||
| 116 | 'validators' => [ |
||
| 117 | Min::class => [ 'value' => 4], |
||
| 118 | Max::class => [ 'value' => 40], |
||
| 119 | ], |
||
| 120 | 'renderable' => [ |
||
| 121 | Renderable_number::STEP => 2, |
||
| 122 | Renderable::LABEL => 'Type integer', |
||
| 123 | Renderable::PLACEHOLDER => "Type here" |
||
| 124 | ], |
||
| 125 | ], |
||
| 126 | 'countrycodeselect' => [ |
||
| 127 | 'datatype' => 'countrycodeISO3', |
||
| 128 | 'renderable' => [ |
||
| 129 | Renderable_choice::FORMAT_CHOOSER => Renderable_choice::FORMAT_CHOOSER_SELECT, |
||
| 130 | Renderable::LABEL => 'Country code - select choice' |
||
| 131 | ], |
||
| 132 | ], |
||
| 133 | ]; |
||
| 134 | |||
| 135 | // generate basic model |
||
| 136 | $basicModel = Model::fromStruct( |
||
| 137 | [ |
||
| 138 | 'name' => 'BasicModel', |
||
| 139 | 'fields' => $basicFields |
||
| 140 | ] |
||
| 141 | ); |
||
| 142 | $basicDemoEditable = $basicModel->editable($framework, []); |
||
| 143 | |||
| 144 | // generate kitchen sink model |
||
| 145 | $model = Model::fromStruct( |
||
| 146 | [ |
||
| 147 | 'name' => 'TestModel', |
||
| 148 | 'fields' => $fields |
||
| 149 | ] |
||
| 150 | ); |
||
| 151 | $randomData = []; |
||
| 152 | foreach ($model->getFields() as $f) { |
||
| 153 | if ($f->getDatatype()->getBasetype() !== 'constant') { |
||
| 154 | $randomData[$f->getName()] = $f->getDatatype()->getRandom(); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | $modelViewable = $model->viewable($framework, $randomData); |
||
| 158 | $modelEditable = $model->editable($framework); |
||
| 159 | |||
| 160 | $title = join('/', $frameworkName); |
||
| 161 | $template = file_get_contents(__DIR__ . '/kitchentemplates/' . $templateName); |
||
| 162 | |||
| 163 | $template = strtr( |
||
| 164 | $template, |
||
| 165 | [ |
||
| 166 | '{{title}}' => $title, |
||
| 167 | '{{head}}' => $head, |
||
| 168 | '{{basicDemoEditable}}' => $basicDemoEditable, |
||
| 169 | '{{elements}}' => elements($framework), |
||
| 170 | '{{modelViewable}}' => $modelViewable, |
||
| 171 | '{{modelEditable}}' => $modelEditable, |
||
| 172 | '{{footer}}' => $footer, |
||
| 173 | ] |
||
| 174 | ); |
||
| 175 | return $template; |
||
| 176 | } |
||
| 238 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.