core icon indicating copy to clipboard operation
core copied to clipboard

Fix passing `null` to `ltrim()`

Open JSn1nj4 opened this issue 1 year ago • 1 comments

In TypeRocket\Console\Command, the getGalaxyMakeNamespace() method uses the $append var to decide whether to extend the namespace prefix for the command being created.

The error below was triggered by running ltrim() on $append when it was set to null, which is deprecated in PHP 8.2.

Since the existing ternary resulted in the constant TYPEROCKET_GALAXY_MAKE_NAMESPACE being returned outright anyway, this is now the direct behavior.

And as a result, the final return statement is only reachable when $append is a string.

[ErrorException]                                                              
  ltrim(): Passing null to parameter #1 ($string) of type string is deprecated  
                                                                                

Exception trace:
  at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/Command.php:281
 Spatie\Ignition\Ignition->renderError() at n/a:n/a
 ltrim() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/Command.php:281
 TypeRocket\Console\Command->getGalaxyMakeNamespace() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/Commands/MakeModel.php:80
 TypeRocket\Console\Commands\MakeModel->makeFile() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/Commands/MakeModel.php:63
 TypeRocket\Console\Commands\MakeModel->exec() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/Command.php:109
 TypeRocket\Console\Command->execute() at /app/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/symfony/console/Application.php:1014
 Symfony\Component\Console\Application->doRunCommand() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/GalaxyConsoleLauncher.php:116
 TypeRocket\Console\GalaxyConsoleLauncher->loadCommandsAndRun() at /app/wp-includes/class-wp-hook.php:322
 WP_Hook->apply_filters() at /app/wp-includes/class-wp-hook.php:348
 WP_Hook->do_action() at /app/wp-includes/plugin.php:517
 do_action() at /app/wp-settings.php:621
 require_once() at /app/wp-config.php:193
 require_once() at /app/wp-load.php:50
 require() at /app/wp-content/plugins/typerocket-v6/typerocket/vendor/typerocket/core/src/Console/GalaxyConsoleLauncher.php:64
 TypeRocket\Console\GalaxyConsoleLauncher->__construct() at /app/galaxy:20

JSn1nj4 avatar Apr 23 '24 02:04 JSn1nj4

@kevindees the error output might be confusing at first. I haven't switched this project away from the plugin because that's where I started. If you went to the plugin, you'd probably see the plugin still depending on typerocket/core 6.0.0-RC1 instead of the latest 6.0.

When trying to debug this, I manually updated the typerocket/core version in the plugin, so it's a little different in my copy of the plugin now.

I'm going to try to move away from the plugin to the composer package directly when I find some time. Doing that probably would've saved me another headache... :sweat_smile:

JSn1nj4 avatar Apr 23 '24 02:04 JSn1nj4

I fixed this using string casting.

kevindees avatar May 16 '24 18:05 kevindees

I mean, I can. But if $append isn't a string, TYPEROCKET_GALAXY_MAKE_NAMESPACE is all that gets returned anyway, right?

JSn1nj4 avatar May 18 '24 02:05 JSn1nj4

I'm sorry. That was a typo 🙈 I meant to say I "fixed" it, not that you should fix it.

kevindees avatar May 22 '24 18:05 kevindees

Oh, awesome, thanks!

JSn1nj4 avatar May 22 '24 20:05 JSn1nj4