Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 25, 2025

Proposed Changes

I'm very curious why the reported issue only appears to happen with a Drupal setup (and I cannot reproduce it, nor do our tests fail). All the same, I'm hoping this will fix it.

Note: yes, realpath() can return false, but that shouldn't be possible in this case as we only call it after we've already checked isPHPCodeSnifferInstalled().

Related Issues

Fixed #239 (hopefully)

I'm very curious why the reported issue only appears to happen with a Drupal setup (and I cannot reproduce it, nor do our tests fail). All the same, I'm hoping this will fix it.

Note: yes, `realpath()` can return `false`, but that shouldn't be possible in this case as we only call it after we've already checked `isPHPCodeSnifferInstalled()`.
@rpkoller
Copy link

rpkoller commented Jun 25, 2025

I've updated line 558 in src/plugin.php to return (string) realpath(InstalledVersions::getInstallPath(self::PACKAGE_NAME)); the error unfortunately persists, BUT it changed now to

In Process.php line 350:
                                       
  The provided cwd "" does not exist.

*on a fresh install of Drupal 11.x with php 8.3

@jrfnl
Copy link
Member Author

jrfnl commented Jun 25, 2025

Thanks for testing @rpkoller ! That sounds like realpath() returning false, so something must be off about the Composer API method as that shouldn't be possible.

I've just pushed a new commit to revert this line back to its v1.0 state. Would be great to get confirmation whether that does fix things.

@rpkoller
Copy link

rpkoller commented Jun 25, 2025

with your latest change to return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage()); a composer require runs through without an error again

@sharif-elshobkshy
Copy link

sharif-elshobkshy commented Jun 25, 2025

@jrfnl . Thank you for the PR.

That seems to fix the bug.

$ composer update
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package laminas/laminas-text is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
Hardening vendor directory with .htaccess and web.config files.
102 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../drupal/coder/coder_sniffer,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard
phpstan/extension-installer: Extensions installed
Cleaning installed packages.

@pandaskii
Copy link

@jrfnl

This new change resolves the issue.

I was troubleshooting it in the resolved install paths, and here are the results:

/app/vendor/squizlabs/php_codesniffer is the correct and expected path

DEBUG: loadInstalledPaths called
DEBUG: InstalledVersions path 1: /app/vendor/composer/../squizlabs/php_codesniffer (the new method from 1.1.0)
DEBUG: InstalledVersions path 2: /app/vendor/squizlabs/php_codesniffer

To debug this, I modified the following code accordingly.

/**
     * Returns the path to the PHP_CodeSniffer package installation location
     *
     * @return string
     */
    private function getPHPCodeSnifferInstallPath()
    {
        error_log("DEBUG: loadInstalledPaths called");
        $path1 = (string) InstalledVersions::getInstallPath(self::PACKAGE_NAME);
        $path2 = $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage());
        error_log("DEBUG: InstalledVersions path 1: " . $path1);
        error_log("DEBUG: InstalledVersions path 2: " . $path2);
        return $path2;
    }

@jrfnl
Copy link
Member Author

jrfnl commented Jun 25, 2025

Thanks everyone for testing and confirming! We'll get this out in a patch release soon.

Copy link
Member

@Potherca Potherca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge at will. (I've read #239.)

@jrfnl jrfnl merged commit 2d64426 into main Jun 25, 2025
75 checks passed
@jrfnl jrfnl deleted the feature/239-fix-composer-getinstalledpath branch June 25, 2025 20:23
@rfay
Copy link

rfay commented Jun 26, 2025

Could we have a release that includes this please?

@jrfnl
Copy link
Member Author

jrfnl commented Jun 26, 2025

@rfay Just waiting for an approval on #246.

@MarcHagen
Copy link

MarcHagen commented Jun 27, 2025

Side note, not only Drupal setups are affected. My personal dev pc (windows 🤷🏻) and multiple action workflows are failing with exactly the same error.

Adding this to the composer.json did the trick for now.
Also, yes, the change as proposed is also working, but need to wait for release version

	"conflict": {
		"dealerdirect/phpcodesniffer-composer-installer": "1.1.0"
	},

@jrfnl
Copy link
Member Author

jrfnl commented Jun 27, 2025

@MarcHagen Could you please add details about your setup to #239 ? We still haven't been able to pinpoint the underlying cause, so would be great to get more information to see if we can find a pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Composer update in a drupal stack will break after composer-installer new version

8 participants