Conditions | 15 |
Paths | 12 |
Total Lines | 52 |
Code Lines | 35 |
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 |
||
23 | public static function add_links_to_fields($obj, $fields) |
||
24 | { |
||
25 | if (!isset(self::$completion_array[$obj->ClassName])) { |
||
26 | self::$completion_array[$obj->ClassName] = true; |
||
27 | if ($obj->exists()) { |
||
28 | $fieldLabels = array_merge($obj->FieldLabels(), (array)$obj->Config()->get("field_labels")); |
||
29 | $hasOneLinks = $obj->Config()->get("has_one"); |
||
30 | if (is_array($hasOneLinks) && count($hasOneLinks)) { |
||
31 | $linkTabName = Config::inst()->get("LinkThroughInCMS", "tab_name_for_link"); |
||
32 | $fields->addFieldToTab($linkTabName, new LiteralField("YouAreLookingAt", '<h2>This objects links to ...</h2>')); |
||
33 | foreach ($hasOneLinks as $methodName => $className) { |
||
34 | $dbFieldName = $methodName."ID"; |
||
35 | $label = isset($fieldLabels[$methodName]) ? $fieldLabels[$methodName] : null; |
||
36 | if ($obj->$dbFieldName && $relationObject = $obj->$methodName()) { |
||
37 | if (! in_array($relationObject->ClassName, Config::inst()->get("LinkThroughInCMS", "excluded_has_one_classes"))) { |
||
38 | $fields->addFieldToTab( |
||
39 | $linkTabName, |
||
40 | LiteralField::create( |
||
41 | "LinkThroughFor".$relationObject->ClassName.$relationObject->ID, |
||
42 | '<h3><a href="'.$relationObject->CMSEditLink().'" target="_blank">open related '.$label.'</a></h3>' |
||
43 | ) |
||
44 | ); |
||
45 | } |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | $castedVariables = $obj->Config()->get("casting"); |
||
50 | if (is_array($castedVariables) && count($castedVariables)) { |
||
51 | $calcTabName = Config::inst()->get("LinkThroughInCMS", "tab_name_for_calc"); |
||
52 | $fields->addFieldToTab( |
||
53 | $calcTabName, |
||
54 | LiteralField::create( |
||
55 | "CalculatedValuesHeader", |
||
56 | '<h2>'.Config::inst()->get("LinkThroughInCMS", "heading_for_casted_variables").'</h2>' |
||
57 | ) |
||
58 | ); |
||
59 | foreach ($castedVariables as $castedVariableName => $castedVariableType) { |
||
60 | if (!in_array($castedVariableName, Config::inst()->get("LinkThroughInCMS", "excluded_casted_variables"))) { |
||
61 | $label = isset($fieldLabels[$castedVariableName]) ? $fieldLabels[$castedVariableName] : null; |
||
62 | $fields->addFieldToTab( |
||
63 | $calcTabName, |
||
64 | ReadonlyField::create( |
||
65 | $castedVariableName, |
||
66 | $label |
||
67 | ) |
||
68 | ); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 |
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.