public appliesToContext ( Phpro\SoapClient\CodeGenerator\Context\ContextInterface $context ) : boolean | ||
$context | Phpro\SoapClient\CodeGenerator\Context\ContextInterface | |
Résultat | boolean |
/** * @param ContextInterface $context * * @return bool */ public function appliesToContext(ContextInterface $context) { if (!$context instanceof TypeContext && !$context instanceof PropertyContext) { return false; } $type = $context->getType(); if (!preg_match($this->regex, $type->getName())) { return false; } return $this->subRule->appliesToContext($context); }
/** * @param RuleInterface $rule * @param ContextInterface $context */ private function applyRule(RuleInterface $rule, ContextInterface $context) { if (!$rule->appliesToContext($context)) { return; } $rule->apply($context); }
function it_can_apply_to_multiple_other_rules(RuleInterface $rule1, RuleInterface $rule2, ContextInterface $context) { $rule1->appliesToContext($context)->willReturn(false); $rule1->apply($context)->shouldNotBeCalled(); $rule2->appliesToContext($context)->willReturn(true); $rule2->apply($context)->shouldBeCalled(); $this->apply($context); }
/** * @param ContextInterface $context * * @return bool */ public function appliesToContext(ContextInterface $context) { if (!$context instanceof TypeContext && !$context instanceof PropertyContext) { return false; } $type = $context->getType(); $typeExists = array_key_exists($type->getName(), $this->typeMap); // The default rule will be used here: if (!$typeExists) { return $this->defaultRule->appliesToContext($context); } // It's possible to define a null rule, which means that no code will be generated. $rule = $this->typeMap[$type->getName()]; if ($rule === null) { return false; } return $rule->appliesToContext($context); }
function it_can_apply_if_subrule_does_not_apply(RuleInterface $subRule, TypeContext $context) { $context->getType()->willReturn(new Type('MyNamespace', 'TypeName', [])); $subRule->appliesToContext($context)->willReturn(false); $this->appliesToContext($context)->shouldReturn(false); }
function it_can_skip_rules(RuleInterface $rule, ContextInterface $context) { $rule->appliesToContext($context)->willReturn(false); $rule->apply($context)->shouldNotBeCalled(); $this->applyRules($context); }
function it_can_apply_if_subrule_does_not_apply(RuleInterface $subRule, PropertyContext $context) { $context->getProperty()->willReturn(new Property('MyProperty', 'string')); $subRule->appliesToContext($context)->willReturn(false); $this->appliesToContext($context)->shouldReturn(false); }