diff --git a/sphinxcontrib/phpdomain.py b/sphinxcontrib/phpdomain.py index 068f98b..a4482a1 100644 --- a/sphinxcontrib/phpdomain.py +++ b/sphinxcontrib/phpdomain.py @@ -53,12 +53,10 @@ def log_assert( php_sig_re = re.compile( r'''^ (public\ |protected\ |private\ )? # visibility (final\ |abstract\ |static\ )? # modifiers - ([\w\\]+\:\:)? # class name(s) - (\$?[\w\\]+) \s* # thing name - (?: - \((.*)\) # optional: arguments - (?:\s* -> \s* (.*))? # return annotation - )? + ([\w.]*\:\:)? # class name(s) + (\$?\w+) \s* # thing name + (?: \((.*)\) # optional: arguments + (?:\s* -> \s* (.*))?)? # return annotation (?:\s* : \s* (.*))? # backed enum type / case value $ # and nothing more ''', re.VERBOSE) @@ -200,13 +198,13 @@ def handle_signature(self, sig, signode): # determine module and class name (if applicable), as well as full name modname = self.options.get( 'namespace', self.env.temp_data.get('php:namespace')) + + classname = self.env.temp_data.get('php:class') separator = separators[self.objtype] - if '::' in name_prefix: + # Method declared as Class::methodName + if not classname and '::' in name_prefix: classname = name_prefix.rstrip('::') - else: - classname = self.env.temp_data.get('php:class') - if self.objtype == 'global' or self.objtype == 'function': add_module = False modname = None @@ -580,9 +578,6 @@ def process_link(self, env, refnode, has_explicit_title, title, target): if m: title = m.group(1) - if title.startswith(NS): - title = title[1:] - refnode['php:namespace'] = env.temp_data.get('php:namespace') refnode['php:class'] = env.temp_data.get('php:class') @@ -784,20 +779,14 @@ def find_obj(self, env, fromdocnode, modname, classname, name, type, searchorder if name[-2:] == '()': name = name[:-2] - objects = self.data['objects'] + if not name: + return None, None - if name.startswith(NS): - absname = name[1:] - else: - absname = (modname + NS if modname else "") \ - + (classname + NS if classname and '::' not in name else "") \ - + name + objects = self.data['objects'] newname = None if searchorder == 1: - if absname in objects: - newname = absname - elif modname and classname and \ + if modname and classname and \ modname + NS + classname + '::' + name in objects: newname = modname + NS + classname + '::' + name elif modname and modname + NS + name in objects: @@ -811,9 +800,7 @@ def find_obj(self, env, fromdocnode, modname, classname, name, type, searchorder elif name in objects: newname = name else: - if absname in objects: - newname = absname - elif name in objects: + if name in objects: newname = name elif classname and classname + '::' + name in objects: newname = classname + '::' + name