Conditions | 23 |
Paths | 64 |
Total Lines | 93 |
Code Lines | 71 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
120 | public function requireDefaultRecords() |
||
121 | { |
||
122 | parent::requireDefaultRecords(); |
||
123 | $data = ClassInfo::subclassesFor("SiteTree"); |
||
124 | $fileList = null; |
||
125 | if ($this->Config()->get("image_source_folder")) { |
||
126 | $fileList = CMSHelp::get_list_of_files($this->Config()->get("image_source_folder")); |
||
127 | if (!is_array($fileList)) { |
||
128 | $fileList = null; |
||
129 | } elseif (!count($fileList)) { |
||
130 | $fileList = null; |
||
131 | } |
||
132 | } |
||
133 | if ($fileList) { |
||
134 | $destinationDir = Director::baseFolder()."/assets/".$this->Config()->get("image_folder_name")."/"; |
||
135 | $destinationFolder = Folder::find_or_make($this->Config()->get("image_folder_name")); |
||
136 | } |
||
137 | if ($data) { |
||
138 | foreach ($data as $className) { |
||
139 | $object = TemplateoverviewDescription::get() |
||
140 | ->filter(array("ClassNameLink" => $className))->First(); |
||
141 | if (!$object) { |
||
142 | $object = new TemplateoverviewDescription(); |
||
143 | $object->ClassNameLink = $className; |
||
144 | $object->write(); |
||
145 | DB::alteration_message("adding template description for $className", "created"); |
||
146 | } else { |
||
147 | $otherObjects = TemplateoverviewDescription::get() |
||
148 | ->filter(array("ClassNameLink" => $className))->exclude(array("ID" => $object->ID)); |
||
149 | foreach ($otherObjects as $otherObject) { |
||
150 | DB::alteration_message("Deleting superfluous TemplateoverviewDescription with Class Name Link: $className", "deleted"); |
||
151 | $otherObject->delete(); |
||
152 | } |
||
153 | } |
||
154 | if ($fileList) { |
||
155 | $i = 0; |
||
156 | foreach ($fileList as $fileArray) { |
||
157 | $explodeByDot = explode(".", $fileArray["FileName"]); |
||
158 | if (is_array($explodeByDot) && count($explodeByDot)) { |
||
159 | $base = $explodeByDot[0]; |
||
160 | $explodeByUnderscore = explode("_", $base); |
||
161 | if (is_array($explodeByUnderscore) && count($explodeByUnderscore)) { |
||
162 | $base = $explodeByUnderscore[0]; |
||
163 | $classNameOptionArray = array($className); |
||
164 | for ($j = 0; $j < 10; $j++) { |
||
165 | $classNameOptionArray[] = $className.$j; |
||
166 | } |
||
167 | foreach ($classNameOptionArray as $potentialBase) { |
||
168 | if ($base == $potentialBase) { |
||
169 | $i++; |
||
170 | $filename = "".$this->Config()->get("image_folder_name")."/".$fileArray["FileName"]; |
||
171 | if (!file_exists($destinationDir.$fileArray["FileName"])) { |
||
172 | copy($fileArray["FullLocation"], $destinationDir.$fileArray["FileName"]); |
||
173 | } |
||
174 | $image = $Image::get() |
||
175 | ->filter(array("ParentID" => $destinationFolder->ID, "Name" => $fileArray["FileName"]))->First(); |
||
176 | if (!$image) { |
||
177 | $image = new Image(); |
||
178 | $image->ParentID = $destinationFolder->ID; |
||
179 | $image->Filename = $filename; |
||
180 | $image->Name = $fileArray["FileName"]; |
||
181 | $image->Title = $fileArray["Title"]; |
||
182 | $image->write(); |
||
183 | } |
||
184 | $fieldName = "Image$i"."ID"; |
||
185 | if ($object->$fieldName != $image->ID) { |
||
186 | $object->$fieldName = $image->ID; |
||
187 | $object->write(); |
||
188 | DB::alteration_message("adding image to $className: ".$image->Title." (".$image->Filename.") using $fieldName field.", "created"); |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | } else { |
||
196 | DB::alteration_message("no design images found for $className", "deleted"); |
||
197 | } |
||
198 | } |
||
199 | } |
||
200 | $helpDirectory = Director::baseFolder()."/".Config::inst()->get("CMSHelp", "help_file_directory_name")."/"; |
||
201 | if (!file_exists($helpDirectory)) { |
||
202 | mkdir($helpDirectory); |
||
203 | } |
||
204 | $this->createManifestExcludeFile($helpDirectory); |
||
205 | |||
206 | $devDirectory = Director::baseFolder()."/".Config::inst()->get("CMSHelp", "dev_file_directory_name")."/"; |
||
207 | if (!file_exists($devDirectory)) { |
||
208 | mkdir($devDirectory); |
||
209 | } |
||
210 | $this->createManifestExcludeFile($devDirectory); |
||
211 | $this->createHTACCESSDenyAll($devDirectory); |
||
212 | } |
||
213 | |||
261 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.