[wp-trac] [WordPress Trac] #61694: Ensure compat functions do not rely on external functions
WordPress Trac
noreply at wordpress.org
Tue Aug 13 17:53:12 UTC 2024
#61694: Ensure compat functions do not rely on external functions
----------------------------+---------------------
Reporter: jorbin | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.7
Component: Bootstrap/Load | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
----------------------------+---------------------
Comment (by jrf):
Replying to [comment:7 jorbin]:
> @jrf Are you aware of any existing sniffs that check to see if a file
only contains either functions defined in the file or functions in the PHP
standard library so that we don't need to duplicate work?
@jorbin No, I'm not aware of any such sniff existing. Would be quite
doable to write in principle, but will never do exactly what you want -
`get_defined_functions()['internal']` (which such a sniff would use too)
will get you all the functions defined at ''runtime'' of the sniff and has
no information on whether the function is defined in the PHP standard/Core
library', in a bundled, always-on PHP extension or in an optional or even
a PECL extension which happens to be enabled in the runtime running the
sniff/script.
I don't think adding sniffs to WP itself (or Gutenberg) is a good idea (at
all, ever).
Adding it to WPCS is also not an option, as that would automatically
enforce the rule on all files being scanned by WPCS, not just on the
`compat.php` file, which would have undesired consequences.
A sniff like this could live in the PHPCSExtra library, which is used by
WPCS anyway. This also means that the sniff could then be used by WP Core
via an explicit `rule` include in the `phpcs.xml.dist` file (and applied
to specific file(s) only).
I have a utility lined up for PHPCSUtils 1.2.0 which will make writing the
sniff straight-forward (and reliable).
If so desired, knowing the limitations, please open an issue in
PHPCSExtra.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61694#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list