Conditions | 3 |
Paths | 4 |
Total Lines | 55 |
Code Lines | 32 |
Lines | 28 |
Ratio | 50.91 % |
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 |
||
40 | public function __construct( array $config = [] ) { |
||
41 | // Configuration initialization |
||
42 | $config = array_merge( |
||
43 | [ |
||
44 | // Config options for nested widgets |
||
45 | 'namespace' => [], |
||
46 | 'invert' => [], |
||
47 | 'invertLabel' => [], |
||
48 | 'associated' => [], |
||
49 | 'associatedLabel' => [], |
||
50 | ], |
||
51 | $config |
||
52 | ); |
||
53 | |||
54 | // Parent constructor |
||
55 | parent::__construct( $config ); |
||
56 | |||
57 | // Properties |
||
58 | $this->config = $config; |
||
59 | |||
60 | $this->namespace = new NamespaceInputWidget( $config['namespace'] ); |
||
61 | View Code Duplication | if ( $config['associated'] !== null ) { |
|
62 | $this->associated = new \OOUI\CheckboxInputWidget( array_merge( |
||
63 | [ 'value' => '1' ], |
||
64 | $config['associated'] |
||
65 | ) ); |
||
66 | // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet |
||
67 | $this->associatedLabel = new \OOUI\FieldLayout( |
||
68 | $this->associated, |
||
69 | array_merge( |
||
70 | [ 'align' => 'inline' ], |
||
71 | $config['associatedLabel'] |
||
72 | ) |
||
73 | ); |
||
74 | } |
||
75 | View Code Duplication | if ( $config['invert'] !== null ) { |
|
76 | $this->invert = new \OOUI\CheckboxInputWidget( array_merge( |
||
77 | [ 'value' => '1' ], |
||
78 | $config['invert'] |
||
79 | ) ); |
||
80 | // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet |
||
81 | $this->invertLabel = new \OOUI\FieldLayout( |
||
82 | $this->invert, |
||
83 | array_merge( |
||
84 | [ 'align' => 'inline' ], |
||
85 | $config['invertLabel'] |
||
86 | ) |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | // Initialization |
||
91 | $this |
||
92 | ->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] ) |
||
93 | ->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel ); |
||
94 | } |
||
95 | |||
120 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.