| Conditions | 21 |
| Paths | 17 |
| Total Lines | 83 |
| Code Lines | 57 |
| 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 |
||
| 105 | public function listofobjectsused($request) |
||
| 106 | { |
||
| 107 | $classWeAreLookingFor = $request->param("ID"); |
||
| 108 | $classWeAreLookingFor = singleton($classWeAreLookingFor); |
||
| 109 | if ($classWeAreLookingFor instanceof DataObject) { |
||
| 110 | $list = $this->ListOfAllClasses(); |
||
| 111 | foreach ($list as $item) { |
||
| 112 | $config = Config::inst(); |
||
| 113 | $listOfImages = $config->get($item->ClassName, "has_one") |
||
| 114 | + $config->get($item->ClassName, "has_many") |
||
| 115 | + $config->get($item->ClassName, "many_many"); |
||
| 116 | foreach ($listOfImages as $fieldName => $potentialImage) { |
||
| 117 | $innerSingleton = singleton($potentialImage); |
||
| 118 | if ($innerSingleton instanceof $classWeAreLookingFor) { |
||
| 119 | DB::alteration_message($item->ClassName.".". $fieldName); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } else { |
||
| 124 | user_error("Please specify the ID for the model you are looking for - e.g. /listofobjectsused/Image/", E_USER_ERROR); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 |
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.