Skip to content

PHP extension detection and requirements documentation #1392

@fredden

Description

@fredden

This is a follow-up to squizlabs/PHP_CodeSniffer#3754. See also #1388.

The lists of PHP extensions in composer.json's "require" and "suggest" sections are incomplete. Running maglnet/composer-require-checker as described in squizlabs/PHP_CodeSniffer#3754 on this codebase (as at 8b1c267) yields the following issues (and a long list of PHP_CodeSniffer-internal T_* constants).

ComposerRequireChecker 4.0.1-111-g8b1c26745-dev
The following unknown symbols were found:
+-------------------------------------------------------+--------------------+
| unknown symbol                                        | guessed dependency |
+-------------------------------------------------------+--------------------+
| Composer\Autoload\ClassLoader                         |                    |
| PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase |                    |
| PHP_CodeSniffer\Tests\ConfigDouble                    |                    |
| PHP_CODESNIFFER_VERBOSITY                             |                    |
| PHP_CODESNIFFER_CBF                                   |                    |
| iconv_strlen                                          | ext-iconv          |
| libxml_use_internal_errors                            | ext-libxml         |
| libxml_get_errors                                     | ext-libxml         |
| libxml_clear_errors                                   | ext-libxml         |
| json_encode                                           | ext-json           |
| iconv                                                 | ext-iconv          |
| DOMElement                                            | ext-dom            |
| DOMDocument                                           | ext-dom            |
| DOMNode                                               | ext-dom            |
| json_decode                                           | ext-json           |
| posix_isatty                                          | ext-posix          |
| pcntl_fork                                            | ext-pcntl          |
| pcntl_waitpid                                         | ext-pcntl          |
| pcntl_wexitstatus                                     | ext-pcntl          |
+-------------------------------------------------------+--------------------+

\Composer\Autoload\ClassLoader

No action required here.

The use of this class is wrapped in suitable safeguarding code.

PHP_CodeSniffer\Tests\Standards\AbstractSniffTestCase and PHP_CodeSniffer\Tests\ConfigDouble

No action required here.

These show up due to the way that I wrote the temporary 'autoload' section within composer.json and can safely be ignored.
This is a feature of the filesystem layout, having tests for each standard within the src/ directory.

PHP_CODESNIFFER_VERBOSITY and PHP_CODESNIFFER_CBF

No action required here.

These are internal PHP_CodeSniffer constants which are always defined in the entrypoints used to run PHP_CodeSniffer.

Similarly, there is a long list of T_* constants which showed up in the tool output, which I have validated and removed before opening this issue.

🔲 ext-dom

This extension is used within the "generator" feature, and is used by all three generators (HTML, Markdown, Text).
While this extension is enabled by default within PHP, it is possible to disable it at compile time.

Actions required:

🔲 ext-iconv

Actions required:

  • Create a new way for reports to declare what extensions they need.
    • Add a new constant to the Report interface (with a default value, thus making this feature optional). Reports will use this constant to declare what PHP extensions they require in order to operate properly.
    • Add a check to the start-up code. For each report that has been requested: loop through all of the PHP extensions that it declares are necessary and assert that these are loaded. If any required PHP extensions are not present, throw some kind of error with a suitable message to the user.
  • Add iconv to the list of "required extensions" for the 'checkstyle' report.
  • Add iconv to the list of "required extensions" for the 'junit' report.
  • Add iconv to the list of "required extensions" for the 'xml' report.
  • Update the wiki to show that this extension is required when using the these reports.- PR Wiki/Requirements: improve information about required PHP extensions PHP_CodeSniffer-documentation#97

🔲 ext-json

This extension is used without suitable checks in the 'json' report and the cache feature.
While this extension is enabled by default within PHP, it is possible to disable it at compile time for PHP versions below 8.0.
(From PHP 8.0 and above, this extension can no longer be disabled.)

Actions required:

🔲 ext-libxml

This extension is a requirement of the SimpleXML extension which we already declare a depenency on.
While this extension is enabled by default within PHP, it is possible to disable it at compile time.

Actions required:

🔲 ext-pcntl

This extension is not currently available on Windows. This extension powers the "parallel" feature.

We already detect the existence of this extension and silently disable the parallel feature. I have discussed this with @jrfnl and we have agreed that this "automatic disable" should remain silent.

Actions required:

✅ ext-posix

No action required here.

This is used in exactly one place within the codebase (\PHP_CodeSniffer\Util\Common::isStdinATTY()). It is wrapped in a suitable check, and the code safely falls back to other methods to detect if the output will be going to a terminal or not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions