Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 36 | class WorkflowTransition extends DataObject |
||
| 37 | { |
||
| 38 | private static $db = array( |
||
|
|
|||
| 39 | 'Title' => 'Varchar(128)', |
||
| 40 | 'Sort' => 'Int', |
||
| 41 | 'Type' => "Enum('Active, Passive', 'Active')" |
||
| 42 | ); |
||
| 43 | |||
| 44 | private static $default_sort = 'Sort'; |
||
| 45 | |||
| 46 | private static $has_one = array( |
||
| 47 | 'Action' => WorkflowAction::class, |
||
| 48 | 'NextAction' => WorkflowAction::class, |
||
| 49 | ); |
||
| 50 | |||
| 51 | private static $many_many = array( |
||
| 52 | 'Users' => Member::class, |
||
| 53 | 'Groups' => Group::class, |
||
| 54 | ); |
||
| 55 | |||
| 56 | private static $icon = 'symbiote/silverstripe-advancedworkflow:images/transition.png'; |
||
| 57 | |||
| 58 | private static $table_name = 'WorkflowTransition'; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * |
||
| 62 | * @var array $extendedMethodReturn A basic extended validation routine method return format |
||
| 63 | */ |
||
| 64 | public static $extendedMethodReturn = array( |
||
| 65 | 'fieldName' => null, |
||
| 66 | 'fieldField' => null, |
||
| 67 | 'fieldMsg' => null, |
||
| 68 | 'fieldValid' => true, |
||
| 69 | ); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Returns true if it is valid for this transition to be followed given the |
||
| 73 | * current state of a workflow. |
||
| 74 | * |
||
| 75 | * @param WorkflowInstance $workflow |
||
| 76 | * @return bool |
||
| 77 | */ |
||
| 78 | public function isValid(WorkflowInstance $workflow) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Before saving, make sure we're not in an infinite loop |
||
| 85 | */ |
||
| 86 | public function onBeforeWrite() |
||
| 94 | |||
| 95 | /* CMS FUNCTIONS */ |
||
| 96 | |||
| 97 | public function getCMSFields() |
||
| 163 | |||
| 164 | public function fieldLabels($includerelations = true) |
||
| 173 | |||
| 174 | public function getValidator() |
||
| 180 | |||
| 181 | public function numChildren() |
||
| 185 | |||
| 186 | public function summaryFields() |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * Check if the current user can execute this transition |
||
| 196 | * |
||
| 197 | * @return bool |
||
| 198 | **/ |
||
| 199 | public function canExecute(WorkflowInstance $workflow) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Allows users who have permission to create a WorkflowDefinition, to create actions on it too. |
||
| 223 | * |
||
| 224 | * @param Member $member |
||
| 225 | * @param array $context |
||
| 226 | * @return bool |
||
| 227 | */ |
||
| 228 | public function canCreate($member = null, $context = array()) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param Member $member |
||
| 235 | * @return bool |
||
| 236 | */ |
||
| 237 | public function canEdit($member = null) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param Member $member |
||
| 244 | * @return bool |
||
| 245 | */ |
||
| 246 | public function canDelete($member = null) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Returns a set of all Members that are assigned to this transition, either directly or via a group. |
||
| 253 | * |
||
| 254 | * @return ArrayList |
||
| 255 | */ |
||
| 256 | View Code Duplication | public function getAssignedMembers() |
|
| 268 | |||
| 269 | /* |
||
| 270 | * A simple field same-value checker. |
||
| 271 | * |
||
| 272 | * @param array $data |
||
| 273 | * @return array |
||
| 274 | * @see {@link AWRequiredFields} |
||
| 275 | */ |
||
| 276 | public function extendedRequiredFieldsNotSame($data = null) |
||
| 296 | } |
||
| 297 |