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

Determine return value from \Drupal\Core\Config\Config::get #753

Open
mstrelan opened this issue May 2, 2024 · 2 comments
Open

Determine return value from \Drupal\Core\Config\Config::get #753

mstrelan opened this issue May 2, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mstrelan
Copy link

mstrelan commented May 2, 2024

Feature request

\Drupal\Core\Config\Config::get returns mixed.

Given the following code in a functional test:

$theme = $this->config('system.theme')->get('default');
$this->assertStringContainsString('foo', $theme);

When I analyze it with phpstan level 9 I get:

Parameter #2 $haystack of method PHPUnit\Framework\Assert::assertStringContainsString() expects string, mixed given. 

However we have config schema for system.theme that says that default is a string. Perhaps we can figure this out in phpstan-drupal so we don't need to make assertions about the data. However it might not be wise to do this. If we put the same code in to a kernel test then $theme is in fact null, so phpstan is right to complain about it.

@mstrelan mstrelan added the enhancement New feature or request label May 2, 2024
@mglaman
Copy link
Owner

mglaman commented May 4, 2024

The one hard part I foresee: I'm pretty sure the typed config manager is stateful. If it doesn't rely on the database at all and only plugin discovery maybe we can make this work

@simesy
Copy link

simesy commented Jun 11, 2024

Why not contribute a method(s) to the class in Drupal that returns explicit types, and even throws an exception if the type is not a match? It seems like methods for scalar types like Config::getString() should be feasible? The caller is responsible for knowing what type to expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants