lundi 7 septembre 2015

Shorting if condition and switch case in PHP

I am writing a conjugation script. I need to find all combination of mood, tense and person for unregular verbs, which had to changed the word_stem.

Example if condition

if ($exceptionmodel->getValue () === ExceptionModel::MOUVOIR && (($mood->getValue () === Mood::Indicatif && $tense->getValue () === Tense::Present && in_array ( $person->getValue (), array (
        Person::FirstPersonSingular,
        Person::SecondPersonSingular,
        Person::ThirdPersonSingular,
        Person::ThirdPersonPlural 
) ) || $tense->getValue () === Tense::Passe) || ($mood->getValue () === Mood::Subjonctif && $tense->getValue () === Tense::Present && in_array ( $person->getValue (), array (
        Person::FirstPersonSingular,
        Person::SecondPersonSingular,
        Person::ThirdPersonSingular,
        Person::ThirdPersonPlural 
) ) || $tense->getValue () === Tense::Imparfait) || (($mood->getValue () === Mood::Imperatif && $tense->getValue () === Tense::Present && $person->getValue () === Person::FirstPersonSingular))))

How is it possible to short this condition?

I will also shorting the switch case for this example for the changed endings of the exception verb in another function:

Example switch case

case ExceptionModel::MOUVOIR :
    $ending [EndingWith::IR] [Mood::Indicatif] [Tense::Present] [Person::FirstPersonSingular] = 'eus';
    $ending [EndingWith::IR] [Mood::Indicatif] [Tense::Present] [Person::SecondPersonSingular] = 'eus';
    $ending [EndingWith::IR] [Mood::Indicatif] [Tense::Present] [Person::ThirdPersonSingular] = 'eut';
    $ending [EndingWith::IR] [Mood::Indicatif] [Tense::Present] [Person::ThirdPersonPlural] = 'euvent';

    $ending [EndingWith::IR] [Mood::Imperatif] [Tense::Present] [Person::FirstPersonSingular] = 'eus';

    $ending [EndingWith::IR] [Mood::Indicatif] [Tense::Passe] = array (
            Person::FirstPersonSingular => 'us',
            Person::SecondPersonSingular => 'us',
            Person::ThirdPersonSingular => 'ut',
            Person::FirstPersonPlural => 'ûmes',
            Person::SecondPersonPlural => 'ûtes',
            Person::ThirdPersonPlural => 'urent' 
    );
    $ending [EndingWith::IR] [Mood::Subjonctif] [Tense::Present] [Person::FirstPersonSingular] = 'euve';
    $ending [EndingWith::IR] [Mood::Subjonctif] [Tense::Present] [Person::SecondPersonSingular] = 'euves';
    $ending [EndingWith::IR] [Mood::Subjonctif] [Tense::Present] [Person::ThirdPersonSingular] = 'euve';
    $ending [EndingWith::IR] [Mood::Subjonctif] [Tense::Present] [Person::ThirdPersonPlural] = 'euvent';
    $ending [EndingWith::IR] [Mood::Subjonctif] [Tense::Imparfait] = array (
            Person::FirstPersonSingular => 'usse',
            Person::SecondPersonSingular => 'usses',
            Person::ThirdPersonSingular => 'ût',
            Person::FirstPersonPlural => 'ussions',
            Person::SecondPersonPlural => 'ussiez',
            Person::ThirdPersonPlural => 'ussent'
    );

How is it possible to short this switch case?

Aucun commentaire:

Enregistrer un commentaire