Commits

Takeshi Komiya committed 935905e

Add testcases for undocumented/private classes

Comments (0)

Files changed (13)

src/sphinxcontrib_phpautodoc.py

         self.add_line(u'.. %s:%s:: %s' % (domain, directive, name), indent_level)
         self.add_line('')
 
-    def add_directive(self, directive, name, comment_node, indent_level=0):
+    def add_directive(self, directive, name, comment_node, indent_level=0, force=False):
         if is_private_comment(comment_node):
-            pass  # skipped
-        elif is_comment(comment_node) or 'undoc-members' in self.options:
+            if force is True:
+                self.add_directive_header(directive, name, indent_level)
+        elif is_comment(comment_node) or 'undoc-members' in self.options or force is True:
             self.add_directive_header(directive, name, indent_level)
 
             if is_comment(comment_node):
     def traverse(self, tree, indent=0):
         last_node = None
         for node in tree:
-            if (isinstance(node, ast.Class) or isinstance(node, ast.Interface)) and node.name in self.targets:
-                self.traverse_all([last_node, node])
+            if isinstance(node, ast.Class) and node.name in self.targets:
+                self.add_directive('class', node.name, last_node, indent, force=True)
+
+                if 'members' in self.options:
+                    self.traverse_all(node.nodes, indent + 1)
+            elif isinstance(node, ast.Interface) and node.name in self.targets:
+                self.add_directive('interface', node.name, last_node, indent, force=True)
+
+                if 'members' in self.options:
+                    self.traverse_all(node.nodes, indent + 1)
 
             last_node = node
 

tests/inputs/phpautoclass/private_class_basic.rst

+.. phpautoclass:: Hello
+   :filename: inputs/private_class.php
+   :members:

tests/inputs/phpautoclass/private_interface_basic.rst

+.. phpautoclass:: IHello
+   :filename: inputs/private_interface.php
+   :members:

tests/inputs/phpautoclass/undoc_class_basic.rst

+.. phpautoclass:: Hello
+   :filename: inputs/undoc_class.php
+   :members:

tests/inputs/phpautoclass/undoc_interface_basic.rst

+.. phpautoclass:: IHello
+   :filename: inputs/undoc_interface.php
+   :members:

tests/inputs/private_class.php

+<?php
+
+/**
+ * @access private
+ */
+class Hello {
+  /**
+   * here is docs for world method
+   */
+  public function world($name = CONSTANT) {
+  }
+}
+?>

tests/inputs/private_interface.php

+<?php
+
+/**
+ * @access private
+ */
+interface IHello {
+  /**
+   * here is docs for world method
+   */
+  public function world($name = array());
+}
+?>

tests/inputs/undoc_class.php

+<?php
+
+class Hello {
+  /**
+   * here is docs for world method
+   */
+  public function world($name = CONSTANT) {
+  }
+}
+?>

tests/inputs/undoc_interface.php

+<?php
+
+interface IHello {
+  /**
+   * here is docs for world method
+   */
+  public function world($name = array());
+}
+?>

tests/outputs/phpautoclass/private_class_basic.rst

+.. php:class:: Hello
+
+   .. php:method:: world($name = CONSTANT)
+
+      here is docs for world method
+

tests/outputs/phpautoclass/private_interface_basic.rst

+.. php:interface:: IHello
+
+   .. php:method:: world($name = array())
+
+      here is docs for world method
+

tests/outputs/phpautoclass/undoc_class_basic.rst

+.. php:class:: Hello
+
+   .. php:method:: world($name = CONSTANT)
+
+      here is docs for world method
+

tests/outputs/phpautoclass/undoc_interface_basic.rst

+.. php:interface:: IHello
+
+   .. php:method:: world($name = array())
+
+      here is docs for world method
+