Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EditorConfig and PHPStan #4

Merged
merged 3 commits into from
Jul 13, 2024
Merged

Add EditorConfig and PHPStan #4

merged 3 commits into from
Jul 13, 2024

Conversation

mcaskill
Copy link
Owner

@mcaskill mcaskill commented Jul 11, 2024

This pull request supersedes:

Checklist

  • I've read the Contributing page.
  • No issue.
  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

Description

Follow-up to junaidbhura#59 and fork of junaidbhura#58.

Depends on #2 being merged first.

Added an EditorConfig ruleset to enforce tabs for PHP files and spaces for JSON, Markdown, NEON, YML, and XML files. This should help avoid accidental mixing of tabs if one's IDE supports this feature.

Added PHPStan dependency to help finds bugs and logic flaws. Given that tests are absent and not so simple to write given the proprietary and expensive nature of its target WP plugins.

composer lint:phpstan -- --xdebug

PHPStan's situation is a little complicated given this plugin supports multiple versions of different packages (notably Composer and vlucas/phpdotenv). PHPStan can't tell that and reports errors for whichever version is not installed. To resolve this, I've introduced a way to conditionally include different baselines based on what is installed in order to hide "errors" from versions not installed.

This conditional functionality can be greatly reduced if we drop support for older versions of PHP, Composer, and other dependencies.

How has this been tested?

  • PHP 8.3
  • PHP 8.2
  • PHP 7.4
  • Composer 1.10
  • Composer 2.5
  • vlucas/phpdotenv 5.5
  • vlucas/phpdotenv 4.3
  • vlucas/phpdotenv 3.6

Types of changes

@mcaskill mcaskill marked this pull request as ready for review July 11, 2024 22:29
Enforces minimal coding styles to match existing coding styles inspired by WordPress' own styles.

Changed:
- Replaced inconsistent indentation in `RemoteFilesystem`.
- Removed colon in pull request template to match other titles.
Required:
- composer/composer ^1.0 or ^2.0
- phpstan/phpstan ^1.10

Usage:

```shell
composer lint:phpstan -- --xdebug
```
Based on the PHP version and installed package versions.

Added conditionally included baselines for PHP 5–7 and 8+, Composer 1 and 2, Dotenv 3–5.

This conditional functionality can be greatly reduced if we drop support for older versions of PHP, Composer, and other dependencies.

To resolve these conditional baselines, we have to replace the initial data of `Composer\InstalledVersions` which contains PHPStan's dependencies, since the context is its PHAR.

To accomplish this, we have to retrieve the contents of the project's installed dependencies from either:

1. `vendor/composer/installed.php` — Composer v2 PHP format.
2. `vendor/composer/installed.json` — Either Composer v1 or v2 JSON format.

The JSON format is tricky because it changes drastically between Composer v1 and v2 and the v2 PHP format. Both JSON formats must be remapped to the PHP format expected by `InstalledVersions`.

If the project's installed dependencies cannot be loaded, this file returns only the PHP baselines.

If the project's installed dependencies can be loaded, the extra baselines are resolved and the initial data of `InstalledVersions` is restored.
@mcaskill mcaskill merged commit fd9cb3b into main Jul 13, 2024
@mcaskill mcaskill deleted the feature/linting branch July 13, 2024 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant