Conditions | 10 |
Paths | 16 |
Total Lines | 61 |
Code Lines | 37 |
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 audit() |
||
70 | { |
||
71 | $body = ''; |
||
72 | $missing = []; |
||
73 | $subtitle = "Missing Config property definitions"; |
||
74 | |||
75 | foreach ($this->array_keys_recursive(Config::inst()->getAll(), 2) as $className => $props) { |
||
76 | $props = array_keys($props); |
||
77 | |||
78 | if (!count($props)) { |
||
79 | // We can skip this entry |
||
80 | continue; |
||
81 | } |
||
82 | |||
83 | if ($className == strtolower(Injector::class)) { |
||
84 | // We don't want to check the injector config |
||
85 | continue; |
||
86 | } |
||
87 | |||
88 | foreach ($props as $prop) { |
||
89 | $defined = false; |
||
90 | // Check ancestry (private properties don't inherit natively) |
||
91 | foreach (ClassInfo::ancestry($className) as $cn) { |
||
92 | if (property_exists($cn, $prop)) { |
||
93 | $defined = true; |
||
94 | break; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | if ($defined) { |
||
99 | // No need to record this property |
||
100 | continue; |
||
101 | } |
||
102 | |||
103 | $missing[] = sprintf("%s::$%s\n", $className, $prop); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | $output = count($missing) |
||
108 | ? implode("\n", $missing) |
||
109 | : "All configured properties are defined\n"; |
||
110 | |||
111 | if (Director::is_cli()) { |
||
112 | $body .= sprintf("\n%s\n\n", strtoupper($subtitle)); |
||
113 | $body .= $output; |
||
114 | } else { |
||
115 | $renderer = DebugView::create(); |
||
116 | $body .= $renderer->renderHeader(); |
||
117 | $body .= $renderer->renderInfo( |
||
118 | "Configuration", |
||
119 | Director::absoluteBaseURL(), |
||
120 | "Config properties that are not defined (or inherited) by their respective classes" |
||
121 | ); |
||
122 | $body .= "<div class=\"options\">"; |
||
123 | $body .= sprintf("<h2>%s</h2>", $subtitle); |
||
124 | $body .= sprintf("<pre>%s</pre>", $output); |
||
125 | $body .= "</div>"; |
||
126 | $body .= $renderer->renderFooter(); |
||
127 | } |
||
128 | |||
129 | return $this->getResponse()->setBody($body); |
||
130 | } |
||
159 |