zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

Regex validator constructor parameter type issue #197

Closed alextartan closed 6 years ago

alextartan commented 7 years ago

The current docblock lists @param string|Traversable $pattern, but arrays are accepted as well.

What should it receive to avoid any warnings?

I'm currently using:

new Regex(
    new \ArrayIterator(
        [
            'pattern'  => 'something', 
            'messages' => [
                Regex::NOT_MATCH => 'somethingElse'
            ]
        ]
    )
)

But it seems a bit of an overhead to wrap an array in an arrayIterator just to avoid a warning. I can. of course, extend the Regex validator and fix this in my codebase, but i figure i'm not the only one bumping into this isuue.

Since the $pattern parameter is passed to parent::__construct($param) which does accept @param array|Traversable $options, I'm guessing Regex should accept array as well

froschdesign commented 7 years ago

@alextartan

I'm guessing Regex should accept array as well

It accepts also an array. Only the DocBlock is missing this hint.

alextartan commented 7 years ago

@froschdesign I know. I made this Pull Request to fix the docblock https://github.com/zendframework/zend-validator/pull/198

alextartan commented 6 years ago

@froschdesign any news on this?

samsonasik commented 6 years ago

as #198 merged, it can be closed.