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

Composite Iterator with PHP #19

Open
matiux opened this issue Jul 13, 2018 · 1 comment
Open

Composite Iterator with PHP #19

matiux opened this issue Jul 13, 2018 · 1 comment

Comments

@matiux
Copy link

matiux commented Jul 13, 2018

Hi, I have a problem with printVegetarianMenu() methos in Composite Iterator Pattern.
This is my method:

    public function printVegetarianMenu()
    {
        $iterator = $this->allMenus->createIterator();

        echo sprintf("\nVEGETARIAN MENU\n----");

        while ($iterator->valid()) {

            /** @var MenuComponent $menuComponent */
            $menuComponent = $iterator->current();
            $iterator->next();

            try {

                if ($menuComponent->isVegetarian()) {

                    $menuComponent->print();
                }
            } catch (\LogicException $e) {}
        }
    }

I do not know if it's a difference between java and PHP but my method doesn't print nothing because the while condition iterate only over menus so, obviusly the isVegetarian() method throws always an exception.

Do you have any idea about it?

@Woolfy80
Copy link

Woolfy80 commented Mar 25, 2019

may be $menuComponent must be a not menuComponent class?
extender MenuItem implements isVegetarian() as getter, not thower of exception, like a parent.

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

2 participants