Conditions | 17 |
Paths | 144 |
Total Lines | 93 |
Code Lines | 63 |
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 |
||
69 | public function performAction() |
||
70 | { |
||
71 | $schema = new Schema(); |
||
72 | |||
73 | if ($this->schema) { |
||
74 | $schemaDataOrig = $this->readData($this->schema); |
||
75 | $schemaData = $schemaDataOrig; |
||
76 | |||
77 | $resolver = new ResolverMux(); |
||
78 | |||
79 | if (!empty($this->ptrInSchema)) { |
||
80 | $baseName = basename($this->schema); |
||
81 | $preloaded = new Preloaded(); |
||
82 | $preloaded->setSchemaData($baseName, $schemaData); |
||
83 | $resolver->resolvers[] = $preloaded; |
||
84 | $schemaData = (object)[Schema::PROP_REF => $baseName . $this->ptrInSchema]; |
||
85 | } |
||
86 | |||
87 | $resolver->resolvers[] = new BasicFetcher(); |
||
88 | |||
89 | try { |
||
90 | $schemaContract = Schema::import($schemaData, new Context($resolver)); |
||
91 | if ($schemaContract instanceof Schema) { |
||
92 | $schema = $schemaContract; |
||
93 | } |
||
94 | } catch (InvalidValue $e) { |
||
95 | $this->response->error('Invalid schema'); |
||
96 | $this->response->addContent($e->getMessage()); |
||
97 | throw new ExitCode('', 1); |
||
98 | } catch (\Exception $e) { |
||
99 | $this->response->error('Failed to import schema:' . $e->getMessage()); |
||
100 | throw new ExitCode('', 1); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | $maker = new JsonSchemaFromInstance($schema); |
||
105 | $maker->options->useXNullable = $this->useXNullable; |
||
106 | $maker->options->useNullable = $this->useNullable; |
||
107 | $maker->options->defsPtr = $this->defsPtr; |
||
108 | |||
109 | if ($this->jsonl) { |
||
110 | $pathInData = []; |
||
111 | if ($this->ptrInData) { |
||
112 | $pathInData = JsonPointer::splitPath($this->ptrInData); |
||
113 | } |
||
114 | |||
115 | $handle = fopen($this->data, "r"); |
||
116 | if ($handle) { |
||
117 | while (($buffer = fgets($handle)) !== false) { |
||
118 | $item = json_decode($buffer); |
||
119 | if ($this->ptrInData) { |
||
120 | $item = JsonPointer::get($item, $pathInData); |
||
121 | } |
||
122 | $maker->addInstanceValue($item); |
||
123 | } |
||
124 | if (!feof($handle)) { |
||
125 | echo "Error: unexpected fgets() fail\n"; |
||
126 | } |
||
127 | fclose($handle); |
||
128 | } |
||
129 | } else { |
||
130 | $data = $this->readData($this->data); |
||
131 | $maker->addInstanceValue($data); |
||
132 | } |
||
133 | |||
134 | |||
135 | $s = Schema::export($schema); |
||
136 | $this->out = $s; |
||
137 | |||
138 | if ($this->ptrInSchema && isset($schemaDataOrig)) { |
||
139 | $tmp = json_encode($schemaDataOrig); |
||
140 | if ($tmp === false) { |
||
141 | throw new ExitCode('Failed to encode JSON', 1); |
||
142 | } |
||
143 | $schemaDataResult = json_decode($tmp); |
||
144 | |||
145 | $defs = JsonPointer::get($s, JsonPointer::splitPath(rtrim($this->defsPtr, '/'))); |
||
146 | foreach ($defs as $name => $def) { |
||
147 | JsonPointer::add($schemaDataResult, JsonPointer::splitPath($this->defsPtr . $name), $def); |
||
148 | } |
||
149 | JsonPointer::remove($s, JsonPointer::splitPath(rtrim($this->defsPtr, '/'))); |
||
150 | JsonPointer::add($schemaDataResult, JsonPointer::splitPath($this->ptrInSchema), $s); |
||
151 | |||
152 | $tmp = json_encode($schemaDataResult); |
||
153 | if ($tmp === false) { |
||
154 | throw new ExitCode('Failed to encode JSON', 1); |
||
155 | } |
||
156 | $schemaDataResult = json_decode($tmp); |
||
157 | $diff = new JsonDiff($schemaDataOrig, $schemaDataResult, JsonDiff::REARRANGE_ARRAYS); |
||
158 | $this->out = $diff->getRearranged(); |
||
159 | } |
||
160 | |||
161 | $this->postPerform(); |
||
162 | } |
||
163 | } |
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..