Conditions | 15 |
Paths | 15 |
Total Lines | 74 |
Code Lines | 51 |
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 |
||
50 | public function performAction() |
||
51 | { |
||
52 | try { |
||
53 | $skipRoot = false; |
||
54 | $baseName = null; |
||
55 | $schema = $this->loadSchema($skipRoot, $baseName); |
||
56 | |||
57 | $appPath = realpath($this->nsPath); |
||
58 | if (!$appPath) { |
||
59 | $this->response->error('Could not find directory ' . $this->nsPath); |
||
60 | throw new ExitCode('', 1); |
||
61 | } |
||
62 | $appNs = $this->ns; |
||
63 | |||
64 | $app = new PhpApp(); |
||
65 | $app->setNamespaceRoot($appNs, '.'); |
||
66 | |||
67 | $builder = new PhpBuilder(); |
||
68 | $this->setupBuilder($builder); |
||
69 | |||
70 | $builder->classCreatedHook = new ClassHookCallback(function (PhpClass $class, $path, $schema) |
||
71 | use ($app, $appNs, $skipRoot, $baseName) { |
||
72 | if ($skipRoot && '#' === $path) { |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $desc = ''; |
||
77 | if ($schema->title) { |
||
78 | $desc = $schema->title; |
||
79 | } |
||
80 | if ($schema->description) { |
||
81 | $desc .= "\n" . $schema->description; |
||
82 | } |
||
83 | if ($fromRefs = $schema->getFromRefs()) { |
||
84 | $desc .= "\nBuilt from " . implode("\n" . ' <- ', $fromRefs); |
||
85 | } |
||
86 | $class->setDescription(trim($desc)); |
||
87 | |||
88 | $class->setNamespace($appNs); |
||
89 | if ('#' === $path) { |
||
90 | $class->setName($this->rootName); |
||
91 | } else { |
||
92 | if (!empty($fromRefs)) { |
||
93 | $path = $fromRefs[0]; |
||
94 | } |
||
95 | foreach ($this->defPtr as $defPtr) { |
||
96 | if (isset($baseName)) { |
||
97 | $baseNameDefPtr = $baseName . $defPtr; |
||
98 | if ($baseNameDefPtr === substr($path, 0, strlen($baseNameDefPtr))) { |
||
99 | $path = substr($path, strlen($baseNameDefPtr)); |
||
100 | $className = PhpCode::makePhpClassName($path); |
||
101 | $class->setName($className); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | if ($defPtr === substr($path, 0, strlen($defPtr))) { |
||
106 | $className = PhpCode::makePhpClassName(substr($path, strlen($defPtr))); |
||
107 | $class->setName($className); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | $app->addClass($class); |
||
112 | }); |
||
113 | |||
114 | if (!$schema instanceof Schema) { |
||
115 | $this->response->error('failed to assert Schema type, ' . get_class($schema) . ' received'); |
||
116 | throw new ExitCode('', 1); |
||
117 | } |
||
118 | $builder->getType($schema); |
||
119 | $app->store($appPath); |
||
120 | $this->response->success("Classes are generated in " . $appPath); |
||
121 | } catch (\Exception $e) { |
||
122 | $this->response->error($e->getMessage()); |
||
123 | throw new ExitCode('', 1); |
||
124 | } |
||
126 | } |
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..