| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 52 | 
| 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  | 
            ||
| 49 |   public function setUp() : void { | 
            ||
| 50 | parent::setUpExtended();  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 51 | $this->Graph->setDirected(true);  | 
            ||
| 52 | $graph = &$this->Graph;  | 
            ||
| 53 | $dic = &$this->dic;  | 
            ||
| 54 | |||
| 55 | $graph->addChild($main = new Node($dic, 'main', array(  | 
            ||
| 56 | new Attribute($dic, 'shape', 'box'),  | 
            ||
| 57 | new Attribute($dic, 'comment', 'this is a comment'),  | 
            ||
| 58 | )));  | 
            ||
| 59 | $graph->addChild(new Edge($dic, $main,  | 
            ||
| 60 | $parse = new Node($this->dic, 'parse'), array(  | 
            ||
| 61 | new Attribute($dic, 'weight', 8)  | 
            ||
| 62 | )));  | 
            ||
| 63 | $graph->addChild(new Edge($dic,  | 
            ||
| 64 | $parse = new Node($dic, 'parse', Node::implicit()),  | 
            ||
| 65 | $execute = new Node($dic, 'execute', Node::implicit())  | 
            ||
| 66 | ));  | 
            ||
| 67 | $graph->addChild(new Edge($dic, $main,  | 
            ||
| 68 | $init = new Node($dic, 'init', Node::implicit()), array(  | 
            ||
| 69 | new Attribute($dic, 'style', 'dotted')  | 
            ||
| 70 | )));  | 
            ||
| 71 | $graph->addChild(new Edge($dic, $main,  | 
            ||
| 72 | $cleanup = new Node($dic, 'cleanup', Node::implicit())  | 
            ||
| 73 | ));  | 
            ||
| 74 | |||
| 75 | // XXX The original example creates the node after the edge referencing it.  | 
            ||
| 76 | $graph->addChild($make_string = new Node($dic, 'make_string', array(  | 
            ||
| 77 | new Attribute($dic, 'label', "make a\nstring"),  | 
            ||
| 78 | )));  | 
            ||
| 79 | |||
| 80 | $graph->addChild(new Edge($dic, $execute, $make_string));  | 
            ||
| 81 | $graph->addChild(new Edge($dic, $execute,  | 
            ||
| 82 | $printf = new Node($dic, 'printf', Node::implicit())  | 
            ||
| 83 | ));  | 
            ||
| 84 | $graph->addChild(new Edge($dic, $init, $make_string));  | 
            ||
| 85 | $graph->addChild(new Edge($dic, $main, $printf, array(  | 
            ||
| 86 | new Attribute($dic, 'style', 'bold'),  | 
            ||
| 87 | new Attribute($dic, 'label', '100 times'),  | 
            ||
| 88 | )));  | 
            ||
| 89 | |||
| 90 | $graph->addChild($compare = new Node($dic, 'compare', array(  | 
            ||
| 91 | new Attribute($dic, 'shape', 'box'),  | 
            ||
| 92 | new Attribute($dic, 'style', 'filled'),  | 
            ||
| 93 | new Attribute($dic, 'color', '.7 .3 1.0'),  | 
            ||
| 94 | )));  | 
            ||
| 95 | |||
| 96 | $graph->addChild(new Edge($dic, $execute, $compare, array(  | 
            ||
| 97 | new Attribute($dic, 'color', 'red'),  | 
            ||
| 98 | new Attribute($dic, 'comment', 'so is this'),  | 
            ||
| 99 | )));  | 
            ||
| 100 | }  | 
            ||
| 101 | |||
| 126 | 
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.