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

missing use statements should trigger an error #46

Closed
schmunk42 opened this issue Dec 17, 2019 · 3 comments
Closed

missing use statements should trigger an error #46

schmunk42 opened this issue Dec 17, 2019 · 3 comments

Comments

@schmunk42
Copy link

What steps will reproduce the problem?

Use a config with missing namespaces

<?php
return [
    ServerRequestFactoryInterface::class => Psr17Factory::class,
];

What is the expected result?

An error.

What do you get instead?

Value parsed as...

'ServerRequestFactoryInterface' => 'Nyholm\\Psr7\\Factory\\Psr17Factory',

Additional info

Q A
Version dev-master 7fa31d1
Composer Version 1.9.1 2019-11-01 17:20:17
PHP version PHP 7.4.0
Operating system Debian
@rob006
Copy link

rob006 commented Dec 17, 2019

ServerRequestFactoryInterface::class evaluates to 'ServerRequestFactoryInterface' string (this is how PHP parser works). How config plugin could detect whether provided string is correct or not?

@schmunk42
Copy link
Author

How config plugin could detect whether provided string is correct or not?

Thinking loud, untested: class_exists($name)

@hiqsol
Copy link
Member

hiqsol commented Dec 18, 2019

<?php
return [
    ServerRequestFactoryInterface::class => Psr17Factory::class,
];

IMHO this cannot be parsed as:

    'ServerRequestFactoryInterface' => 'Nyholm\\Psr7\\Factory\\Psr17Factory',

Namespace Nyholm\Psr7\Factory is just nowhere to come from.

As to the main question about triggering an error, it is a known issue described in the README:

This plugin treats configs as simple PHP arrays. No specific structure or semantics are expected and handled. It is simple and straightforward, but I'm in doubt... What about errors and typos? I think about adding config validation rules provided together with plugins. Will it solve all the problems?

So, validators can be added. But specific validators should not be a part of the plugin.
I mean expecting class name in certain places in the configuration array is specific for Yii and those places are different for Yii 2 and 3 versions. And validation can go further than checking class names only.
The plugin could provide something like schema validation and packages could provide their schemas.

@hiqsol hiqsol closed this as completed Jun 30, 2020
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