Conditions | 10 |
Paths | 62 |
Total Lines | 48 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 1 | Features | 1 |
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 |
||
31 | public function getModel($model = null) |
||
32 | { |
||
33 | if ($model === null) { |
||
34 | $model = $this->crudApi->model; |
||
35 | } |
||
36 | |||
37 | if ($model === null) { |
||
38 | return false; |
||
39 | } |
||
40 | |||
41 | // Make Sure model name is uppercased. |
||
42 | $model = ucfirst($model); |
||
43 | |||
44 | // If namespace is not detected or set then set to the laravel default of App. |
||
45 | if ($this->crudApi->namespace === null) { |
||
46 | $this->crudApi->setNamespace('App\\'); |
||
47 | } |
||
48 | |||
49 | |||
50 | // Test conventional namespace model combinations |
||
51 | $conventions = [ |
||
52 | $this->crudApi->namespace . $model, |
||
53 | $this->crudApi->namespace . 'Models\\' . $model |
||
54 | ]; |
||
55 | |||
56 | foreach ($conventions as $fqModel) { |
||
57 | if (class_exists($fqModel)) { |
||
58 | return $fqModel; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | try { |
||
63 | // If not conventional, try configurable |
||
64 | $additionalNamespaces = $this->getAdditionalNamespaces(); |
||
65 | if (!empty($additionalNamespaces)) { |
||
66 | foreach ($additionalNamespaces as $ns) { |
||
67 | $fqModel = $ns . $model; |
||
68 | if (class_exists($fqModel)) { |
||
69 | return $fqModel; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | } catch (\Exception $e) { |
||
74 | return false; |
||
75 | } |
||
76 | |||
77 | return false; |
||
78 | } |
||
79 | |||
104 |