php method that checks two strings in a variable

0
Does anyone know of any method in PHP that equals the value of a variable with string ?

I need to refactor the following code:

 public function hasPlan() : bool
{
    return $this->reference === 'unico' || $this->reference === 'simultaneo';
}

I would like some tip that returns Boolean and tell me that the $reference variable is equal to the string 'unico' or the 'simultaneous' string.

    
asked by anonymous 25.06.2018 / 15:36

1 answer

3

You're apparently considering writing the variable twice is inserting redundancy into the code. On the one hand it is, but it leaves the code simpler. If you still want to change, just use the native in_array function:

public function hasPlan() : bool
{
    return in_array($this->reference, ['unico', 'simultaneo']);
}
    
25.06.2018 / 15:58