Conditions | 18 |
Paths | 5328 |
Total Lines | 95 |
Lines | 23 |
Ratio | 24.21 % |
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 namespace XoopsModules\Smartobject; |
||
60 | public function createTableRow($object, $level = 0) |
||
61 | { |
||
62 | $aObject = []; |
||
63 | |||
64 | $i = 0; |
||
65 | |||
66 | $aColumns = []; |
||
67 | $doWeHaveActions = false; |
||
|
|||
68 | |||
69 | foreach ($this->_columns as $column) { |
||
70 | $aColumn = []; |
||
71 | |||
72 | View Code Duplication | if (0 == $i) { |
|
73 | $class = 'head'; |
||
74 | } elseif (0 == $i % 2) { |
||
75 | $class = 'even'; |
||
76 | } else { |
||
77 | $class = 'odd'; |
||
78 | } |
||
79 | |||
80 | if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
||
81 | $method = $column->_customMethodForValue; |
||
82 | $value = $object->$method(); |
||
83 | View Code Duplication | } else { |
|
84 | /** |
||
85 | * If the column is the identifier, then put a link on it |
||
86 | */ |
||
87 | if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
||
88 | $value = $object->getItemLink(); |
||
89 | } else { |
||
90 | $value = $object->getVar($column->getKeyName()); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | $space = ''; |
||
95 | if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
||
96 | for ($i = 0; $i < $level; ++$i) { |
||
97 | $space .= '--'; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | if ('' !== $space) { |
||
102 | $space .= ' '; |
||
103 | } |
||
104 | |||
105 | $aColumn['value'] = $space . $value; |
||
106 | $aColumn['class'] = $class; |
||
107 | $aColumn['width'] = $column->getWidth(); |
||
108 | $aColumn['align'] = $column->getAlign(); |
||
109 | $aColumn['key'] = $column->getKeyName(); |
||
110 | |||
111 | $aColumns[] = $aColumn; |
||
112 | ++$i; |
||
113 | } |
||
114 | |||
115 | $aObject['columns'] = $aColumns; |
||
116 | |||
117 | $class = 'even' === $class ? 'odd' : 'even'; |
||
118 | $aObject['class'] = $class; |
||
119 | |||
120 | $actions = []; |
||
121 | |||
122 | // Adding the custom actions if any |
||
123 | foreach ($this->_custom_actions as $action) { |
||
124 | if (method_exists($object, $action)) { |
||
125 | $actions[] = $object->$action(); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
||
130 | $controller = new ObjectController($this->_objectHandler); |
||
131 | |||
132 | View Code Duplication | if (in_array('edit', $this->_actions)) { |
|
133 | $actions[] = $controller->getEditItemLink($object, false, true); |
||
134 | } |
||
135 | View Code Duplication | if (in_array('delete', $this->_actions)) { |
|
136 | $actions[] = $controller->getDeleteItemLink($object, false, true); |
||
137 | } |
||
138 | $aObject['actions'] = $actions; |
||
139 | |||
140 | $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
||
141 | $aObject['id'] = $object->id(); |
||
142 | $this->_aObjects[] = $aObject; |
||
143 | |||
144 | $childrenObjects = $this->getChildrenOf($object->id()); |
||
145 | |||
146 | $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
||
147 | |||
148 | if ($childrenObjects) { |
||
149 | ++$level; |
||
150 | foreach ($childrenObjects as $subObject) { |
||
151 | $this->createTableRow($subObject, $level); |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
182 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.