Skip to content

Commit 74cc15d

Browse files
authored
Deprecate the define method (#22)
* Deprecate the define method * Update baseline after adding entrypoint
1 parent 6daed52 commit 74cc15d

5 files changed

+27
-102
lines changed

bin/baseline.neon

-90
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ parameters:
4848
count: 2
4949
path: ../includes/acf-field-functions.php
5050

51-
-
52-
message: '#^Constant ACF_PATH not found\.$#'
53-
identifier: constant.notFound
54-
count: 1
55-
path: ../includes/acf-helper-functions.php
56-
5751
-
5852
message: '#^Function acf_set_filters\(\) should return array but return statement is missing\.$#'
5953
identifier: return.missing
@@ -126,24 +120,12 @@ parameters:
126120
count: 1
127121
path: ../includes/acf-user-functions.php
128122

129-
-
130-
message: '#^Constant ACF_PATH not found\.$#'
131-
identifier: constant.notFound
132-
count: 1
133-
path: ../includes/acf-utility-functions.php
134-
135123
-
136124
message: '#^Action callback returns string but should not return anything\.$#'
137125
identifier: return.void
138126
count: 1
139127
path: ../includes/admin/admin-internal-post-type-list.php
140128

141-
-
142-
message: '#^Constant ACF_PATH not found\.$#'
143-
identifier: constant.notFound
144-
count: 1
145-
path: ../includes/admin/admin-internal-post-type-list.php
146-
147129
-
148130
message: '#^Action callback returns string but should not return anything\.$#'
149131
identifier: return.void
@@ -168,12 +150,6 @@ parameters:
168150
count: 2
169151
path: ../includes/admin/admin-upgrade.php
170152

171-
-
172-
message: '#^Constant ACF_UPGRADE_VERSION not found\.$#'
173-
identifier: constant.notFound
174-
count: 1
175-
path: ../includes/admin/admin-upgrade.php
176-
177153
-
178154
message: '#^Action callback returns string but should not return anything\.$#'
179155
identifier: return.void
@@ -288,12 +264,6 @@ parameters:
288264
count: 1
289265
path: ../includes/admin/views/tools/tools.php
290266

291-
-
292-
message: '#^Constant ACF_VERSION not found\.$#'
293-
identifier: constant.notFound
294-
count: 2
295-
path: ../includes/admin/views/upgrade/network.php
296-
297267
-
298268
message: '#^Variable \$button_text might not be defined\.$#'
299269
identifier: variable.undefined
@@ -312,12 +282,6 @@ parameters:
312282
count: 1
313283
path: ../includes/admin/views/upgrade/notice.php
314284

315-
-
316-
message: '#^Constant ACF_VERSION not found\.$#'
317-
identifier: constant.notFound
318-
count: 1
319-
path: ../includes/admin/views/upgrade/upgrade.php
320-
321285
-
322286
message: '#^Function remove_filter invoked with 4 parameters, 2\-3 required\.$#'
323287
identifier: arguments.count
@@ -360,12 +324,6 @@ parameters:
360324
count: 1
361325
path: ../includes/api/api-term.php
362326

363-
-
364-
message: '#^Constant ACF_VERSION not found\.$#'
365-
identifier: constant.notFound
366-
count: 3
367-
path: ../includes/blocks.php
368-
369327
-
370328
message: '#^Access to an undefined property ACF_Data\:\:\$site_aliases\.$#'
371329
identifier: property.notFound
@@ -618,24 +576,6 @@ parameters:
618576
count: 1
619577
path: ../includes/revisions.php
620578

621-
-
622-
message: '#^Constant ACF_VERSION not found\.$#'
623-
identifier: constant.notFound
624-
count: 1
625-
path: ../includes/third-party.php
626-
627-
-
628-
message: '#^Constant ACF_UPGRADE_VERSION not found\.$#'
629-
identifier: constant.notFound
630-
count: 2
631-
path: ../includes/upgrades.php
632-
633-
-
634-
message: '#^Constant ACF_VERSION not found\.$#'
635-
identifier: constant.notFound
636-
count: 3
637-
path: ../includes/upgrades.php
638-
639579
-
640580
message: '#^Access to an undefined property acf_validation\:\:\$errors\.$#'
641581
identifier: property.notFound
@@ -648,36 +588,6 @@ parameters:
648588
count: 1
649589
path: ../includes/wpml.php
650590

651-
-
652-
message: '#^Constant ACF_BASENAME not found\.$#'
653-
identifier: constant.notFound
654-
count: 2
655-
path: ../secure-custom-fields.php
656-
657-
-
658-
message: '#^Constant ACF_FIELD_API_VERSION not found\.$#'
659-
identifier: constant.notFound
660-
count: 3
661-
path: ../secure-custom-fields.php
662-
663-
-
664-
message: '#^Constant ACF_MAJOR_VERSION not found\.$#'
665-
identifier: constant.notFound
666-
count: 4
667-
path: ../secure-custom-fields.php
668-
669-
-
670-
message: '#^Constant ACF_PATH not found\.$#'
671-
identifier: constant.notFound
672-
count: 2
673-
path: ../secure-custom-fields.php
674-
675-
-
676-
message: '#^Constant ACF_VERSION not found\.$#'
677-
identifier: constant.notFound
678-
count: 2
679-
path: ../secure-custom-fields.php
680-
681591
-
682592
message: '#^One or more @param tags has an invalid name or invalid syntax\.$#'
683593
identifier: phpDoc.parseError

bin/phpstan-bootstrap.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Bootstrap the plugin for PHPStan.
4+
*
5+
* Loads the plugin file as the entry point for PHPStan.
6+
*
7+
* @package WordPress/Secure-Custom-Fields
8+
*/
9+
10+
/**
11+
* Main plugin file. Will always be loaded.
12+
*/
13+
require_once __DIR__ . '/../secure-custom-fields.php';

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@test:phpstan"
7272
],
7373
"test:php": "phpunit",
74-
"test:phpstan": "phpstan analyze --memory-limit=2G"
74+
"test:phpstan": "phpstan analyze --memory-limit=2G",
75+
"test:phpstan:baseline": "phpstan analyze --memory-limit=2G --generate-baseline=bin/baseline.neon"
7576
}
7677
}

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ parameters:
1111
- docs
1212
- lang
1313
- wordpress
14+
bootstrapFiles:
15+
- bin/phpstan-bootstrap.php

secure-custom-fields.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
*/
2929
#[AllowDynamicProperties]
3030
class ACF {
31-
32-
3331
/**
3432
* The plugin version number.
3533
*
@@ -77,14 +75,14 @@ public function __construct() {
7775
public function initialize() {
7876

7977
// Define constants.
80-
$this->define( 'ACF', true );
81-
$this->define( 'ACF_PATH', plugin_dir_path( __FILE__ ) );
82-
$this->define( 'ACF_BASENAME', plugin_basename( __FILE__ ) );
83-
$this->define( 'ACF_VERSION', $this->version );
84-
$this->define( 'ACF_MAJOR_VERSION', 6 );
85-
$this->define( 'ACF_FIELD_API_VERSION', 5 );
86-
$this->define( 'ACF_UPGRADE_VERSION', '5.5.0' ); // Highest version with an upgrade routine. See upgrades.php.
87-
$this->define( 'ACF_PRO', true );
78+
defined( 'ACF' ) || define( 'ACF', true );
79+
defined( 'ACF_PATH' ) || define( 'ACF_PATH', plugin_dir_path( __FILE__ ) );
80+
defined( 'ACF_BASENAME' ) || define( 'ACF_BASENAME', plugin_basename( __FILE__ ) );
81+
defined( 'ACF_VERSION' ) || define( 'ACF_VERSION', $this->version );
82+
defined( 'ACF_MAJOR_VERSION' ) || define( 'ACF_MAJOR_VERSION', 6 );
83+
defined( 'ACF_FIELD_API_VERSION' ) || define( 'ACF_FIELD_API_VERSION', 5 );
84+
defined( 'ACF_UPGRADE_VERSION' ) || define( 'ACF_UPGRADE_VERSION', '5.5.0' ); // Highest version with an upgrade routine. See upgrades.php.
85+
defined( 'ACF_PRO' ) || define( 'ACF_PRO', true );
8886

8987
// Register activation hook.
9088
register_activation_hook( __FILE__, array( $this, 'acf_plugin_activated' ) );
@@ -585,14 +583,15 @@ public function posts_where( $where, $wp_query ) {
585583
/**
586584
* Defines a constant if doesnt already exist.
587585
*
588-
* @date 3/5/17
589586
* @since ACF 5.5.13
587+
* @deprecated 6.5.0 -- Use vanilla PHP defined() || define() instead.
590588
*
591589
* @param string $name The constant name.
592590
* @param mixed $value The constant value.
593591
* @return void
594592
*/
595593
public function define( $name, $value = true ) {
594+
_deprecated_function( __METHOD__, '6.5.0', 'defined() || define()' );
596595
if ( ! defined( $name ) ) {
597596
define( $name, $value );
598597
}

0 commit comments

Comments
 (0)