| Conditions | 14 |
| Paths | 97 |
| Total Lines | 69 |
| Code Lines | 46 |
| 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 |
||
| 70 | public function performAction() |
||
| 71 | { |
||
| 72 | $dataValue = Base::readJsonOrYaml($this->schema, $this->response); |
||
| 73 | if (!$dataValue) { |
||
| 74 | $this->response->error('Unable to find schema in ' . $this->schema); |
||
| 75 | die(1); |
||
| 76 | } |
||
| 77 | |||
| 78 | $skipRoot = false; |
||
| 79 | if (empty($this->ptrInSchema)) { |
||
| 80 | $schema = Schema::import($dataValue); |
||
| 81 | } else { |
||
| 82 | $baseName = basename($this->schema); |
||
| 83 | $skipRoot = true; |
||
| 84 | $preloaded = new Preloaded(); |
||
| 85 | $preloaded->setSchemaData($baseName, $dataValue); |
||
| 86 | $data = new \stdClass(); |
||
| 87 | foreach ($this->ptrInSchema as $i => $ptr) { |
||
| 88 | $data->oneOf[$i] = (object)[Schema::PROP_REF => $baseName . $ptr]; |
||
| 89 | } |
||
| 90 | $schema = Schema::import($data, new Context($preloaded)); |
||
| 91 | } |
||
| 92 | |||
| 93 | |||
| 94 | $builder = new GoBuilder(); |
||
| 95 | $builder->options->hideConstProperties = !$this->showConstProperties; |
||
| 96 | $builder->options->trimParentFromPropertyNames = !$this->keepParentInPropertyNames; |
||
| 97 | $pathToNameHook = new StripPrefixPathToNameHook(); |
||
| 98 | |||
| 99 | if (!empty($this->defPtr)) { |
||
| 100 | $pathToNameHook->prefixes = []; |
||
| 101 | foreach ($this->defPtr as $defPtr) { |
||
| 102 | if (isset($baseName)) { |
||
| 103 | $pathToNameHook->prefixes[] = $baseName . $defPtr; |
||
| 104 | } |
||
| 105 | $pathToNameHook->prefixes[] = $defPtr; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | if (isset($baseName)) { |
||
| 110 | $pathToNameHook->prefixes[] = $baseName; |
||
| 111 | } |
||
| 112 | |||
| 113 | $builder->pathToNameHook = $pathToNameHook; |
||
| 114 | |||
| 115 | $builder->structCreatedHook = new StructHookCallback(function (StructDef $structDef, $path, $schema) { |
||
| 116 | if ('#' === $path) { |
||
| 117 | $structDef->setName($this->rootName); |
||
| 118 | } |
||
| 119 | }); |
||
| 120 | if ($schema instanceof JsonSchema) { |
||
| 121 | $builder->getType($schema); |
||
| 122 | } |
||
| 123 | |||
| 124 | $goFile = new GoFile($this->packageName); |
||
| 125 | $goFile->fileComment = 'Code generated by github.com/swaggest/json-cli, DO NOT EDIT.'; |
||
| 126 | $goFile->setComment('Package ' . $this->packageName . ' contains JSON mapping structures.'); |
||
| 127 | foreach ($builder->getGeneratedStructs() as $generatedStruct) { |
||
| 128 | if ($skipRoot && $generatedStruct->path === '#') { |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | $goFile->getCode()->addSnippet($generatedStruct->structDef); |
||
| 132 | } |
||
| 133 | $goFile->getCode()->addSnippet($builder->getCode()); |
||
| 134 | |||
| 135 | if ($this->output) { |
||
| 136 | file_put_contents($this->output, $goFile->render()); |
||
| 137 | } else { |
||
| 138 | echo $goFile->render(); |
||
| 139 | } |
||
| 141 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..