Skip to content

Commit

Permalink
General: update our PHP version requirements to PHP 7.0 (#34126)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Jorsch <[email protected]>
Co-authored-by: anomiex <[email protected]>
Co-authored-by: Brandon Kraft <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2023
1 parent b610d62 commit b62f68f
Show file tree
Hide file tree
Showing 130 changed files with 397 additions and 587 deletions.
2 changes: 1 addition & 1 deletion .github/actions/tool-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
# Read tool versions
. .github/versions.sh
if [[ "${INPUT_PHP:-$PHP_VERSION}" == 5.6 || "${INPUT_PHP:-$PHP_VERSION}" == 7.[01] ]]; then
if [[ "${INPUT_PHP:-$PHP_VERSION}" == 7.[01] ]]; then
printf "Downgrading composer for PHP %s\n\n" "${INPUT_PHP:-$PHP_VERSION}"
COMPOSER_VERSION=2.2.12
fi
Expand Down
2 changes: 1 addition & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// Monorepo packages are excluded in renovate-config.js, where we can read
// the list of them in code.

// We need to keep a wide version range to support PHP 5.6.
// We need to keep a wide version range to support PHP 7.0.
// Note for libraries used in plugins this will only work right for require-dev deps, not require.
{
matchPackageNames: [
Expand Down
2 changes: 1 addition & 1 deletion .github/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ NODE_VERSION=20.8.1
PNPM_VERSION=8.6.8

# Other useful version numbers.
MIN_PHP_VERSION=5.6
MIN_PHP_VERSION=7.0
MAX_PHP_VERSION=8.2
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '5.6', '7.0', '7.2', '7.4', '8.0', '8.1', '8.2' ]
php-versions: [ '7.0', '7.2', '7.4', '8.0', '8.1', '8.2' ]
experimental: [ false ]

steps:
Expand Down
2 changes: 1 addition & 1 deletion docs/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ These are some things to keep in mind when writing code for Jetpack plugin. Plea

## Versions supported

- Jetpack supports PHP 5.6, as per WordPress' own requirements. Keep that in mind when developing for Jetpack.
- Jetpack supports PHP 7.0, as per WordPress' own requirements. Keep that in mind when developing for Jetpack.
- Jetpack follows [WordPress Core's standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/), with a few additions. The best way to ensure that you adhere to those standards is to set up your IDE [as per the recommendations here](./development-environment.md#use-php-codesniffer-and-eslint-to-make-sure-your-code-respects-coding-standards).
- Jetpack supports the WP current version and the immediate previous version. So if WP version is 4.6, Jetpack will support it, as well as 4.5. It's desirable that when Jetpack is installed in older versions, it doesn't fail in a severe way.
- We support the latest two versions of all major browsers, except IE, where we currently only support 11 and Edge. (see [Browse Happy](http://browsehappy.com) for current latest versions).
Expand Down
4 changes: 2 additions & 2 deletions docs/development-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ We strongly recommend that you install tools to review your code in your IDE. It
composer phpcs:lint
```

* ### Checking Jetpack's PHP for compatibility with different versions of PHP since 5.6
* ### Checking Jetpack's PHP for compatibility with different versions of PHP since 7.0

We have a handy `composer` script that will just run the PHP CodeSniffer `PHPCompatibilityWP` ruleset checking for code not compatible with PHP 5.6
We have a handy `composer` script that will just run the PHP CodeSniffer `PHPCompatibilityWP` ruleset checking for code not compatible with PHP 7.0

```sh
composer phpcs:compatibility
Expand Down
6 changes: 3 additions & 3 deletions docs/monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ All GitHub Actions configuration for the monorepo, including CI, lives in `.gith

## Compatibility

All projects should be compatible with PHP versions WordPress supports. That's currently PHP 5.6 to 8.0.
All projects should be compatible with PHP versions WordPress supports. That's currently PHP 7.0 to 8.2.

## First Time

Expand Down Expand Up @@ -210,15 +210,15 @@ If a project contains PHP tests (typically PHPUnit), it must define `.scripts.te

A MySQL database is available if needed; credentials may be found in `~/.my.cnf`. Note that the host must be specified as `127.0.0.1`, as when passed `localhost` PHP will try to connect via a Unix domain socket which is not available in the Actions environment.

Tests are run with a variety of supported PHP versions from 5.6 to 8.0. If you have tests that only need to be run once, run them when `PHP_VERSION` matches that in `.github/versions.sh`.
Tests are run with a variety of supported PHP versions from 7.0 to 8.2. If you have tests that only need to be run once, run them when `PHP_VERSION` matches that in `.github/versions.sh`.

#### PHP tests for non-plugins

For all project types other than WordPress plugins, the necessary version of PHPUnit and/or any other tools should be pulled in via Composer.

We currently make use of the following packages in testing; it's encouraged to use these rather than introducing other tools that serve the same purpose.

* [yoast/phpunit-polyfills](https://packagist.org/packages/yoast/phpunit-polyfills) supplies polyfills for compatibility with PHPUnit 5.7 to 9.0, to support PHP 5.6 to 8.0.
* [yoast/phpunit-polyfills](https://packagist.org/packages/yoast/phpunit-polyfills) supplies polyfills for compatibility with PHPUnit 6.5 to 9.0, to support PHP 7.0 to 8.2.
* Do not use `Yoast\PHPUnitPolyfills\TestCases\TestCase` or `Yoast\PHPUnitPolyfills\TestCases\XTestCase`. Just use the `@before`, `@after`, `@beforeClass`, and `@afterClass` annotations directly.
* PHPUnit's built-in mocking is used for class mocks.
* [brain/monkey](https://packagist.org/packages/brain/monkey) is used for mocking functions, and can also provide some functions for minimal WordPress compatibility.
Expand Down
2 changes: 1 addition & 1 deletion docs/testing/regression-checklist/regression-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NOTE: it might become outdated, so it could be a good idea to generate this file

### PHP versions(Low)

- 5.6 - current
- 7.0 - current

### Hosting providers(High)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

General: updated PHP requirement to PHP 7.0+
4 changes: 2 additions & 2 deletions projects/packages/changelogger/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev"
],
"require": {
"php": ">=5.6",
"php": ">=7.0",
"symfony/console": "^3.4 || ^5.2 || ^6.0",
"symfony/process": "^3.4 || ^5.2 || ^6.0",
"wikimedia/at-ease": "^1.2 || ^2.0"
Expand Down Expand Up @@ -58,7 +58,7 @@
"extra": {
"autotagger": true,
"branch-alias": {
"dev-trunk": "3.3.x-dev"
"dev-trunk": "4.0.x-dev"
},
"mirror-repo": "Automattic/jetpack-changelogger",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/changelogger/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class Application extends SymfonyApplication {

const VERSION = '3.3.11';
const VERSION = '4.0.0-alpha';

/**
* Constructor.
Expand Down
98 changes: 89 additions & 9 deletions projects/packages/changelogger/src/CommandLoader.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,98 @@
<?php
/**
* Compatibility stub for Symfony 6 changes.
*
* Symfony 6 (for PHP 8.0+) added return type hints to its interface. But we still support PHP 5.6, which doesn't recognize that syntax.
* Since specifying a return type when the interface doesn't is ok, use the version that always does that for PHP 7+ instead of figuring
* out how to check the actual symfony version.
* Command loader for the changelogger tool CLI.
*
* @package automattic/jetpack-changelogger
*/

namespace Automattic\Jetpack\Changelogger;

if ( PHP_VERSION_ID >= 70000 ) {
class_alias( php7\CommandLoader::class, CommandLoader::class );
} else {
class_alias( php5\CommandLoader::class, CommandLoader::class );
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Exception\CommandNotFoundException;

/**
* Command loader for the changelogger tool CLI.
*/
class CommandLoader implements CommandLoaderInterface {
/**
* Get the class name for a command.
*
* @param string $name Command name.
* @return string Class name.
*/
private function get_class_name( $name ) {
return __NAMESPACE__ . '\\' . ucfirst( $name ) . 'Command';
}

/**
* Checks if a command exists.
*
* @param string $name Command name.
* @return bool
*/
protected function doHas( $name ) {
return class_exists( $this->get_class_name( $name ) );
}

/**
* Loads a command.
*
* @param string $name Command name.
* @return Command
* @throws CommandNotFoundException If the command is not found.
*/
protected function doGet( $name ) {
$class = $this->get_class_name( $name );
if ( ! class_exists( $class ) ) {
throw new CommandNotFoundException( "Command \"$name\" does not exist." );
}
return new $class();
}

/**
* Return all command names.
*
* @return string[] All registered command names
*/
protected function doGetNames() {
$names = array();
foreach ( new \DirectoryIterator( __DIR__ ) as $file ) {
if ( substr( $file->getBasename(), -11 ) === 'Command.php' ) {
$names[] = lcfirst( substr( $file->getBasename(), 0, -11 ) );
}
}
sort( $names );
return $names;
}

/**
* Checks if a command exists.
*
* @param string $name Command name.
* @return bool
*/
public function has( $name ): bool {
return $this->doHas( $name );
}

/**
* Loads a command.
*
* @param string $name Command name.
* @return Command
* @throws CommandNotFoundException If the command is not found.
*/
public function get( $name ): Command {
return $this->doGet( $name );
}

/**
* Return all command names.
*
* @return string[] All registered command names
*/
public function getNames(): array {
return $this->doGetNames();
}
}
70 changes: 0 additions & 70 deletions projects/packages/changelogger/src/CommandLoaderBase.php

This file was deleted.

47 changes: 0 additions & 47 deletions projects/packages/changelogger/src/php5/CommandLoader.php

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions projects/packages/changelogger/src/php7/.phpcs.dir.xml

This file was deleted.

Loading

0 comments on commit b62f68f

Please sign in to comment.