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