nunomaduro / phpinsights

🔰 Instant PHP quality checks from your console
https://phpinsights.com
MIT License
5.29k stars 282 forks source link

wmic is not recognized as an internal or external command on a clean install of Windows 11 24H2 #696

Open hdcore opened 1 day ago

hdcore commented 1 day ago
Q A
Bug report? yes
Feature request? no
Library version 2.11.0 who is reporting itself as 2.10
PHP version 8.3.10
Windows version 24H2 clean install (no upgrade)

I've installed my computer with a clean install of the most recent Windows 24H2 installation media. The error I've got is:

phpinsights analyse --no-interaction --ansi 'wmic' is not recognized as an internal or external command, operable program or batch file. 'wmic' is not recognized as an internal or external command, operable program or batch file. 'wmic' is not recognized as an internal or external command, operable program or batch file. 'wmic' is not recognized as an internal or external command, operable program or batch file. 'wmic' is not recognized as an internal or external command, operable program or batch file.

Fatal error: Uncaught DivisionByZeroError: Division by zero in C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Runner.php:115 Stack trace:

0 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightFactory.php(98): NunoMaduro\PhpInsights\Domain\Runner->run()

1 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightFactory.php(69): NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->runInsightCollector()

2 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightCollectionFactory.php(67): NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->makeFrom()

3 [internal function]: NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory::NunoMaduro\PhpInsights\Domain\Insights{closure}()

4 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightCollectionFactory.php(66): array_map()

5 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Application\Console\Analyser.php(36): NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory->get()

6 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Application\Console\Commands\AnalyseCommand.php(65): NunoMaduro\PhpInsights\Application\Console\Analyser->analyse()

7 [internal function]: NunoMaduro\PhpInsights\Application\Console\Commands\AnalyseCommand->__invoke()

8 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Application\Console\Commands\InvokableCommand.php(41): call_user_func()

9 C:\WAMP\APPS\php-qa\vendor\symfony\console\Command\Command.php(279): NunoMaduro\PhpInsights\Application\Console\Commands\InvokableCommand->execute()

10 C:\WAMP\APPS\php-qa\vendor\symfony\console\Application.php(1029): Symfony\Component\Console\Command\Command->run()

11 C:\WAMP\APPS\php-qa\vendor\symfony\console\Application.php(316): Symfony\Component\Console\Application->doRunCommand()

12 C:\WAMP\APPS\php-qa\vendor\symfony\console\Application.php(167): Symfony\Component\Console\Application->doRun()

13 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\bin\phpinsights(42): Symfony\Component\Console\Application->run()

14 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\bin\phpinsights(43): {closure}()

15 C:\WAMP\APPS\php-qa\vendor\bin\phpinsights(119): include('...')

16 {main}

thrown in C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Runner.php on line 115 PHP Fatal error: Uncaught DivisionByZeroError: Division by zero in C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Runner.php:115 Stack trace:

0 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightFactory.php(98): NunoMaduro\PhpInsights\Domain\Runner->run()

1 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightFactory.php(69): NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->runInsightCollector()

2 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightCollectionFactory.php(67): NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->makeFrom()

3 [internal function]: NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory::NunoMaduro\PhpInsights\Domain\Insights{closure}()

4 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Insights\InsightCollectionFactory.php(66): array_map()

5 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Application\Console\Analyser.php(36): NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory->get()

6 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Application\Console\Commands\AnalyseCommand.php(65): NunoMaduro\PhpInsights\Application\Console\Analyser->analyse()

7 [internal function]: NunoMaduro\PhpInsights\Application\Console\Commands\AnalyseCommand->__invoke()

8 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Application\Console\Commands\InvokableCommand.php(41): call_user_func()

9 C:\WAMP\APPS\php-qa\vendor\symfony\console\Command\Command.php(279): NunoMaduro\PhpInsights\Application\Console\Commands\InvokableCommand->execute()

10 C:\WAMP\APPS\php-qa\vendor\symfony\console\Application.php(1029): Symfony\Component\Console\Command\Command->run()

11 C:\WAMP\APPS\php-qa\vendor\symfony\console\Application.php(316): Symfony\Component\Console\Application->doRunCommand()

12 C:\WAMP\APPS\php-qa\vendor\symfony\console\Application.php(167): Symfony\Component\Console\Application->doRun()

13 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\bin\phpinsights(42): Symfony\Component\Console\Application->run()

14 C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\bin\phpinsights(43): {closure}()

15 C:\WAMP\APPS\php-qa\vendor\bin\phpinsights(119): include('...')

16 {main}

thrown in C:\WAMP\APPS\php-qa\vendor\nunomaduro\phpinsights\src\Domain\Runner.php on line 115 Script phpinsights analyse --no-interaction --ansi handling the phpinsights event returned with error code 255

Starting from Windows 24H2 the wmic command will not be installed by default. https://techcommunity.microsoft.com/t5/windows-it-pro-blog/wmi-command-line-wmic-utility-deprecation-next-steps/ba-p/4039242 . As a workaround I could install the feature manually https://techcommunity.microsoft.com/t5/windows-it-pro-blog/how-to-install-wmic-feature-on-demand-on-windows-11/ba-p/4189530 but this is not a future proof solution.

Can you replace the wmic command by another method or library?

Jibbarth commented 4 hours ago

Hello,

A solution could be to use the https://github.com/theofidry/cpu-core-counter lib instead of our own implementation, but I can see it use wmic also, so I'm not sure.

However, you can fix the number to threads in your phpinsights.php config file

    /*
    |--------------------------------------------------------------------------
    | Threads
    |--------------------------------------------------------------------------
    |
    | Here you may adjust how many threads (core) PHPInsights can use to perform
    | the analysis. This is optional, don't provide it and the tool will guess
    | the max core number available. It accepts null value or integer > 0.
    |
    */

    'threads' => 2, // For example