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

Unknown command leads to Undefined Index #64

Closed
alexz707 opened this issue Feb 24, 2021 · 1 comment · Fixed by #65
Closed

Unknown command leads to Undefined Index #64

alexz707 opened this issue Feb 24, 2021 · 1 comment · Fixed by #65
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@alexz707
Copy link

Bug Report

Q A
Laminas-CLI 1.0.0

Summary

When you provide an unknown command to the php file it will result in an Fatal Error:

`php laminas.php unknowncommand

PHP Notice: Undefined index: unknowncommand in /var/cli/importer/vendor/laminas/laminas-cli/src/AbstractContainerCommandLoader.php on line 64

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Laminas\ServiceManager\ServiceManager::Laminas\ServiceManager{closure}() must be of the type string, null given, called in /var/cli/importer/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 270 and defined in /var/cli/importer/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:262
Stack trace:
#0 /var/cli/importer/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(270): Laminas\ServiceManager\ServiceManager::Laminas\ServiceManager{closure}(NULL)
#1 /var/cli/importer/vendor/laminas/laminas-cli/src/AbstractContainerCommandLoader.php(64): Laminas\ServiceManager\ServiceManager->has(NULL)
#2 /var/cli/importer/vendor/laminas/laminas-cli/src/ContainerCommandLoaderTypeHint.php(22): Laminas\Cli\AbstractContainerCommandLoader->hasCommand('unknowncommand')
#3 /var/cli/importer/vendor/symfony/console/Application.php(551): Laminas\Cli\ContainerCommandLoaderTypeHint->has('unknowncommand')
#4 /var/cli/importer/vendor/symfony/console/Applicati in /var/cli/importer/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 262`

The reason is the following:

Problem 1 is the lookup in the array without checking if the key exists. (that's the notice)
Problem 2 is the missing cast to string of the array

In the AbstractContainerCommandLoader:

if ($this->container->has($this->commandMap[$name])) { return $this->fetchCommandFromContainer($name); }

Current behavior

A Fatal Error

How to reproduce

Just call it with an unknown command.

Expected behavior

Message that command is invalid or not registered.
No notices ;)

@alexz707 alexz707 added the Bug Something isn't working label Feb 24, 2021
@weierophinney weierophinney added this to the 1.0.1 milestone Feb 24, 2021
@weierophinney weierophinney self-assigned this Feb 24, 2021
weierophinney added a commit to weierophinney/laminas-cli that referenced this issue Feb 26, 2021
…om container

Updates `AbstractContainerCommandLoader::hasCommand()` to test if the `$name` exists in the `$commandMap` before attempting to check the container.
If not, it immediately returns false.

Fixes laminas#64

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
weierophinney added a commit to weierophinney/laminas-cli that referenced this issue Feb 26, 2021
…om container

Updates `AbstractContainerCommandLoader::hasCommand()` to test if the `$name` exists in the `$commandMap` before attempting to check the container.
If not, it immediately returns false.

Fixes laminas#64

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
weierophinney added a commit to weierophinney/laminas-cli that referenced this issue Feb 26, 2021
…om container

Updates `AbstractContainerCommandLoader::hasCommand()` to test if the `$name` exists in the `$commandMap` before attempting to check the container.
If not, it immediately returns false.

Fixes laminas#64

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney
Copy link
Member

Fixed with #65; 1.0.1 release will contain the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants