| Conditions | 3 |
| Paths | 4 |
| Total Lines | 56 |
| Lines | 8 |
| Ratio | 14.29 % |
| 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 | |||
| 54 | $nullTitle = array(new Attribute($dic, 'title', NULL)); |
||
| 55 | |||
| 56 | // Global |
||
| 57 | $g->addChild($start = new Node($dic, 'start', array( |
||
| 58 | new Attribute($dic, 'shape', 'Mdiamond'), |
||
| 59 | ))); |
||
| 60 | $g->addChild($end = new Node($dic, 'end', array( |
||
| 61 | new Attribute($dic, 'shape', 'Msquare'), |
||
| 62 | ))); |
||
| 63 | |||
| 64 | $nodes = array(); |
||
| 65 | |||
| 66 | // cluster0 |
||
| 67 | $g->addChild($cluster0 = new Cluster($dic, 0, array( |
||
| 68 | new Attribute($dic, 'style', 'filled'), |
||
| 69 | new Attribute($dic, 'color', 'lightgrey'), |
||
| 70 | new Attribute($dic, 'label', 'process #1'), |
||
| 71 | ))); |
||
| 72 | View Code Duplication | for ($i = 0 ; $i < 4 ; $i++) { |
|
| 73 | $nodeName = "a$i"; |
||
| 74 | $cluster0->addChild($nodes[$nodeName] = new Node($dic, $nodeName, $nullTitle)); |
||
| 75 | } |
||
| 76 | |||
| 77 | // cluster1 |
||
| 78 | $g->addChild($cluster1 = new Cluster($dic, 1, array( |
||
| 79 | new Attribute($dic, 'color', 'blue'), |
||
| 80 | new Attribute($dic, 'label', 'process #2'), |
||
| 81 | ))); |
||
| 82 | View Code Duplication | for ($i = 0 ; $i < 4 ; $i++) { |
|
| 83 | $nodeName = "b$i"; |
||
| 84 | $cluster1->addChild($nodes[$nodeName] = new Node($dic, $nodeName, $nullTitle)); |
||
| 85 | } |
||
| 86 | |||
| 87 | $g->addChild(new Edge($dic, $nodes['a0'], $nodes['a1'])); |
||
| 88 | $g->addChild(new Edge($dic, $nodes['a1'], $nodes['a2'])); |
||
| 89 | $g->addChild(new Edge($dic, $nodes['a1'], $nodes['b3'])); |
||
| 90 | $g->addChild(new Edge($dic, $nodes['a2'], $nodes['a3'])); |
||
| 91 | $g->addChild(new Edge($dic, $nodes['b0'], $nodes['b1'])); |
||
| 92 | $g->addChild(new Edge($dic, $nodes['b1'], $nodes['b2'])); |
||
| 93 | $g->addChild(new Edge($dic, $nodes['b2'], $nodes['b3'])); |
||
| 94 | $g->addChild(new Edge($dic, $nodes['b2'], $nodes['a3'])); |
||
| 95 | |||
| 96 | $g->addChild(new Edge($dic, $start, $nodes['a0'])); |
||
| 97 | $g->addChild(new Edge($dic, $start, $nodes['b0'])); |
||
| 98 | |||
| 99 | $g->addChild(new Edge($dic, $nodes['a3'], $nodes['a0'])); |
||
| 100 | $g->addChild(new Edge($dic, $nodes['a3'], $end)); |
||
| 101 | $g->addChild(new Edge($dic, $nodes['b3'], $end)); |
||
| 102 | } |
||
| 103 | |||
| 150 |
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 theSoncalls the wrong method in the parent class.