|function\s)' . $quotedMethod . '\s*\(/iS', $content ); } // without opening parentheses to match static callbacks notation if (self::_isRegexpMatched( '/' . preg_quote($class, '/') . '::\s*' . $quotedMethod . '[^a-z\d_]/iS', $content ) ) { return true; } if (self::isClassOrInterface($content, $class) || self::isDirectDescendant($content, $class)) { return self::_isRegexpMatched('/this->' . $quotedMethod . '\s*\(/iS', $content) || self::_isRegexpMatched( '/(self|static|parent)::\s*' . $quotedMethod . '\s*\(/iS', $content ); } } /** * Check if methods or functions are used in the content * * If class context is specified, only the class and its descendants will be checked. * * @param string $property * @param string $content * @param string $class * @return bool */ public static function isPropertyUsed($property, $content, $class = null) { if ($class) { if (!self::isClassOrInterface($content, $class) && !self::isDirectDescendant($content, $class)) { return false; } } return self::_isRegexpMatched( '/[^a-z\d_]' . preg_quote($property, '/') . '[^a-z\d_]/iS', $content ); } /** * Analyze content to determine whether it is a declaration of the specified class/interface * * @param string $content * @param string $name * @return bool */ public static function isClassOrInterface($content, $name) { return self::_isRegexpMatched('/\b(?:class|interface)\s+' . preg_quote($name, '/') . '\b[^{]*\{/iS', $content); } /** * Analyze content to determine whether this is a direct descendant of the specified class/interface * * @param string $content * @param string $name * @return bool */ public static function isDirectDescendant($content, $name) { $name = preg_quote($name, '/'); return self::_isRegexpMatched( '/\s+extends\s+' . $name . '\b|\s+implements\s+[^{]*\b' . $name . '\b[^{^\\\\]*\{/iS', $content ); } /** * Check if content matches the regexp * * @param string $regexp * @param string $content * @throws \Exception * @return bool True if the content matches the regexp */ protected static function _isRegexpMatched($regexp, $content) { $result = preg_match($regexp, $content); if ($result === false) { throw new \Exception('An error occurred when matching regexp "' . $regexp . '""'); } return 1 === $result; } }