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

Fix passing null to ltrim() #105

Closed

Conversation

JSn1nj4
Copy link

@JSn1nj4 JSn1nj4 commented Apr 23, 2024

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
Copy link
Author

JSn1nj4 commented Apr 23, 2024

@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... 😅

@kevindees
Copy link
Member

kevindees commented May 16, 2024

I fixed this using string casting.

@JSn1nj4
Copy link
Author

JSn1nj4 commented May 18, 2024

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

@kevindees
Copy link
Member

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

@JSn1nj4
Copy link
Author

JSn1nj4 commented May 22, 2024

Oh, awesome, thanks!

@JSn1nj4 JSn1nj4 closed this May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants