| Conditions | 11 |
| Paths | 6 |
| Total Lines | 44 |
| 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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 85 | public static function get_declarations( string $scan_path ) { // phpcs:ignore PHPCompatibility |
||
| 86 | $core_declarations = new Declarations(); |
||
| 87 | $core_declarations->scan( $scan_path ); |
||
| 88 | $filtered_declarations = new Declarations(); |
||
| 89 | |||
| 90 | foreach ( $core_declarations->get() as $declaration ) { |
||
| 91 | |||
| 92 | if ( $declaration instanceof Declarations\Class_ ) { |
||
| 93 | |||
| 94 | // We are not interested in class definitions. |
||
| 95 | continue; |
||
| 96 | |||
| 97 | } elseif ( |
||
| 98 | $declaration instanceof Declarations\Class_Property |
||
| 99 | && ! $declaration->static |
||
| 100 | ) { |
||
| 101 | |||
| 102 | // We are not interested in properties of objects if they are not static. |
||
| 103 | continue; |
||
| 104 | |||
| 105 | } elseif ( |
||
| 106 | $declaration instanceof Declarations\Class_Method |
||
| 107 | && ! $declaration->static |
||
| 108 | ) { |
||
| 109 | |||
| 110 | // We are not interested in methods of objects if they are not static. |
||
| 111 | continue; |
||
| 112 | |||
| 113 | } elseif ( |
||
| 114 | ! ( |
||
| 115 | $declaration instanceof Declarations\Function_ |
||
| 116 | || $declaration instanceof Declarations\Class_Property |
||
| 117 | || $declaration instanceof Declarations\Class_Method |
||
| 118 | || $declaration instanceof Declarations\Class_Const |
||
| 119 | ) |
||
| 120 | ) { |
||
| 121 | throw new \Exception( 'Unhandled declaration of type ' . get_class( $declaration ) ); |
||
| 122 | } |
||
| 123 | |||
| 124 | $filtered_declarations->add( $declaration ); |
||
| 125 | } |
||
| 126 | |||
| 127 | return $filtered_declarations; |
||
| 128 | } |
||
| 129 | } |
||
| 130 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.