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

Conflict with composer cmd scripts #780

Open
UVLabs opened this issue Jan 8, 2025 · 2 comments
Open

Conflict with composer cmd scripts #780

UVLabs opened this issue Jan 8, 2025 · 2 comments

Comments

@UVLabs
Copy link

UVLabs commented Jan 8, 2025

🐞 bug report

Behavior:

  • Freemius composer package causes conflict by stopping composer scripts from running as intended.

  • When PHPCodeSniffer is installed via composer using composer require --dev dealerdirect/phpcodesniffer-composer-installer the bin files it creates phpcbf and phpcs should be able to be referenced like this vendor/bin/phpcbf -p that will cause the library to run its behavior. However with the latest version of the SDK this doesn't work.

I reported to the PHPCodeSniffer team and they helped identify the issue. The discussion and reason for the issue can be seen here: PHPCSStandards/PHP_CodeSniffer#781

Versions: (*)

  • Freemius SDK Version: 2.10.1
  • WordPress Version: N/A
  • PHP Version: 8.1 (tried different versions, no difference)
@codex-m
Copy link

codex-m commented Jan 11, 2025

To add to this bug report, I see that it also affects PHP unit tests in a plugin. Previously, running the unit tests script via command line at the plugin root directory would run without any issues.

However, unit tests won't run if we load the Freemius SDK (version 2.10.1) via the composer vendor directory (autoloaded). I debugged this, and this is the issue: (start.php of Freemius SDK)

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

The problem is that when we execute tests in a command line environment - WordPress is never loaded, ABSPATH is never defined, and the tests will terminate.

However, if you change the above line from exit to return, the test will now work. If ABSPATH is not defined, it will simply bail out and run the rest (including tests).

Proposed solution:

if ( ! defined( 'ABSPATH' ) ) {
return;
}

Though I'm not sure about the consequences of using return for the rest of the Freemius SDK functionalities, this change requires thorough testing if we would like to adopt this approach.

@JUVOJustin
Copy link

I can confirm the proposal of @codex-m solves the issue for phpstan and phpcs.

In this context, I would propose to also add typings to the default sdk script output on the ui like this:

/**
 * Freemius init function
 *
 * @return Freemius
 * @throws Freemius_Exception Thrown when an API call returns an exception.
 */
function my_fs(): Freemius {
}

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

No branches or pull requests

3 participants