Conditions | 17 |
Paths | 241 |
Total Lines | 65 |
Lines | 9 |
Ratio | 13.85 % |
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.NotHyphenatedLowercase |
||
108 | public function validateFile( $filename ) { |
||
109 | try { |
||
110 | $diagnostics = null; // Make phpcs happy. |
||
111 | $data = Utils::loadChangeFile( $filename, $diagnostics ); |
||
112 | } catch ( \RuntimeException $ex ) { |
||
113 | $this->msg( 'error', $filename, $ex->fileLine, $ex->getMessage() ); |
||
|
|||
114 | return false; |
||
115 | } |
||
116 | |||
117 | $messages = array(); |
||
118 | |||
119 | foreach ( $diagnostics['warnings'] as list( $msg, $line ) ) { |
||
120 | $messages[] = array( 'warning', $msg, $line ); |
||
121 | } |
||
122 | |||
123 | foreach ( $diagnostics['lines'] as $header => $line ) { |
||
124 | if ( ! in_array( $header, array( 'Significance', 'Type', 'Comment', '' ), true ) ) { |
||
125 | $messages[] = array( 'warning', "Unrecognized header \"$header\".", $line ); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | if ( ! isset( $data['Significance'] ) ) { |
||
130 | $messages[] = array( 'error', 'File does not contain a Significance header.', null ); |
||
131 | } elseif ( ! in_array( $data['Significance'], array( 'patch', 'minor', 'major' ), true ) ) { |
||
132 | $messages[] = array( 'error', 'Significance must be "patch", "minor", or "major".', $diagnostics['lines']['Significance'] ); |
||
133 | } elseif ( 'patch' !== $data['Significance'] && '' === $data[''] ) { |
||
134 | $messages[] = array( 'error', 'Changelog entry may only be empty when Significance is "patch".', $diagnostics['lines'][''] ); |
||
135 | } |
||
136 | |||
137 | $types = Config::types(); |
||
138 | if ( $types ) { |
||
139 | if ( ! isset( $data['Type'] ) ) { |
||
140 | $messages[] = array( 'error', 'File does not contain a Type header.', null ); |
||
141 | } elseif ( ! isset( $types[ $data['Type'] ] ) ) { |
||
142 | $list = array_map( |
||
143 | function ( $v ) { |
||
144 | return "\"$v\""; |
||
145 | }, |
||
146 | array_keys( $types ) |
||
147 | ); |
||
148 | View Code Duplication | if ( count( $list ) > 1 ) { |
|
149 | $list[ count( $list ) - 1 ] = 'or ' . $list[ count( $list ) - 1 ]; |
||
150 | } |
||
151 | $messages[] = array( 'error', 'Type must be ' . implode( count( $list ) > 2 ? ', ' : ' ', $list ) . '.', $diagnostics['lines']['Type'] ); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | usort( |
||
156 | $messages, |
||
157 | function ( $a, $b ) { |
||
158 | // @codeCoverageIgnoreStart |
||
159 | View Code Duplication | if ( $a[2] !== $b[2] ) { |
|
160 | return $a[2] - $b[2]; |
||
161 | } |
||
162 | View Code Duplication | if ( $a[0] !== $b[0] ) { |
|
163 | return strcmp( $a[0], $b[0] ); |
||
164 | } |
||
165 | return strcmp( $a[1], $b[1] ); |
||
166 | // @codeCoverageIgnoreEnd |
||
167 | } |
||
168 | ); |
||
169 | foreach ( $messages as list( $type, $msg, $line ) ) { |
||
170 | $this->msg( $type, $filename, $line, $msg ); |
||
171 | } |
||
172 | } |
||
173 | |||
219 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.