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:
Complex classes like DataList often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DataList, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
35 | class DataList extends ViewableData implements SS_List, Filterable, Sortable, Limitable |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The DataObject class name that this data list is querying |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $dataClass; |
||
44 | |||
45 | /** |
||
46 | * The {@link DataQuery} object responsible for getting this DataList's records |
||
47 | * |
||
48 | * @var DataQuery |
||
49 | */ |
||
50 | protected $dataQuery; |
||
51 | |||
52 | /** |
||
53 | * The DataModel from which this DataList comes. |
||
54 | * |
||
55 | * @var DataModel |
||
56 | */ |
||
57 | protected $model; |
||
58 | |||
59 | /** |
||
60 | * Create a new DataList. |
||
61 | * No querying is done on construction, but the initial query schema is set up. |
||
62 | * |
||
63 | * @param string $dataClass - The DataObject class to query. |
||
64 | */ |
||
65 | public function __construct($dataClass) |
||
72 | |||
73 | /** |
||
74 | * Set the DataModel |
||
75 | * |
||
76 | * @param DataModel $model |
||
77 | */ |
||
78 | public function setDataModel(DataModel $model) |
||
82 | |||
83 | /** |
||
84 | * Get the dataClass name for this DataList, ie the DataObject ClassName |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | public function dataClass() |
||
92 | |||
93 | /** |
||
94 | * When cloning this object, clone the dataQuery object as well |
||
95 | */ |
||
96 | public function __clone() |
||
100 | |||
101 | /** |
||
102 | * Return a copy of the internal {@link DataQuery} object |
||
103 | * |
||
104 | * Because the returned value is a copy, modifying it won't affect this list's contents. If |
||
105 | * you want to alter the data query directly, use the alterDataQuery method |
||
106 | * |
||
107 | * @return DataQuery |
||
108 | */ |
||
109 | public function dataQuery() |
||
113 | |||
114 | /** |
||
115 | * @var bool - Indicates if we are in an alterDataQueryCall already, so alterDataQuery can be re-entrant |
||
116 | */ |
||
117 | protected $inAlterDataQueryCall = false; |
||
118 | |||
119 | /** |
||
120 | * Return a new DataList instance with the underlying {@link DataQuery} object altered |
||
121 | * |
||
122 | * If you want to alter the underlying dataQuery for this list, this wrapper method |
||
123 | * will ensure that you can do so without mutating the existing List object. |
||
124 | * |
||
125 | * It clones this list, calls the passed callback function with the dataQuery of the new |
||
126 | * list as it's first parameter (and the list as it's second), then returns the list |
||
127 | * |
||
128 | * Note that this function is re-entrant - it's safe to call this inside a callback passed to |
||
129 | * alterDataQuery |
||
130 | * |
||
131 | * @param callable $callback |
||
132 | * @return static |
||
133 | * @throws Exception |
||
134 | */ |
||
135 | public function alterDataQuery($callback) |
||
164 | |||
165 | /** |
||
166 | * Return a new DataList instance with the underlying {@link DataQuery} object changed |
||
167 | * |
||
168 | * @param DataQuery $dataQuery |
||
169 | * @return static |
||
170 | */ |
||
171 | public function setDataQuery(DataQuery $dataQuery) |
||
177 | |||
178 | /** |
||
179 | * Returns a new DataList instance with the specified query parameter assigned |
||
180 | * |
||
181 | * @param string|array $keyOrArray Either the single key to set, or an array of key value pairs to set |
||
182 | * @param mixed $val If $keyOrArray is not an array, this is the value to set |
||
183 | * @return static |
||
184 | */ |
||
185 | public function setDataQueryParam($keyOrArray, $val = null) |
||
199 | |||
200 | /** |
||
201 | * Returns the SQL query that will be used to get this DataList's records. Good for debugging. :-) |
||
202 | * |
||
203 | * @param array $parameters Out variable for parameters required for this query |
||
204 | * @return string The resulting SQL query (may be paramaterised) |
||
205 | */ |
||
206 | public function sql(&$parameters = array()) |
||
210 | |||
211 | /** |
||
212 | * Return a new DataList instance with a WHERE clause added to this list's query. |
||
213 | * |
||
214 | * Supports parameterised queries. |
||
215 | * See SQLSelect::addWhere() for syntax examples, although DataList |
||
216 | * won't expand multiple method arguments as SQLSelect does. |
||
217 | * |
||
218 | * @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or |
||
219 | * paramaterised queries |
||
220 | * @return static |
||
221 | */ |
||
222 | public function where($filter) |
||
228 | |||
229 | /** |
||
230 | * Return a new DataList instance with a WHERE clause added to this list's query. |
||
231 | * All conditions provided in the filter will be joined with an OR |
||
232 | * |
||
233 | * Supports parameterised queries. |
||
234 | * See SQLSelect::addWhere() for syntax examples, although DataList |
||
235 | * won't expand multiple method arguments as SQLSelect does. |
||
236 | * |
||
237 | * @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or |
||
238 | * paramaterised queries |
||
239 | * @return static |
||
240 | */ |
||
241 | public function whereAny($filter) |
||
247 | |||
248 | |||
249 | |||
250 | /** |
||
251 | * Returns true if this DataList can be sorted by the given field. |
||
252 | * |
||
253 | * @param string $fieldName |
||
254 | * @return boolean |
||
255 | */ |
||
256 | public function canSortBy($fieldName) |
||
260 | |||
261 | /** |
||
262 | * Returns true if this DataList can be filtered by the given field. |
||
263 | * |
||
264 | * @param string $fieldName (May be a related field in dot notation like Member.FirstName) |
||
265 | * @return boolean |
||
266 | */ |
||
267 | public function canFilterBy($fieldName) |
||
289 | |||
290 | /** |
||
291 | * Return a new DataList instance with the records returned in this query |
||
292 | * restricted by a limit clause. |
||
293 | * |
||
294 | * @param int $limit |
||
295 | * @param int $offset |
||
296 | * @return static |
||
297 | */ |
||
298 | public function limit($limit, $offset = 0) |
||
304 | |||
305 | /** |
||
306 | * Return a new DataList instance with distinct records or not |
||
307 | * |
||
308 | * @param bool $value |
||
309 | * @return static |
||
310 | */ |
||
311 | public function distinct($value) |
||
317 | |||
318 | /** |
||
319 | * Return a new DataList instance as a copy of this data list with the sort |
||
320 | * order set. |
||
321 | * |
||
322 | * @see SS_List::sort() |
||
323 | * @see SQLSelect::orderby |
||
324 | * @example $list = $list->sort('Name'); // default ASC sorting |
||
325 | * @example $list = $list->sort('Name DESC'); // DESC sorting |
||
326 | * @example $list = $list->sort('Name', 'ASC'); |
||
327 | * @example $list = $list->sort(array('Name'=>'ASC', 'Age'=>'DESC')); |
||
328 | * |
||
329 | * @param String|array Escaped SQL statement. If passed as array, all keys and values are assumed to be escaped. |
||
330 | * @return static |
||
331 | */ |
||
332 | public function sort() |
||
381 | |||
382 | /** |
||
383 | * Return a copy of this list which only includes items with these charactaristics |
||
384 | * |
||
385 | * @see SS_List::filter() |
||
386 | * |
||
387 | * @example $list = $list->filter('Name', 'bob'); // only bob in the list |
||
388 | * @example $list = $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list |
||
389 | * @example $list = $list->filter(array('Name'=>'bob', 'Age'=>21)); // bob with the age 21 |
||
390 | * @example $list = $list->filter(array('Name'=>'bob', 'Age'=>array(21, 43))); // bob with the Age 21 or 43 |
||
391 | * @example $list = $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43))); |
||
392 | * // aziz with the age 21 or 43 and bob with the Age 21 or 43 |
||
393 | * |
||
394 | * Note: When filtering on nullable columns, null checks will be automatically added. |
||
395 | * E.g. ->filter('Field:not', 'value) will generate '... OR "Field" IS NULL', and |
||
396 | * ->filter('Field:not', null) will generate '"Field" IS NOT NULL' |
||
397 | * |
||
398 | * @todo extract the sql from $customQuery into a SQLGenerator class |
||
399 | * |
||
400 | * @param string|array Escaped SQL statement. If passed as array, all keys and values will be escaped internally |
||
401 | * @return $this |
||
402 | */ |
||
403 | public function filter() |
||
422 | |||
423 | /** |
||
424 | * Return a new instance of the list with an added filter |
||
425 | * |
||
426 | * @param array $filterArray |
||
427 | * @return $this |
||
428 | */ |
||
429 | public function addFilter($filterArray) |
||
440 | |||
441 | /** |
||
442 | * Return a copy of this list which contains items matching any of these charactaristics. |
||
443 | * |
||
444 | * @example // only bob in the list |
||
445 | * $list = $list->filterAny('Name', 'bob'); |
||
446 | * // SQL: WHERE "Name" = 'bob' |
||
447 | * @example // azis or bob in the list |
||
448 | * $list = $list->filterAny('Name', array('aziz', 'bob'); |
||
449 | * // SQL: WHERE ("Name" IN ('aziz','bob')) |
||
450 | * @example // bob or anyone aged 21 in the list |
||
451 | * $list = $list->filterAny(array('Name'=>'bob, 'Age'=>21)); |
||
452 | * // SQL: WHERE ("Name" = 'bob' OR "Age" = '21') |
||
453 | * @example // bob or anyone aged 21 or 43 in the list |
||
454 | * $list = $list->filterAny(array('Name'=>'bob, 'Age'=>array(21, 43))); |
||
455 | * // SQL: WHERE ("Name" = 'bob' OR ("Age" IN ('21', '43')) |
||
456 | * @example // all bobs, phils or anyone aged 21 or 43 in the list |
||
457 | * $list = $list->filterAny(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); |
||
458 | * // SQL: WHERE (("Name" IN ('bob', 'phil')) OR ("Age" IN ('21', '43')) |
||
459 | * |
||
460 | * @todo extract the sql from this method into a SQLGenerator class |
||
461 | * |
||
462 | * @param string|array See {@link filter()} |
||
463 | * @return static |
||
464 | */ |
||
465 | View Code Duplication | public function filterAny() |
|
487 | |||
488 | /** |
||
489 | * Note that, in the current implementation, the filtered list will be an ArrayList, but this may change in a |
||
490 | * future implementation. |
||
491 | * @see Filterable::filterByCallback() |
||
492 | * |
||
493 | * @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; }) |
||
494 | * @param callable $callback |
||
495 | * @return ArrayList (this may change in future implementations) |
||
496 | */ |
||
497 | View Code Duplication | public function filterByCallback($callback) |
|
514 | |||
515 | /** |
||
516 | * Given a field or relation name, apply it safely to this datalist. |
||
517 | * |
||
518 | * Unlike getRelationName, this is immutable and will fallback to the quoted field |
||
519 | * name if not a relation. |
||
520 | * |
||
521 | * @param string $field Name of field or relation to apply |
||
522 | * @param string &$columnName Quoted column name |
||
523 | * @param bool $linearOnly Set to true to restrict to linear relations only. Set this |
||
524 | * if this relation will be used for sorting, and should not include duplicate rows. |
||
525 | * @return $this DataList with this relation applied |
||
526 | */ |
||
527 | public function applyRelation($field, &$columnName = null, $linearOnly = false) |
||
554 | |||
555 | /** |
||
556 | * Check if the given field specification could be interpreted as an unquoted relation name |
||
557 | * |
||
558 | * @param string $field |
||
559 | * @return bool |
||
560 | */ |
||
561 | protected function isValidRelationName($field) |
||
565 | |||
566 | /** |
||
567 | * Given a filter expression and value construct a {@see SearchFilter} instance |
||
568 | * |
||
569 | * @param string $filter E.g. `Name:ExactMatch:not`, `Name:ExactMatch`, `Name:not`, `Name` |
||
570 | * @param mixed $value Value of the filter |
||
571 | * @return SearchFilter |
||
572 | */ |
||
573 | protected function createSearchFilter($filter, $value) |
||
603 | |||
604 | /** |
||
605 | * Return a copy of this list which does not contain any items with these charactaristics |
||
606 | * |
||
607 | * @see SS_List::exclude() |
||
608 | * @example $list = $list->exclude('Name', 'bob'); // exclude bob from list |
||
609 | * @example $list = $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list |
||
610 | * @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21 |
||
611 | * @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43 |
||
612 | * @example $list = $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); |
||
613 | * // bob age 21 or 43, phil age 21 or 43 would be excluded |
||
614 | * |
||
615 | * @todo extract the sql from this method into a SQLGenerator class |
||
616 | * |
||
617 | * @param string|array Escaped SQL statement. If passed as array, all keys and values will be escaped internally |
||
618 | * @return $this |
||
619 | */ |
||
620 | View Code Duplication | public function exclude() |
|
642 | |||
643 | /** |
||
644 | * This method returns a copy of this list that does not contain any DataObjects that exists in $list |
||
645 | * |
||
646 | * The $list passed needs to contain the same dataclass as $this |
||
647 | * |
||
648 | * @param DataList $list |
||
649 | * @return static |
||
650 | * @throws InvalidArgumentException |
||
651 | */ |
||
652 | public function subtract(DataList $list) |
||
662 | |||
663 | /** |
||
664 | * Return a new DataList instance with an inner join clause added to this list's query. |
||
665 | * |
||
666 | * @param string $table Table name (unquoted and as escaped SQL) |
||
667 | * @param string $onClause Escaped SQL statement, e.g. '"Table1"."ID" = "Table2"."ID"' |
||
668 | * @param string $alias - if you want this table to be aliased under another name |
||
669 | * @param int $order A numerical index to control the order that joins are added to the query; lower order values |
||
670 | * will cause the query to appear first. The default is 20, and joins created automatically by the |
||
671 | * ORM have a value of 10. |
||
672 | * @param array $parameters Any additional parameters if the join is a parameterised subquery |
||
673 | * @return static |
||
674 | */ |
||
675 | public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = array()) |
||
681 | |||
682 | /** |
||
683 | * Return a new DataList instance with a left join clause added to this list's query. |
||
684 | * |
||
685 | * @param string $table Table name (unquoted and as escaped SQL) |
||
686 | * @param string $onClause Escaped SQL statement, e.g. '"Table1"."ID" = "Table2"."ID"' |
||
687 | * @param string $alias - if you want this table to be aliased under another name |
||
688 | * @param int $order A numerical index to control the order that joins are added to the query; lower order values |
||
689 | * will cause the query to appear first. The default is 20, and joins created automatically by the |
||
690 | * ORM have a value of 10. |
||
691 | * @param array $parameters Any additional parameters if the join is a parameterised subquery |
||
692 | * @return static |
||
693 | */ |
||
694 | public function leftJoin($table, $onClause, $alias = null, $order = 20, $parameters = array()) |
||
700 | |||
701 | /** |
||
702 | * Return an array of the actual items that this DataList contains at this stage. |
||
703 | * This is when the query is actually executed. |
||
704 | * |
||
705 | * @return array |
||
706 | */ |
||
707 | public function toArray() |
||
719 | |||
720 | /** |
||
721 | * Return this list as an array and every object it as an sub array as well |
||
722 | * |
||
723 | * @return array |
||
724 | */ |
||
725 | public function toNestedArray() |
||
735 | |||
736 | /** |
||
737 | * Walks the list using the specified callback |
||
738 | * |
||
739 | * @param callable $callback |
||
740 | * @return $this |
||
741 | */ |
||
742 | public function each($callback) |
||
750 | |||
751 | View Code Duplication | public function debug() |
|
761 | |||
762 | /** |
||
763 | * Returns a map of this list |
||
764 | * |
||
765 | * @param string $keyField - the 'key' field of the result array |
||
766 | * @param string $titleField - the value field of the result array |
||
767 | * @return Map |
||
768 | */ |
||
769 | public function map($keyField = 'ID', $titleField = 'Title') |
||
773 | |||
774 | /** |
||
775 | * Create a DataObject from the given SQL row |
||
776 | * |
||
777 | * @param array $row |
||
778 | * @return DataObject |
||
779 | */ |
||
780 | public function createDataObject($row) |
||
802 | |||
803 | /** |
||
804 | * Get query parameters for this list. |
||
805 | * These values will be assigned as query parameters to newly created objects from this list. |
||
806 | * |
||
807 | * @return array |
||
808 | */ |
||
809 | public function getQueryParams() |
||
813 | |||
814 | /** |
||
815 | * Returns an Iterator for this DataList. |
||
816 | * This function allows you to use DataLists in foreach loops |
||
817 | * |
||
818 | * @return ArrayIterator |
||
819 | */ |
||
820 | public function getIterator() |
||
824 | |||
825 | /** |
||
826 | * Return the number of items in this DataList |
||
827 | * |
||
828 | * @return int |
||
829 | */ |
||
830 | public function count() |
||
834 | |||
835 | /** |
||
836 | * Return the maximum value of the given field in this DataList |
||
837 | * |
||
838 | * @param string $fieldName |
||
839 | * @return mixed |
||
840 | */ |
||
841 | public function max($fieldName) |
||
845 | |||
846 | /** |
||
847 | * Return the minimum value of the given field in this DataList |
||
848 | * |
||
849 | * @param string $fieldName |
||
850 | * @return mixed |
||
851 | */ |
||
852 | public function min($fieldName) |
||
856 | |||
857 | /** |
||
858 | * Return the average value of the given field in this DataList |
||
859 | * |
||
860 | * @param string $fieldName |
||
861 | * @return mixed |
||
862 | */ |
||
863 | public function avg($fieldName) |
||
867 | |||
868 | /** |
||
869 | * Return the sum of the values of the given field in this DataList |
||
870 | * |
||
871 | * @param string $fieldName |
||
872 | * @return mixed |
||
873 | */ |
||
874 | public function sum($fieldName) |
||
878 | |||
879 | |||
880 | /** |
||
881 | * Returns the first item in this DataList |
||
882 | * |
||
883 | * @return DataObject |
||
884 | */ |
||
885 | public function first() |
||
892 | |||
893 | /** |
||
894 | * Returns the last item in this DataList |
||
895 | * |
||
896 | * @return DataObject |
||
897 | */ |
||
898 | public function last() |
||
905 | |||
906 | /** |
||
907 | * Returns true if this DataList has items |
||
908 | * |
||
909 | * @return bool |
||
910 | */ |
||
911 | public function exists() |
||
915 | |||
916 | /** |
||
917 | * Find the first DataObject of this DataList where the given key = value |
||
918 | * |
||
919 | * @param string $key |
||
920 | * @param string $value |
||
921 | * @return DataObject|null |
||
922 | */ |
||
923 | public function find($key, $value) |
||
927 | |||
928 | /** |
||
929 | * Restrict the columns to fetch into this DataList |
||
930 | * |
||
931 | * @param array $queriedColumns |
||
932 | * @return static |
||
933 | */ |
||
934 | public function setQueriedColumns($queriedColumns) |
||
940 | |||
941 | /** |
||
942 | * Filter this list to only contain the given Primary IDs |
||
943 | * |
||
944 | * @param array $ids Array of integers |
||
945 | * @return $this |
||
946 | */ |
||
947 | public function byIDs($ids) |
||
951 | |||
952 | /** |
||
953 | * Return the first DataObject with the given ID |
||
954 | * |
||
955 | * @param int $id |
||
956 | * @return DataObject |
||
957 | */ |
||
958 | public function byID($id) |
||
962 | |||
963 | /** |
||
964 | * Returns an array of a single field value for all items in the list. |
||
965 | * |
||
966 | * @param string $colName |
||
967 | * @return array |
||
968 | */ |
||
969 | public function column($colName = "ID") |
||
973 | |||
974 | // Member altering methods |
||
975 | |||
976 | /** |
||
977 | * Sets the ComponentSet to be the given ID list. |
||
978 | * Records will be added and deleted as appropriate. |
||
979 | * |
||
980 | * @param array $idList List of IDs. |
||
981 | */ |
||
982 | public function setByIDList($idList) |
||
1008 | |||
1009 | /** |
||
1010 | * Returns an array with both the keys and values set to the IDs of the records in this list. |
||
1011 | * Does not respect sort order. Use ->column("ID") to get an ID list with the current sort. |
||
1012 | * |
||
1013 | * @return array |
||
1014 | */ |
||
1015 | public function getIDList() |
||
1020 | |||
1021 | /** |
||
1022 | * Returns a HasManyList or ManyMany list representing the querying of a relation across all |
||
1023 | * objects in this data list. For it to work, the relation must be defined on the data class |
||
1024 | * that you used to create this DataList. |
||
1025 | * |
||
1026 | * Example: Get members from all Groups: |
||
1027 | * |
||
1028 | * DataList::Create("Group")->relation("Members") |
||
1029 | * |
||
1030 | * @param string $relationName |
||
1031 | * @return HasManyList|ManyManyList |
||
1032 | */ |
||
1033 | public function relation($relationName) |
||
1038 | |||
1039 | public function dbObject($fieldName) |
||
1043 | |||
1044 | /** |
||
1045 | * Add a number of items to the component set. |
||
1046 | * |
||
1047 | * @param array $items Items to add, as either DataObjects or IDs. |
||
1048 | * @return $this |
||
1049 | */ |
||
1050 | public function addMany($items) |
||
1057 | |||
1058 | /** |
||
1059 | * Remove the items from this list with the given IDs |
||
1060 | * |
||
1061 | * @param array $idList |
||
1062 | * @return $this |
||
1063 | */ |
||
1064 | public function removeMany($idList) |
||
1071 | |||
1072 | /** |
||
1073 | * Remove every element in this DataList matching the given $filter. |
||
1074 | * |
||
1075 | * @param string $filter - a sql type where filter |
||
1076 | * @return $this |
||
1077 | */ |
||
1078 | public function removeByFilter($filter) |
||
1085 | |||
1086 | /** |
||
1087 | * Remove every element in this DataList. |
||
1088 | * |
||
1089 | * @return $this |
||
1090 | */ |
||
1091 | public function removeAll() |
||
1098 | |||
1099 | /** |
||
1100 | * This method are overloaded by HasManyList and ManyMany list to perform more sophisticated |
||
1101 | * list manipulation |
||
1102 | * |
||
1103 | * @param mixed $item |
||
1104 | */ |
||
1105 | public function add($item) |
||
1110 | |||
1111 | /** |
||
1112 | * Return a new item to add to this DataList. |
||
1113 | * |
||
1114 | * @todo This doesn't factor in filters. |
||
1115 | * @param array $initialFields |
||
1116 | * @return DataObject |
||
1117 | */ |
||
1118 | public function newObject($initialFields = null) |
||
1123 | |||
1124 | /** |
||
1125 | * Remove this item by deleting it |
||
1126 | * |
||
1127 | * @param DataObject $item |
||
1128 | * @todo Allow for amendment of this behaviour - for example, we can remove an item from |
||
1129 | * an "ActiveItems" DataList by chaning the status to inactive. |
||
1130 | */ |
||
1131 | public function remove($item) |
||
1136 | |||
1137 | /** |
||
1138 | * Remove an item from this DataList by ID |
||
1139 | * |
||
1140 | * @param int $itemID The primary ID |
||
1141 | */ |
||
1142 | public function removeByID($itemID) |
||
1150 | |||
1151 | /** |
||
1152 | * Reverses a list of items. |
||
1153 | * |
||
1154 | * @return static |
||
1155 | */ |
||
1156 | public function reverse() |
||
1162 | |||
1163 | /** |
||
1164 | * Returns whether an item with $key exists |
||
1165 | * |
||
1166 | * @param mixed $key |
||
1167 | * @return bool |
||
1168 | */ |
||
1169 | public function offsetExists($key) |
||
1173 | |||
1174 | /** |
||
1175 | * Returns item stored in list with index $key |
||
1176 | * |
||
1177 | * @param mixed $key |
||
1178 | * @return DataObject |
||
1179 | */ |
||
1180 | public function offsetGet($key) |
||
1184 | |||
1185 | /** |
||
1186 | * Set an item with the key in $key |
||
1187 | * |
||
1188 | * @param mixed $key |
||
1189 | * @param mixed $value |
||
1190 | */ |
||
1191 | public function offsetSet($key, $value) |
||
1195 | |||
1196 | /** |
||
1197 | * Unset an item with the key in $key |
||
1198 | * |
||
1199 | * @param mixed $key |
||
1200 | */ |
||
1201 | public function offsetUnset($key) |
||
1205 | } |
||
1206 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.