| Conditions | 15 |
| Paths | 14 |
| Total Lines | 79 |
| Code Lines | 55 |
| 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 |
||
| 73 | public function performAction() |
||
| 74 | { |
||
| 75 | try { |
||
| 76 | $skipRoot = false; |
||
| 77 | $baseName = null; |
||
| 78 | $schema = $this->loadSchema($skipRoot, $baseName); |
||
| 79 | |||
| 80 | $appPath = realpath($this->nsPath); |
||
| 81 | if (!$appPath) { |
||
| 82 | $this->response->error('Could not find directory ' . $this->nsPath); |
||
| 83 | throw new ExitCode('', 1); |
||
| 84 | } |
||
| 85 | $appNs = $this->ns; |
||
| 86 | |||
| 87 | $app = new PhpApp(); |
||
| 88 | $app->setNamespaceRoot($appNs, '.'); |
||
| 89 | |||
| 90 | $builder = new PhpBuilder(); |
||
| 91 | $builder->buildSetters = $this->setters; |
||
| 92 | $builder->buildGetters = $this->getters; |
||
| 93 | |||
| 94 | $builder->makeEnumConstants = !$this->noEnumConst; |
||
| 95 | $builder->declarePropertyDefaults = $this->declarePropertyDefaults; |
||
| 96 | $builder->buildAdditionalPropertyMethodsOnTrue = $this->buildAdditionalPropertiesAccessors; |
||
| 97 | |||
| 98 | $builder->classCreatedHook = new ClassHookCallback(function (PhpClass $class, $path, $schema) |
||
| 99 | use ($app, $appNs, $skipRoot, $baseName) { |
||
| 100 | if ($skipRoot && '#' === $path) { |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | $desc = ''; |
||
| 105 | if ($schema->title) { |
||
| 106 | $desc = $schema->title; |
||
| 107 | } |
||
| 108 | if ($schema->description) { |
||
| 109 | $desc .= "\n" . $schema->description; |
||
| 110 | } |
||
| 111 | if ($fromRefs = $schema->getFromRefs()) { |
||
| 112 | $desc .= "\nBuilt from " . implode("\n" . ' <- ', $fromRefs); |
||
| 113 | } |
||
| 114 | $class->setDescription(trim($desc)); |
||
| 115 | |||
| 116 | $class->setNamespace($appNs); |
||
| 117 | if ('#' === $path) { |
||
| 118 | $class->setName($this->rootName); |
||
| 119 | } else { |
||
| 120 | if (!empty($fromRefs)) { |
||
| 121 | $path = $fromRefs[0]; |
||
| 122 | } |
||
| 123 | foreach ($this->defPtr as $defPtr) { |
||
| 124 | if (isset($baseName)) { |
||
| 125 | $baseNameDefPtr = $baseName . $defPtr; |
||
| 126 | if ($baseNameDefPtr === substr($path, 0, strlen($baseNameDefPtr))) { |
||
| 127 | $path = substr($path, strlen($baseNameDefPtr)); |
||
| 128 | $className = PhpCode::makePhpClassName($path); |
||
| 129 | $class->setName($className); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($defPtr === substr($path, 0, strlen($defPtr))) { |
||
| 134 | $className = PhpCode::makePhpClassName(substr($path, strlen($defPtr))); |
||
| 135 | $class->setName($className); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | $app->addClass($class); |
||
| 140 | }); |
||
| 141 | |||
| 142 | if (!$schema instanceof Schema) { |
||
| 143 | $this->response->error('failed to assert Schema type, ' . get_class($schema) . ' received'); |
||
| 144 | throw new ExitCode('', 1); |
||
| 145 | } |
||
| 146 | $builder->getType($schema); |
||
| 147 | $app->store($appPath); |
||
| 148 | $this->response->success("Classes are generated in " . $appPath); |
||
| 149 | } catch (\Exception $e) { |
||
| 150 | $this->response->error($e->getMessage()); |
||
| 151 | throw new ExitCode('', 1); |
||
| 152 | } |
||
| 154 | } |
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..