Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I am on symfony 7.4.2, and I am using the new/recommended App::config approach for configuration. I have this config, and phpstan has some buggy behavior around it:

<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
use SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension;
use SensioLabs\AnsiConverter\Theme\SolarizedXTermTheme;

return App::config([
    'services' => [
       '_defaults' => [
           'autowire' => true,
           'autoconfigure' => true,
       ],

       AnsiExtension::class => [],
       SolarizedXTermTheme::class => [],

       AnsiToHtmlConverter::class => [
            'arguments' => [
                '$theme' => service(SolarizedXTermTheme::class),
            ],
        ],
    ],
]);

Sometimes phpstan reports it as clean, other times it report service() method not found. The service() method is indeed in the namespace. I can't figure out how or why the intermittent false possitive happens. I have just ignored the file for now in phpstan.neon but I don't like that.

Any ideas, or suggestions for how I should debug further?

Thanks!

You must be logged in to vote

Replies: 4 comments · 1 reply

Comment options

Please show the whole error message that is reported. Also creating a small repository that reproduces the problem might be helpful, but maybe too hard to do.

You must be logged in to vote
0 replies
Comment options

appoloies

Note: Using configuration file /home/user/code/phpstan.neon.
Result cache restored. 0 files will be reanalysed.
 462/462 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec

Result cache is saved.
 ------ ---------------------------------------------------------------------- 
  Line   config/packages/ansi_to_html.php                                      
 ------ ---------------------------------------------------------------------- 
  24     Function service not found.                                           
         🪪  function.notFound                                                 
         💡  Learn more at https://phpstan.org/user-guide/discovering-symbols  
 ------ ---------------------------------------------------------------------- 


                                                                                                                        
 [ERROR] Found 1 error                                                                                                  
                                                                                                                        

PHP runtime version: 8.5.1
PHP composer.json required version: 8.5-8.5.99
PHP version for analysis: 8.5 (from config)

PHPStan version: 2.1.33
PHPStan running from:
/home/user/code/vendor/phpstan/phpstan

Extension installer:
phpstan/phpstan-deprecation-rules: 2.0.3
phpstan/phpstan-doctrine: 2.0.12
phpstan/phpstan-phpunit: 2.0.10
phpstan/phpstan-symfony: 2.0.9

Included configs from Composer packages:
custom/api-bundle (phpstan.ResultOrPromise.neon): dev-php85-symfony74
custom/api-bundle (phpstan.Type.neon): dev-php85-symfony74

Discovered Composer project root:
/home/user/code

Doctrine's objectManagerLoader: In use
Detected driver: pdo_mysql
Installed Doctrine packages:
doctrine/dbal: 4.4.1
doctrine/orm: 3.5.8
doctrine/collections: 2.4.0
doctrine/persistence: 4.1.1

Symfony's consoleApplicationLoader: In use

Elapsed time: 1.56 seconds
Used memory: 109.45 MB
You must be logged in to vote
1 reply
@ondrejmirtes
Comment options

Is this supposed to be a global function without a namespace? Where it's defined?

Comment options

$ grep -rF 'function service(' vendor/symfony/
vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php:function service(string $serviceId): ReferenceConfigurator

here: https://github.com/symfony/symfony/blob/8.1/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php#L106-L112

My config is in that namespace: namespace Symfony\Component\DependencyInjection\Loader\Configurator;

You must be logged in to vote
0 replies
Comment options

https://symfony.com/doc/current/service_container.html

#example php config
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\Service\MessageGenerator;

return function(ContainerConfigurator $container): void {
    $services = $container->services();

    $services->set(MessageGenerator::class)
        ->args([service('logger')])
    ;
};

using the raw string passes phpstan but the app doesn't run, vice versa the app runs but phpstan is unhappy

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.