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

SM\\StateMachine\\StateMachine::getState(): Return value must be of type string, null returned #72

Open
matthewstick opened this issue Jun 5, 2024 · 1 comment

Comments

@matthewstick
Copy link

matthewstick commented Jun 5, 2024

In the getState function, sometimes $accessor->getValue can return null.

however, getState is expecting a return type of string, so it breaks the state machine.

If you add a check, this fixes it:

if (is_null($state)) { return ''; }

but maybe there is a better way?

`

    public function getState(): string
    {

    $accessor = new PropertyAccessor();
    $state = $accessor->getValue($this->object, $this->config['property_path']);
   
    if ($state instanceof \BackedEnum) {
        return $state->value;
    }

    if ($state instanceof \UnitEnum) {
        return $state->name;
    }


   // possible fix?
    if (is_null($state)) {
        return '';
    }

    return $state;
}

`

@matthewstick
Copy link
Author

hi @sebdesign . Tagging in case you didn't see it. This fix is working for me. Hoping not to fork your project, but let me know if this looks legit and you can implement? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant