Conditions | 1 |
Paths | 1 |
Total Lines | 121 |
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 |
||
47 | public function setUp() : void { |
||
48 | // not strict by default. |
||
49 | parent::setUpExtended(); |
||
|
|||
50 | $g = $this->Graph; |
||
51 | $dic = $this->dic; |
||
52 | $g->setDirected(true); |
||
53 | $g->setAttributes(array( |
||
54 | new Attribute($dic, 'size', 8.6), |
||
55 | new Attribute($dic, 'ratio', 'fill'), |
||
56 | )); |
||
57 | |||
58 | $nullTitle = array(new Attribute($dic, 'title', NULL)); |
||
59 | |||
60 | $g->addChild($nFan = new Node($dic, 'fan', array('implicit' => TRUE))); |
||
61 | |||
62 | $g->addChild($error = new Cluster($dic, 'error.h', array( |
||
63 | new Attribute($dic, 'label', 'error.h'), |
||
64 | ))); |
||
65 | $error->addChild($nInterp_err = new Node($dic, 'interp_err', $nullTitle)); |
||
66 | |||
67 | $g->addChild($sfio = new Cluster($dic, 'sfio.h', array( |
||
68 | new Attribute($dic, 'label', 'sfio.h') |
||
69 | ))); |
||
70 | $sfio->addChild($nSfprintf = new Node($dic, 'sfprintf', $nullTitle)); |
||
71 | |||
72 | $g->addChild($ciafan = new Cluster($dic, 'ciafan.c', array( |
||
73 | new Attribute($dic, 'label', 'ciafan.c'), |
||
74 | ))); |
||
75 | $ciafan->addChild($nCiafan = new Node($dic, 'ciafan', $nullTitle)); |
||
76 | $ciafan->addChild($nComputefan = new Node($dic, 'computefan', $nullTitle)); |
||
77 | $ciafan->addChild($nIncrement = new Node($dic, 'increment', $nullTitle)); |
||
78 | |||
79 | $g->addChild($util = new Cluster($dic, 'util.c', array( |
||
80 | new Attribute($dic, 'label', 'util.c'), |
||
81 | ))); |
||
82 | $util->addChild($nStringdup = new Node($dic, 'stringdup', $nullTitle)); |
||
83 | $util->addChild($nFatal = new Node($dic, 'fatal', $nullTitle)); |
||
84 | $util->addChild($nDebug = new Node($dic, 'debug', $nullTitle)); |
||
85 | |||
86 | $g->addChild($query = new Cluster($dic, 'query.h', array( |
||
87 | new Attribute($dic, 'label', 'query.h'), |
||
88 | ))); |
||
89 | $query->addChild($nRef = new Node($dic, 'ref', $nullTitle)); |
||
90 | $query->addChild($nDef = new Node($dic, 'def', $nullTitle)); |
||
91 | |||
92 | // No label on this cluster. |
||
93 | $g->addChild($field = new Cluster($dic, 'field.h')); |
||
94 | $field->addChild($nGet_sym_fields = new Node($dic, 'get_sym_fields', $nullTitle)); |
||
95 | |||
96 | $g->addChild($stdio = new Cluster($dic, 'stdio.h', array( |
||
97 | new Attribute($dic, 'label', 'stdio.h'), |
||
98 | ))); |
||
99 | $stdio->addChild($nStdprintf = new Node($dic, 'stdprintf', $nullTitle)); |
||
100 | $stdio->addChild($nStdsprintf = new Node($dic, 'stdsprintf', $nullTitle)); |
||
101 | |||
102 | $g->addChild($libc = new Cluster($dic, '<libc.a>')); |
||
103 | $libc->addChild($nGetopt = new Node($dic, 'getopt', $nullTitle)); |
||
104 | |||
105 | $g->addChild($stdlib = new Cluster($dic,'stdlib.h', array( |
||
106 | new Attribute($dic, 'label', 'stdlib.h'), |
||
107 | ))); |
||
108 | $stdlib->addChild($nExit = new Node($dic, 'exit', $nullTitle)); |
||
109 | $stdlib->addChild($nMalloc = new Node($dic, 'malloc', $nullTitle)); |
||
110 | $stdlib->addChild($nFree = new Node($dic, 'free', $nullTitle)); |
||
111 | $stdlib->addChild($nRealloc = new Node($dic, 'realloc', $nullTitle)); |
||
112 | |||
113 | $g->addChild($main = new Cluster($dic, 'main.c')); |
||
114 | $main->addChild($nMain = new Node($dic, 'main', $nullTitle)); |
||
115 | |||
116 | $g->addChild($index = new Cluster($dic, 'index.h')); |
||
117 | $index->addChild($nInit_index = new Node($dic, 'init_index', $nullTitle)); |
||
118 | |||
119 | $g->addChild($string = new Cluster($dic, 'string.h', array( |
||
120 | new Attribute($dic, 'label', 'string.h'), |
||
121 | ))); |
||
122 | $string->addChild($nStrcpy = new Node($dic, 'strcpy', $nullTitle)); |
||
123 | $string->addChild($nStrlen = new Node($dic, 'strlen', $nullTitle)); |
||
124 | $string->addChild($nStrcmp = new Node($dic, 'strcmp', $nullTitle)); |
||
125 | $string->addChild($nStrcat = new Node($dic, 'strcat', $nullTitle)); |
||
126 | |||
127 | $g->addChild(new Edge($dic, $nCiafan, $nComputefan)); |
||
128 | $g->addChild(new Edge($dic, $nCiafan, $nDef)); |
||
129 | |||
130 | $g->addChild(new Edge($dic, $nFan, $nIncrement)); |
||
131 | $g->addChild(new Edge($dic, $nFan, $nFatal)); |
||
132 | $g->addChild(new Edge($dic, $nFan, $nRef)); |
||
133 | $g->addChild(new Edge($dic, $nFan, $nInterp_err)); |
||
134 | $g->addChild(new Edge($dic, $nFan, $nFree)); |
||
135 | $g->addChild(new Edge($dic, $nFan, $nExit)); |
||
136 | $g->addChild(new Edge($dic, $nFan, $nMalloc)); |
||
137 | $g->addChild(new Edge($dic, $nFan, $nStdsprintf)); |
||
138 | $g->addChild(new Edge($dic, $nFan, $nStrlen)); |
||
139 | |||
140 | $g->addChild(new Edge($dic, $nComputefan, $nFan)); |
||
141 | $g->addChild(new Edge($dic, $nComputefan, $nStdprintf)); |
||
142 | $g->addChild(new Edge($dic, $nComputefan, $nGet_sym_fields)); |
||
143 | $g->addChild(new Edge($dic, $nComputefan, $nMalloc)); |
||
144 | $g->addChild(new Edge($dic, $nComputefan, $nStrcmp)); |
||
145 | $g->addChild(new Edge($dic, $nComputefan, $nRealloc)); |
||
146 | $g->addChild(new Edge($dic, $nComputefan, $nStrlen)); |
||
147 | |||
148 | $g->addChild(new Edge($dic, $nStringdup, $nFatal)); |
||
149 | $g->addChild(new Edge($dic, $nStringdup, $nMalloc)); |
||
150 | $g->addChild(new Edge($dic, $nStringdup, $nStrcpy)); |
||
151 | $g->addChild(new Edge($dic, $nStringdup, $nStrlen)); |
||
152 | |||
153 | $g->addChild(new Edge($dic, $nMain, $nExit)); |
||
154 | $g->addChild(new Edge($dic, $nMain, $nInterp_err)); |
||
155 | $g->addChild(new Edge($dic, $nMain, $nCiafan)); |
||
156 | $g->addChild(new Edge($dic, $nMain, $nFatal)); |
||
157 | $g->addChild(new Edge($dic, $nMain, $nMalloc)); |
||
158 | $g->addChild(new Edge($dic, $nMain, $nStrcpy)); |
||
159 | $g->addChild(new Edge($dic, $nMain, $nGetopt)); |
||
160 | $g->addChild(new Edge($dic, $nMain, $nInit_index)); |
||
161 | $g->addChild(new Edge($dic, $nMain, $nStrlen)); |
||
162 | $g->addChild(new Edge($dic, $nIncrement, $nStrcmp)); |
||
163 | $g->addChild(new Edge($dic, $nDebug, $nSfprintf)); |
||
164 | $g->addChild(new Edge($dic, $nDebug, $nStrcat)); |
||
165 | $g->addChild(new Edge($dic, $nFatal, $nSfprintf)); |
||
166 | $g->addChild(new Edge($dic, $nFatal, $nExit)); |
||
167 | } |
||
168 | |||
284 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.