Skip to content

Commit d199361

Browse files
authored
Merge pull request #2361 from WordPress/feature/helpers-final-trait-methods
2 parents 5f565a1 + ea871fb commit d199361

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

.phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
<exclude-pattern>/WordPress/Sniffs/Security/(EscapeOutput|NonceVerification|ValidatedSanitizedInput)Sniff\.php$</exclude-pattern>
8181
</rule>
8282

83+
<!-- Enforce that methods in traits are always final. -->
84+
<rule ref="Universal.FunctionDeclarations.RequireFinalMethodsInTraits"/>
85+
8386

8487
<!--
8588
#############################################################################

WordPress/Helpers/EscapingFunctionsTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ trait EscapingFunctionsTrait {
214214
*
215215
* @return bool
216216
*/
217-
public function is_escaping_function( $functionName ) {
217+
final public function is_escaping_function( $functionName ) {
218218
if ( array() === $this->allEscapingFunctions
219219
|| $this->customEscapingFunctions !== $this->addedCustomEscapingFunctions['escape']
220220
) {
@@ -238,7 +238,7 @@ public function is_escaping_function( $functionName ) {
238238
*
239239
* @return bool
240240
*/
241-
public function is_auto_escaped_function( $functionName ) {
241+
final public function is_auto_escaped_function( $functionName ) {
242242
if ( array() === $this->allAutoEscapedFunctions
243243
|| $this->customAutoEscapedFunctions !== $this->addedCustomEscapingFunctions['autoescape']
244244
) {

WordPress/Helpers/IsUnitTestTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ trait IsUnitTestTrait {
127127
*
128128
* @return array<string, bool>
129129
*/
130-
protected function get_all_test_classes() {
130+
final protected function get_all_test_classes() {
131131
if ( array() === $this->all_test_classes
132132
|| $this->custom_test_classes !== $this->added_custom_test_classes
133133
) {
@@ -179,7 +179,7 @@ protected function get_all_test_classes() {
179179
*
180180
* @return bool True if the class is a unit test class, false otherwise.
181181
*/
182-
protected function is_test_class( File $phpcsFile, $stackPtr ) {
182+
final protected function is_test_class( File $phpcsFile, $stackPtr ) {
183183

184184
$tokens = $phpcsFile->getTokens();
185185

WordPress/Helpers/MinimumWPVersionTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ trait MinimumWPVersionTrait {
9595
*
9696
* @return void
9797
*/
98-
protected function set_minimum_wp_version() {
98+
final protected function set_minimum_wp_version() {
9999
$minimum_wp_version = '';
100100

101101
// Use a ruleset provided value if available.
@@ -128,7 +128,7 @@ protected function set_minimum_wp_version() {
128128
*
129129
* @return bool
130130
*/
131-
protected function wp_version_compare( $version1, $version2, $operator ) {
131+
final protected function wp_version_compare( $version1, $version2, $operator ) {
132132
$version1 = $this->normalize_version_number( $version1 );
133133
$version2 = $this->normalize_version_number( $version2 );
134134

WordPress/Helpers/PrintingFunctionsTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ trait PrintingFunctionsTrait {
9292
*
9393
* @return array<string, bool>
9494
*/
95-
public function get_printing_functions() {
95+
final public function get_printing_functions() {
9696
if ( array() === $this->allPrintingFunctions
9797
|| $this->customPrintingFunctions !== $this->addedCustomPrintingFunctions
9898
) {
@@ -116,7 +116,7 @@ public function get_printing_functions() {
116116
*
117117
* @return bool
118118
*/
119-
public function is_printing_function( $functionName ) {
119+
final public function is_printing_function( $functionName ) {
120120
return isset( $this->get_printing_functions()[ strtolower( $functionName ) ] );
121121
}
122122
}

WordPress/Helpers/SanitizationHelperTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ trait SanitizationHelperTrait {
190190
*
191191
* @return array<string, bool>
192192
*/
193-
public function get_sanitizing_functions() {
193+
final public function get_sanitizing_functions() {
194194
if ( array() === $this->allSanitizingFunctions
195195
|| $this->customSanitizingFunctions !== $this->addedCustomSanitizingFunctions['sanitize']
196196
) {
@@ -212,7 +212,7 @@ public function get_sanitizing_functions() {
212212
*
213213
* @return array<string, bool>
214214
*/
215-
public function get_sanitizing_and_unslashing_functions() {
215+
final public function get_sanitizing_and_unslashing_functions() {
216216
if ( array() === $this->allUnslashingSanitizingFunctions
217217
|| $this->customUnslashingSanitizingFunctions !== $this->addedCustomSanitizingFunctions['unslashsanitize']
218218
) {
@@ -236,7 +236,7 @@ public function get_sanitizing_and_unslashing_functions() {
236236
*
237237
* @return bool
238238
*/
239-
public function is_sanitizing_function( $functionName ) {
239+
final public function is_sanitizing_function( $functionName ) {
240240
return isset( $this->get_sanitizing_functions()[ strtolower( $functionName ) ] );
241241
}
242242

@@ -249,7 +249,7 @@ public function is_sanitizing_function( $functionName ) {
249249
*
250250
* @return bool
251251
*/
252-
public function is_sanitizing_and_unslashing_function( $functionName ) {
252+
final public function is_sanitizing_and_unslashing_function( $functionName ) {
253253
return isset( $this->get_sanitizing_and_unslashing_functions()[ strtolower( $functionName ) ] );
254254
}
255255

@@ -266,7 +266,7 @@ public function is_sanitizing_and_unslashing_function( $functionName ) {
266266
*
267267
* @return bool Whether the token is only within a sanitization.
268268
*/
269-
public function is_only_sanitized( File $phpcsFile, $stackPtr ) {
269+
final public function is_only_sanitized( File $phpcsFile, $stackPtr ) {
270270
$tokens = $phpcsFile->getTokens();
271271

272272
// If it isn't being sanitized at all.
@@ -317,7 +317,7 @@ public function is_only_sanitized( File $phpcsFile, $stackPtr ) {
317317
*
318318
* @return bool Whether the token is being sanitized.
319319
*/
320-
public function is_sanitized( File $phpcsFile, $stackPtr, $unslash_callback = null ) {
320+
final public function is_sanitized( File $phpcsFile, $stackPtr, $unslash_callback = null ) {
321321
$tokens = $phpcsFile->getTokens();
322322
$require_unslash = is_callable( $unslash_callback );
323323

WordPress/Helpers/WPDBTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ trait WPDBTrait {
4747
*
4848
* @return bool Whether this is a $wpdb method call.
4949
*/
50-
protected function is_wpdb_method_call( File $phpcsFile, $stackPtr, $target_methods ) {
50+
final protected function is_wpdb_method_call( File $phpcsFile, $stackPtr, $target_methods ) {
5151
$tokens = $phpcsFile->getTokens();
5252
if ( isset( $tokens[ $stackPtr ] ) === false ) {
5353
return false;

0 commit comments

Comments
 (0)