Add hasOption method to NodeElement class.#766
Conversation
|
This will trigger 2 changes of the data of the form, to check whether it has an option or no. that's quite bad as implementation of the check. |
|
Yeah you are right with this. I will rewrite it to don't change the value of the select. |
src/Element/NodeElement.php
Outdated
| */ | ||
| public function hasOption($option){ | ||
| if ('select' !== $this->getTagName()) { | ||
| return; |
There was a problem hiding this comment.
this is wrong. It must return a boolean
There was a problem hiding this comment.
I writed this because if the element is not a select tag, It is not logical to return a boolean. That would be nice if I throw an exception instead of return null? Or editing the documentation of method to @return Boolean|null?
There was a problem hiding this comment.
IMO it's better to throw an exception.
src/Element/NodeElement.php
Outdated
| return; | ||
| } | ||
|
|
||
| $optionElement = $this->find('named', array('option', $option)); |
There was a problem hiding this comment.
You can safely inline this variable, because it's used only once.
In my case that was a useful method, to check that a select element has an option or not. And I think this will be also useful for others.