composer / composer

Dependency Manager for PHP

Home Page:https://getcomposer.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

--strict-psr Doesn't warn about about classes where namespace is not set or does not start with configured namespace

PrinsFrank opened this issue · comments

My composer.json:

{
    "name": "example/example",
    "description": "",
    "license": "MIT",
    "autoload": {
        "psr-4": {
            "Foo\\": "src/"
        }
    }
}

Output of composer diagnose:

Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK git version 2.39.3
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952
OK
Checking Composer version: OK
Checking Composer and its dependencies for vulnerabilities: OK
Composer version: 2.7.4
PHP version: 8.3.3
PHP binary path: /opt/homebrew/Cellar/php/8.3.3_1/bin/php
OpenSSL version: OpenSSL 3.2.1 30 Jan 2024
cURL version: 8.6.0 libz 1.2.12 ssl (SecureTransport) OpenSSL/3.2.1
zip: extension present, unzip present, 7-Zip not available

When I run this command:

composer du --strict-psr --optimize

With the two following classes:

src/Bar.php

<?php
class Bar {}

src/Boop.php

<?php
namespace Boop;
class Boop {}

I get the following output:

Generating optimized autoload files
Generated optimized autoload files containing 1 classes

And I expected this to happen:

Generating optimized autoload files
+ Class Bar located in ./src/Bar.php does not comply with psr-4 autoloading standard. Skipping.
+ Class Boop\Boop located in ./src/Boop.php does not comply with psr-4 autoloading standard. Skipping.
Generated optimized autoload files containing 1 classes

Only classes that are outside the configured for a folder get ignored. So if src/ is configured with namespace Foo\\, if the class misses a namespace or is in a totally different namespace like Bar\\, it doesn't trigger any errors when running with --strict-psr.

Alright finally got it built into Composer via dc857b4