Checks comparison condition from rules against node.

@param array $rule
@param AbstractNode $node
@return bool
976943
public function checkComparison(array $rule, AbstractNode $node): bool
    {
        if ($rule['key'] == 'plaintext') {
            // plaintext search
            $nodeValue = $node->text();
        } else {
            // normal search
            $nodeValue = $node->getAttribute($rule['key']);
        }

        $check = $this->match($rule['operator'], $rule['value'], $nodeValue);

        // handle multiple classes
        if ( ! $check && $rule['key'] == 'class') {
            $nodeClasses = explode(' ', $node->getAttribute('class'));
            foreach ($nodeClasses as $class) {
                if ( ! empty($class)) {
                    $check = $this->match($rule['operator'], $rule['value'], $class);
                }
                if ($check) {
                    break;
                }
            }
        }

        return $check;
    }
303344
public function matches(NodeData $node)
    {
        if ($node->hasProperty($this->propertyName)) {
            $propertyValue = $node->getProperty($this->propertyName);
            return !empty($propertyValue);
        }
        return false;
    }
475324
public function apply(AbstractNode $node): void
    {
        if (!$this->isPlugin($node)) {
            return;
        }

        $pluginMethods = $node->getMethods();

        foreach ($pluginMethods as $pluginMethod) {
            $this->applyRule($pluginMethod);
        }
    }
1150778
public function apply(AbstractNode $node)
    {
        if (preg_match('([A-Za-z0-9]+Constants$)', $node->getName()) === 0
            || preg_match("(\\\\Shared\\\\)", $node->getNamespaceName()) === 0) {
            return;
        }

        $moduleName = str_replace('Constants', '', $node->getName());

        foreach ($node->findChildrenOfType('ConstantDeclarator') as $constant) {
            /** @var \PDepend\Source\AST\ASTValue|\PHPMD\AbstractNode $constant */
            $value = $constant->getValue()->getValue();

            $expectedConstantValue = sprintf(
                '%s:%s',
                $this->getUnderscoredConstantName($moduleName),
                $constant->getImage()
            );

            if ($value === $expectedConstantValue) {
                continue;
            }

            $message = sprintf(
                'The constant value is expected to be "%s" but is "%s". This violates the rule "%s"',
                $expectedConstantValue,
                is_array($value) ? print_r($value, true) : $value,
                static::RULE
            );

            $this->addViolation($node, [$message]);
        }
    }
1000552
protected function hasRule($attribute, $rules)
	{
		$rules = (array) $rules;

		// To determine if the attribute has a rule in the ruleset, we will spin
		// through each of the rules assigned to the attribute and parse them
		// all, then check to see if the parsed rules exists in the arrays.
		foreach ($this->rules[$attribute] as $rule)
		{
			list($rule, $parameters) = $this->parseRule($rule);

			if (in_array($rule, $rules)) return true;
		}

		return false;
	}
562311
public static function checkCompareValue($rule, $value)
    {
        if(isset($rule[0]) && '!' === $rule[0])
        {
            // 不等
            return $value !== $rule;
        }
        else
        {
            // 相等
            return $value === $rule;
        }
    }
219461
public function apply(AbstractNode $node)
    {
        /** @var \PDepend\Source\AST\ASTClass $node */
        if ($node->isAbstract()) {
            return;
        }

        if (empty($this->classRegex) || preg_match($this->classRegex, $node->getFullQualifiedName()) === 0) {
            return;
        }

        /** @var \PHPMD\Node\ClassNode $node */
        $this->applyImplementsInterfaceWithSameNameAndSuffix($node);
    }
1088039
private static function checkAllow($rule)
	{
		foreach($rule as $item)
		{
			$mca = explode('/',$item);
			if(!isset($mca[2]))
			{
				throw new Exception('allow 规则' . $item . '格式错误！');
			}
			if($mca[0] !== self::$module && $mca[0] !== '*')
			{
				continue;
			}
			if($mca[1] !== self::$control && $mca[1] !== '*')
			{
				continue;
			}
			if($mca[2] === self::$action || $mca[2] === '*')
			{
				return true;
			}
		}
		return false;
	}
171733
private function validateRule($rule): bool
    {
        if ($rule instanceof \Closure || $rule instanceof RuleInterface) {
            return true;
        }

        if (is_array($rule)) {
            return is_callable($rule, true);
        }

        if (is_string($rule) && class_exists($rule)) {
            try {
                $reflection = new \ReflectionClass($rule);
            } catch (\ReflectionException $e) {
                return false;
            }

            return $reflection->isSubclassOf(RuleInterface::class);
        }

        return false;
    }
1060612
public function parseNodeChildren(\DOMNode $node, NodeInterface $target)
    {
        $rules = $this->getStandard()->getRules();
        foreach ($node->childNodes as $childNode) {
            /** @var RuleInterface $rule */
            foreach ($rules as $rule) {
                if ($rule->canHandle($childNode, $target)) {
                    $rule->handle($this, $childNode, $target);
                    break;
                }
            }
        }
    }
914308
function check($rule = null, &$error = null)
    {
        $this->get($rule, $error);
        return !isset($error);
    }
510534
private function isClassFullyQualifiedName(Node $node): bool
    {
        $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
        if ($parentNode === null) {
            return false;
        }

        if (! $parentNode instanceof New_) {
            return false;
        }

        /** @var FullyQualified $fullyQualifiedNode */
        $fullyQualifiedNode = $parentNode->class;

        $newClassName = $fullyQualifiedNode->toString();

        return array_key_exists($newClassName, $this->oldToNewNamespaces);
    }
671036
public function match(RuleInterface $rule, NodeInterface $node): bool
    {
        if (false !== strpos($node->getSubject(), $rule->getSubject())) {
            return true;
        }

        return false;
    }
277043
private function checkBasicRule($rule, $path)
    {
        $rule = $this->prepareRegexRule($this->encode_url($rule));
        // change @ to \@
        $escaped = strtr($rule, array('@' => '\@'));
        // match result
        if (preg_match('@' . $escaped . '@', $path)) {
	        $this->log[] = 'Rule match: Path';
	        return true;
        }
        return false;
    }
349753
protected function isServiceProvider(AbstractNode $node): bool
    {
        if (!($this instanceof ClassAware)) {
            return false;
        }

        $interfaceReferences = $this->getInterfaceReferences($node);

        if (!$interfaceReferences) {
            return false;
        }

        foreach ($interfaceReferences as $interfaceReference) {
            if ($interfaceReference->getType()->getName() === 'ServiceProviderInterface' || $interfaceReference->getType()->getName() === 'ControllerProviderInterface') {
                return true;
            }
        }

        return false;
    }
347565
protected function _check(array $node) {
		$attrib=$node['@attrib'];
		unset($node['@attrib']);
		// Grab <true> and <false> blocks
		foreach ($node as $pos=>$block)
			if (isset($block['true']))
				$true=[$pos,$block];
			elseif (isset($block['false']))
				$false=[$pos,$block];
		if (isset($true,$false) && $true[0]>$false[0])
			// Reverse <true> and <false> blocks
			list($node[$true[0]],$node[$false[0]])=[$false[1],$true[1]];
		return
			'<?php if ('.$this->token($attrib['if']).'): ?>'.
				$this->build($node).
			'<?php endif; ?>';
	}
366384
protected function evaluate($rule, array $context = [])
    {
        try {
            $ruleValue = $this->getValueFromRule($rule);
        } catch (\Exception $e) {
            $this->setError('Error attempting to get a value from a rule.');

            return false;
        }

        try {
            $contextValue = $this->getValueFromContext($rule, $context);
        } catch (\Exception $e) {
            $this->setError('Error attempting to get a value from context.');

            return false;
        }

        $result = $this->evaluateRuleAgainstContext($rule, $contextValue, $ruleValue);
        if (!$result) {
            $this->setError(
                $rule->field.' did not '.$rule->operator.' '.$ruleValue.' (actual value was '.$contextValue.')'
            );
        }

        return $result;
    }