olvlvl / composer-attribute-collector

A convenient and near zero-cost way to retrieve targets of PHP 8 attributes
Other
145 stars 3 forks source link

class not found #1

Closed withinboredom closed 1 year ago

withinboredom commented 1 year ago

When running composer update or composer dump, the following error is generated:

PHP Fatal error:  Uncaught Error: Class "Composer\ClassMapGenerator\ClassMapGenerator" not found in ./vendor/olvlvl/composer-attribute-collector/src/ClassMapBuilder.php:44
olvlvl commented 1 year ago

Hi. Thanks for reporting an issue. Since the plugin is executed by Composer it's interesting that it cannot find the class. Could you share more? Maybe your composer.json?

withinboredom commented 1 year ago

This is the gist, try installing with this I guess.

{
  "name": "XXX/XXX",
  "type": "project",
  "autoload": {
    "psr-4": {
      "XXXX\\XXX\\": "src/"
    }
  },
  "authors": [
    {
      "name": "Robert Landers",
      "email": "XXX"
    }
  ],
  "require": {
    "php": ">=8.2",
    "slim/slim": "^4.11",
    "nyholm/psr7": "^1.5",
    "nyholm/psr7-server": "^1.0",
    "php-di/php-di": "^6.4",
    "php-di/slim-bridge": "^3.2"
  },
  "scripts": {
    "dev": [
      "docker run -it --rm -p 80:80 -p 443:443 -v $(pwd):/app -w /app dev-build:latest"
    ],
    "dev:build": [
      "docker build -t dev-build:latest ."
    ],
    "dev:cli": [
      "docker run -it --rm -p 80:80 -p 443:443 -v $(pwd):/app -w /app --user $(id -u) dev-build:latest /bin/bash"
    ]
  },
  "require-dev": {
    "pestphp/pest": "^1.22",
    "roave/security-advisories": "dev-latest"
  },
  "config": {
    "allow-plugins": {
      "pestphp/pest-plugin": true
    },
    "process-timeout": 0
  }
}

Since the plugin is executed by Composer it's interesting that it cannot find the class

That was my thought as well. I was hoping you'd already seen this after I scratched my head for a while because this really felt like a user-error issue. You know?

olvlvl commented 1 year ago

Thanks for the compose.json. This is what I did.

I created a Docker image to run with PHP 8.2:

FROM php:8.2-cli-buster

RUN echo '\
display_errors=On\n\
error_reporting=E_ALL\n\
date.timezone=UTC\n\
' >> /usr/local/etc/php/conf.d/php.ini

ENV COMPOSER_ALLOW_SUPERUSER 1

RUN apt-get update && \
    apt-get install unzip && \
    curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet && \
    mv composer.phar /usr/local/bin/composer && \
    echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"\n' >> /root/.bashrc

With this docker-compose.yaml:

---
version: "3.2"
services:
  app:
    build: .
    volumes:
    - .:/app:delegated
    working_dir: /app

I edited your composer.json to make it valid:

{
  "require": {
    "php": ">=8.2",
    "slim/slim": "^4.11",
    "nyholm/psr7": "^1.5",
    "nyholm/psr7-server": "^1.0",
    "php-di/php-di": "^6.4",
    "php-di/slim-bridge": "^3.2"
  },
  "scripts": {
    "dev": [
      "docker run -it --rm -p 80:80 -p 443:443 -v $(pwd):/app -w /app dev-build:latest"
    ],
    "dev:build": [
      "docker build -t dev-build:latest ."
    ],
    "dev:cli": [
      "docker run -it --rm -p 80:80 -p 443:443 -v $(pwd):/app -w /app --user $(id -u) dev-build:latest /bin/bash"
    ]
  },
  "require-dev": {
    "pestphp/pest": "^1.22",
    "roave/security-advisories": "dev-latest"
  },
  "config": {
    "allow-plugins": {
      "pestphp/pest-plugin": true,
      "olvlvl/composer-attribute-collector": true
    },
    "process-timeout": 0
  }
}

Running composer install gives me this:

image

Running composer require olvlvl/composer-attribute-collector gives me this:

image

And this is the resulting attributes.php:

<?php

// attributes.php @generated by https://github.com/olvlvl/composer-attribute-collector

namespace olvlvl\ComposerAttributeCollector;

Attributes::with(fn () => new Collection(
    targetClasses: [
        \AllowDynamicProperties::class => [
            [ [], \Laravel\SerializableClosure\Support\ClosureStream::class ],
        ],

    ],
    targetMethods: [

    ],
));

This is running with the latest version of composer: v2.5.0.

Could you try without the autoload maybe and see what it does?

olvlvl commented 1 year ago

I'm closing this issue because there was no response for a month. Please reopen if the problem persists.