felixarntz / wp-oop-plugin-lib

A library providing classes around WordPress APIs, to be used for example in object oriented WordPress plugins.
GNU General Public License v2.0
51 stars 3 forks source link

WordPress compatibility #5

Open szepeviktor opened 1 month ago

szepeviktor commented 1 month ago

Enhancement Description

From 8631681

You can check WordPress compatibility with johnbillion/wp-compat which is a PHPStan extension, PHP compatibility with phpcompatibility/php-compatibility which is a PHPCS ruleset.

imfaizanakram commented 1 month ago

1. Check WordPress Compatibility using johnbillion/wp-compat (PHPStan Extension)

Steps to set up johnbillion/wp-compat: 1.Install PHPStan: First, you need to install PHPStan in your project (if not already installed):

composer require --dev phpstan/phpstan

2.Install the wp-compat extension: Now, install the johnbillion/wp-compat extension:

composer require --dev johnbillion/wp-compat

3.Configure PHPStan: Create a phpstan.neon file in the root directory of your project if you don't already have one. Add the following configuration:

includes: -vendor/johnbillion/wp-compat/extension.neon

4.Run PHPStan: Once everything is set up, you can run PHPStan to analyze your WordPress project for compatibility issues:

vendor/bin/phpstan analyse

This will check for any WordPress-related compatibility issues in your codebase.

2. Check PHP Compatibility using phpcompatibility/php-compatibility (PHPCS Ruleset) Steps to set up phpcompatibility/php-compatibility:

Install PHPCS: If you haven't installed PHPCS (PHP Code Sniffer), you need to do that first:

composer require --dev squizlabs/php_codesniffer

Install PHP Compatibility Standard: Next, you install the PHP Compatibility ruleset:

composer require --dev phpcompatibility/php-compatibility Set up PHPCS: After installing the ruleset, you need to add the PHPCompatibility standard to PHPCS. You can configure this by running:

vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility Run PHPCS with PHP Compatibility: Now you can run PHPCS with the PHPCompatibility standard to check your codebase for PHP version compatibility:

vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 7.4 . Replace 7.4 with the version of PHP you want to test compatibility for. For example, if you want to check compatibility with PHP 8.0, use 8.0.

3. Combining Both Compatibility Checks You can set up both tools and run them independently to ensure that your WordPress site is compatible both with WordPress best practices and the PHP version you are targeting.

This setup will help you identify compatibility issues in your WordPress project related to both WordPress core and the PHP version being used.

felixarntz commented 2 weeks ago

@johnbillion Curious: Since johnbillion/wp-compat appears to be focused on WordPress plugins and themes, I wonder whether/how it would work with a library like this. I see the readme mentions style.css and plugin main file, but neither exist here. Is there a recommended way to use this for a WordPress library (e.g. manually specify the version range that is supposed to be supported)?

johnbillion commented 2 weeks ago

@felixarntz Yep you can manually configure it: https://github.com/johnbillion/wp-compat?tab=readme-ov-file#manual-config

johnbillion commented 2 weeks ago

wp-compat only works for core symbols that have a @since tag so it won't have detected the CaseInsensitiveDictionary issue anyway. Not much that we can do about that unless somebody wants to maintain a mapping of when certain third party library symbols were introduced into core.