Conditions | 15 |
Paths | 172 |
Total Lines | 145 |
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 |
||
21 | public function updateCMSFields(FieldList $fields) |
||
22 | { |
||
23 | parent::updateCMSFields($fields); |
||
24 | $className = $this->owner->ClassName; |
||
|
|||
25 | $uncompletedField = $this->owner->CopyFromFieldName(); |
||
26 | $uncompletedFieldWithID = $uncompletedField."ID"; |
||
27 | $completedField = $this->owner->CopiedFromFieldName(); |
||
28 | $completedFieldWithID = $completedField."ID"; |
||
29 | //remove by default |
||
30 | $fields->removeByName($uncompletedFieldWithID); |
||
31 | $fields->removeByName($completedFieldWithID); |
||
32 | |||
33 | if ( |
||
34 | $this->owner->exists() && |
||
35 | SiteConfig::current_site_config()->AllowCopyingOfRecords && |
||
36 | Permission::check('ADMIN') |
||
37 | ) { |
||
38 | $changeMessage = |
||
39 | "<p class=\"message good\">". |
||
40 | _t("CopyFactory.CHANGE_SETTINGS", "You can change the settings for copying in"). |
||
41 | " <a href=\"/admin/settings/\">"._t("CopyFactory.SITE_CONFIG", "The Site Config (see Copy Tab)")."</a>. ". |
||
42 | _t("CopyFactory.TURN_OFF_WHEN_NOT_IN_USE", "It is recommended you turn off the copy facility when not in use, as it will slow down the CMS.")." |
||
43 | </p>"; |
||
44 | //reload goes here ... @todo |
||
45 | /* |
||
46 | if($this->owner->ID && Session::get("CopyFactoryReload") == $this->owner->ID) { |
||
47 | Session::set("CopyFactoryReload", 0); |
||
48 | return Controller::curr()->redirectBack(); |
||
49 | } |
||
50 | */ |
||
51 | if ($this->owner->$completedFieldWithID) { |
||
52 | if ($obj = $this->owner->$completedField()) { |
||
53 | $fields->addFieldToTab( |
||
54 | "Root.Copy", |
||
55 | new ReadonlyField( |
||
56 | $completedField."_EXPLANATION", |
||
57 | _t("CopyFactory.COPIED_FROM", "This record has been copied from: "), |
||
58 | $this->owner->CopyFactoryTitleMaker($obj) |
||
59 | ) |
||
60 | ); |
||
61 | } |
||
62 | } elseif ($situation = SiteConfig::current_site_config()->AllowCopyingOfRecords) { |
||
63 | if ($situation == 1) { |
||
64 | $message = _t( |
||
65 | 'CopyFactory.DRY_RUN_ONLY', |
||
66 | "Dry run only --- any changes below will be tested once your press 'SAVE' but no actual changes will be made. You will find a log of intended changes below for review." |
||
67 | ); |
||
68 | } |
||
69 | if ($situation == 2) { |
||
70 | $message = _t( |
||
71 | 'CopyFactory.THIS_IS_FOR_REAL', |
||
72 | "Any changes below will be actioned once you press 'SAVE' - please use with care." |
||
73 | ); |
||
74 | } |
||
75 | $fields->addFieldToTab( |
||
76 | "Root.Copy", |
||
77 | $copyField = new LiteralField( |
||
78 | $uncompletedFieldWithID."_WARNING", |
||
79 | "<p class=\"warning message\">".$message."</p>". |
||
80 | $changeMessage |
||
81 | ) |
||
82 | ); |
||
83 | $copyableObjects = $className::get() |
||
84 | ->exclude(array("ID" => intval($this->owner->ID) - 0)) |
||
85 | ->filter(array("ClassName" => $this->owner->ClassName)); |
||
86 | if ($this->owner->hasMethod("additionalFiltersForCopyableObjects")) { |
||
87 | $copyAbleObjects = $this->owner->additionalFiltersForCopyableObjects($copyableObjects); |
||
88 | } |
||
89 | //there are objects to copy from |
||
90 | if ($copyableObjects->count() > 0) { |
||
91 | $fields->addFieldToTab( |
||
92 | "Root.Copy", |
||
93 | $copyField = new DropdownField( |
||
94 | $uncompletedFieldWithID, |
||
95 | _t( |
||
96 | 'CopyFactory.COPY_EXPLANATION', |
||
97 | "Copy from {name}. CAREFUL - this will replace everything in the current {name} with the one copied from ...", |
||
98 | 'Explanation on how copying works', |
||
99 | array('name' => $this->owner->i18n_singular_name()) |
||
100 | ), |
||
101 | $copyableObjects->map("ID", CopyFactory::preferred_title_field($this->owner)) |
||
102 | ) |
||
103 | ); |
||
104 | $copyField->setEmptyString(_t("CopyFactory.SELECT_ONE", "--- Select One ---")); |
||
105 | } else { |
||
106 | $fields->addFieldToTab( |
||
107 | "Root.Copy", |
||
108 | $copyField = new LiteralField( |
||
109 | $uncompletedFieldWithID."_EXPLANATION", |
||
110 | "<h2>". |
||
111 | _t( |
||
112 | 'CopyFactory.COPY_FACTORY_HELP_NO_RECORDS', |
||
113 | "There are no records to copy from." |
||
114 | ). |
||
115 | "</h2>" |
||
116 | ) |
||
117 | ); |
||
118 | } |
||
119 | } else { |
||
120 | $fields->addFieldToTab( |
||
121 | "Root.Copy", |
||
122 | $copyField = new LiteralField( |
||
123 | "CopyFactoryNotTurnedOn", |
||
124 | "<h2>". |
||
125 | _t( |
||
126 | 'CopyFactory.COPY_FACTORY_TURNED_OFF', |
||
127 | "Copying of records is currently turned off." |
||
128 | ). |
||
129 | "</h2>". |
||
130 | $changeMessage |
||
131 | ) |
||
132 | ); |
||
133 | } |
||
134 | if (Config::inst()->get("CopyFactory", "debug")) { |
||
135 | $source = CopyFactoryLog::get() |
||
136 | ->filter(array("CopyCausingClassName" => $this->owner->ClassName, "CopyCausingClassNameID" => $this->owner->ID)) |
||
137 | ->exclude(array("CopyIntoClassName" => $this->owner->ClassName, "CopyIntoClassNameID" => $this->owner->ID)) |
||
138 | ->exclude(array("CopyIntoClassName" => $this->owner->ClassName, "CopyFromClassNameID" => $this->owner->ID)); |
||
139 | if ($source->count()) { |
||
140 | $name = "COPY_CAUSING_GRIDFIELD"; |
||
141 | $title = _t("CopyFactory.COPY_CAUSING_TITLE", "Copy actions originated from this record."); |
||
142 | $fields->addFieldToTab("Root.Copy", $this->gridFieldMaker($name, $title, $source)); |
||
143 | } |
||
144 | $source = CopyFactoryLog::get() |
||
145 | ->filter(array("CopyIntoClassName" => $this->owner->ClassName, "CopyIntoClassNameID" => $this->owner->ID)) |
||
146 | //->exclude(array("CopyCausingClassName" => $this->owner->ClassName, "CopyCausingClassNameID" => $this->owner->ID)) |
||
147 | ->exclude(array("CopyIntoClassName" => $this->owner->ClassName, "CopyFromClassNameID" => $this->owner->ID)); |
||
148 | if ($source->count()) { |
||
149 | $name = "COPY_INTO_GRIDFIELD"; |
||
150 | $title = _t("CopyFactory.COPY_INTO_TITLE", "Copy actioned into this record."); |
||
151 | $fields->addFieldToTab("Root.Copy", $this->gridFieldMaker($name, $title, $source)); |
||
152 | } |
||
153 | $source = CopyFactoryLog::get() |
||
154 | ->filter(array("CopyIntoClassName" => $this->owner->ClassName, "CopyFromClassNameID" => $this->owner->ID)) |
||
155 | ->exclude(array("CopyIntoClassName" => $this->owner->ClassName, "CopyIntoClassNameID" => $this->owner->ID)) |
||
156 | ->exclude(array("CopyCausingClassName" => $this->owner->ClassName, "CopyCausingClassNameID" => $this->owner->ID)); |
||
157 | if ($source->count()) { |
||
158 | $name = "COPY_FROM_GRIDFIELD"; |
||
159 | $title = _t("CopyFactory.COPY_FROM_TITLE", "Copy actions from this record into another record."); |
||
160 | $fields->addFieldToTab("Root.Copy", $this->gridFieldMaker($name, $title, $source)); |
||
161 | } |
||
162 | } |
||
163 | } else { |
||
164 | } |
||
165 | } |
||
166 | |||
337 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.