如果条件和PHP中的切换案例短路

时间:2015-09-07 20:55:39

标签: php if-statement switch-statement

我正在写一个结合脚本。

如果我想改变动词的word_stem,我需要找到不规则动词的情绪,时态和人物的所有组合。

条件示例

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))))

怎样才能缩短这个条件?我必须添加很多其他if条件。

我还将为此示例缩短另一个函数中异常动词的更改结尾的开关大小写:

示例切换案例

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'
    );

如何缩短此开关盒?我必须添加许多其他类似的开关案例。

0 个答案:

没有答案