codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.35k stars 1.9k forks source link

Bug: Migrations Deprecated #3195

Closed MGatner closed 3 years ago

MGatner commented 4 years ago

name: Bug report about: Help us improve the framework by reporting bugs!


Direction I haven’t dug into this yet but PHPUnit tests are giving the following warning about Composer and PSR-4 compatibility:

Deprecation Notice: Class Myth\Auth\Database\Migrations\CreateAuthTables located in ./vendor/myth/auth/src/Database/Migrations/2017-11-20-223112_create_auth_tables.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

CodeIgniter 4 version develop branch

Affected module(s) Composer/PHPUnit

Context

michalsn commented 4 years ago

Hmm... since migrations are not really autoloaded via composer and we have our own system to auto-discover them by namespaces - I suppose it's not really an issue?

I haven't checked anything related to this, but there is something like exclude-from-classmap option in the composer file. Maybe this would help?

MGatner commented 4 years ago

That sounds exactly like what we need! Not urgent as this is just a warning, but good to look into.

MGatner commented 4 years ago

Actually, it looks to me like migrations don't even need to be namespaced. The runner uses the base namespace and then forces the subdirectory Database/Migrations so I think it ignores the actual namespace of the file altogether. I'm not sure if that would fix the warning or not but I don't believe it would affect the framework.

paulbalandan commented 4 years ago

I don't think Composer's deprecation notice is related to the namespace, but rather the clashing migration class name against the file name. The filename uses a date component prepended to the class name but the actual class name does not. Anyway, I fixed this in my current project by adding this to composer.json's autoload key.

        "exclude-from-classmap": [
            "**/Database/Migrations/**"
        ]
lonnieezell commented 3 years ago

@MGatner Is this still a concern?

MGatner commented 3 years ago

I think Paul's solution is the appropriate way to handle it. We should probably get this into the User Guide and the default composer.json files before closing this issue.