Ver Mensaje Individual
  #11 (permalink)  
Antiguo 10/08/2013, 01:14
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Transformar IFs anidados en SWITCH-CASE

Cita:
Iniciado por Italico76 Ver Mensaje

Código PHP:
    public function findSub(TagSequence $sub,$gaps=false,$deep=false)
    {
        if (!
is_bool($gaps))
            throw new 
InvalidArgumentException ("Gaps debe ser bool en ".__METHOD__); 

        if (!
is_bool($deep))
            throw new 
InvalidArgumentException ("Deep debe ser bool en ".__METHOD__);

        
tagSecuenceSearch::setHaystack($this);

        switch (
$gaps*10 $deep)
        {
            case (
11): return tagSecuenceSearch::findSubWithGapsWithDeep($sub);
            case (
10): return tagSecuenceSearch::findSubWithGapsNoDeep($sub);
            case (
1): return tagSecuenceSearch::findSubNoGapsWithDeep($sub);
            case (
0): return tagSecuenceSearch::findSubNoGapsNoDeep($sub);
        }
    } 
Reduciendo varios IF anidados... que incluso podrian ser 3 niveles (o dimensiones) si tuviera 3 condiciones distintas...

Que pensa sino fui claro..... pero POR FAVOR... NO ME AGREDAS.....GRACIAS
Italico76 te comente algo relacionado con esto en otro consulta que hiciste. pero igual te recomiendo la misma lectura: http://www.informit.com/articles/art...98607&seqNum=2
y si puede lee el libro: Pro PHP Refactoring o el de Refactoring to Patterns
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.