Skip to content

Commit

Permalink
deprecate "attr" in favor of "property"
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 3, 2023
1 parent d9a8ba5 commit f395c49
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 65 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ PHP Domain supports following objects:

.. note::

This domain expresses methods and attribute names like this::
This domain expresses methods and properties like this::

Class::method_name
Class::$attribute_name
Class::$prop_name

You address classes/functions in namespaces using \\ syntax as you would in PHP::

Expand Down
14 changes: 7 additions & 7 deletions doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Each directive populates the index, and or the namespace index.

.. rst:directive:: .. php:class:: name
Describes a class. Methods, attributes, and constants belonging to the class
Describes a class. Methods, properties, and constants belonging to the class
should be inside this directive's body::

.. php:class:: MyClass
Expand All @@ -115,7 +115,7 @@ Each directive populates the index, and or the namespace index.
Method description


Attributes, methods and constants don't need to be nested. They can also just
Properties, methods and constants don't need to be nested. They can also just
follow the class declaration::

.. php:class:: MyClass
Expand All @@ -128,7 +128,7 @@ Each directive populates the index, and or the namespace index.

.. seealso:: :rst:dir:`php:method`
:rst:dir:`php:attr`
:rst:dir:`php:property`
:rst:dir:`php:const`

.. rst:directive:: .. php:method:: name(signature)
Expand All @@ -145,9 +145,9 @@ Each directive populates the index, and or the namespace index.
This is an instance method.

.. rst:directive:: .. php:attr:: name
.. rst:directive:: .. php:property:: name
Describe an property/attribute on a class.
Describe a property on a class.

Cross Referencing
=================
Expand Down Expand Up @@ -192,11 +192,11 @@ matching directive is found:
:php:method:`DateTime::setDate`

.. rst:role:: php:attr
.. rst:role:: php:property
Reference a property on an object::
:php:attr:`ClassName::$propertyName`
:php:property:`ClassName::$propertyName`

.. rst:role:: php:interface
Expand Down
20 changes: 15 additions & 5 deletions sphinxcontrib/phpdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def throw_if_false(fromdocnode, value, message: str):
"exception": None,
"method": "::",
"const": "::",
"property": "::$",
"attr": "::$",
"staticmethod": "::",
"case": "::",
Expand Down Expand Up @@ -365,7 +366,8 @@ def _toc_entry_name(self, sig_node: addnodes.desc_signature) -> str:
return name + parens
if config.toc_object_entries_show_parents == "all":
if (
objtype in {"method", "const", "attr", "staticmethod", "case"}
objtype
in {"method", "const", "property", "attr", "staticmethod", "case"}
and len(parents) > 0
):
name = parents.pop() + "::" + name
Expand All @@ -379,7 +381,11 @@ def get_index_text(self, namespace, name):
raise NotImplementedError("must be implemented in subclasses")

def _is_class_member(self):
return self.objtype.startswith("method") or self.objtype.startswith("attr")
return (
self.objtype.startswith("method")
or self.objtype.startswith("property")
or self.objtype.startswith("attr")
)

def add_target_and_index(self, name_cls, sig, signode):
if self.objtype == "global":
Expand Down Expand Up @@ -511,7 +517,7 @@ class PhpClassmember(PhpObject):
"""

def get_signature_prefix(self, sig):
if self.objtype == "attr":
if self.objtype == "property" or self.objtype == "attr":
return _("property ")
if self.objtype == "staticmethod":
return _("static ")
Expand All @@ -527,6 +533,7 @@ def get_index_text(self, namespace, name_cls):

if (
self.objtype.endswith("method")
or self.objtype == "property"
or self.objtype == "attr"
or self.objtype == "case"
):
Expand All @@ -543,7 +550,7 @@ def get_index_text(self, namespace, name_cls):
return _("%s() (%s\\%s method)") % (propname, namespace, clsname)
else:
return _("%s() (%s method)") % (propname, clsname)
elif self.objtype == "attr":
elif self.objtype == "property" or self.objtype == "attr":
if namespace and clsname is None:
return _("%s (in namespace %s)") % (name, namespace)
elif namespace and self.env.config.add_module_names:
Expand Down Expand Up @@ -749,6 +756,7 @@ class PhpDomain(Domain):
"const": ObjType(_("const"), "const", "obj"),
"method": ObjType(_("method"), "method", "obj"),
"class": ObjType(_("class"), "class", "obj"),
"property": ObjType(_("attribute"), "property", "obj"),
"attr": ObjType(_("attribute"), "attr", "obj"),
"exception": ObjType(_("exception"), "exc", "obj"),
"namespace": ObjType(_("namespace"), "namespace", "obj"),
Expand All @@ -765,7 +773,8 @@ class PhpDomain(Domain):
"class": PhpClasslike,
"method": PhpClassmember,
"staticmethod": PhpClassmember, # deprecated, use "method" with "static" modifier, methods in PHP are exclusively static or non-static
"attr": PhpClassmember,
"property": PhpClassmember,
"attr": PhpClassmember, # deprecated, use "property"
"case": PhpClassmember,
"exception": PhpClasslike, # deprecated, use "class", exceptions in PHP are regular classes
"interface": PhpClasslike,
Expand All @@ -784,6 +793,7 @@ class PhpDomain(Domain):
"exc": PhpXRefRole(),
"method": PhpXRefRole(fix_parens=False),
"meth": PhpXRefRole(fix_parens=False), # deprecated, use "method"
"property": PhpXRefRole(),
"attr": PhpXRefRole(),
"const": PhpXRefRole(),
"namespace": PhpXRefRole(),
Expand Down
68 changes: 34 additions & 34 deletions test/rst_doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ <h2>Classes<a class="headerlink" href="#classes" title="Permalink to this headin
<p>Y-m-dTH:i:sP</p>
</dd>
</dl>
<dl class="php attr">
<dt class="sig sig-object php" id="DateTime::$testattr">
<dl class="php property">
<dt class="sig sig-object php" id="DateTime::$testprop">
<em class="property">
<span class="pre">property</span>
</em>
<span class="sig-name descname">
<span class="pre">testattr</span>
<span class="pre">testprop</span>
</span>
<a class="headerlink" href="#DateTime::$testattr" title="Permalink to this definition">&#xB6;</a>
<a class="headerlink" href="#DateTime::$testprop" title="Permalink to this definition">&#xB6;</a>
</dt>
<dd>
<p>Value of some attribute</p>
<p>Value of some property</p>
</dd>
</dl>
</dd>
Expand All @@ -210,21 +210,21 @@ <h2>Classes<a class="headerlink" href="#classes" title="Permalink to this headin
<p>Update something.</p>
</dd>
</dl>
<dl class="php attr">
<dt class="sig sig-object php" id="OtherClass::$nonIndentedAttribute">
<dl class="php property">
<dt class="sig sig-object php" id="OtherClass::$nonIndentedProperty">
<em class="property">
<span class="pre">property</span>
</em>
<span class="sig-prename descclassname">
<span class="pre">OtherClass::$</span>
</span>
<span class="sig-name descname">
<span class="pre">nonIndentedAttribute</span>
<span class="pre">nonIndentedProperty</span>
</span>
<a class="headerlink" href="#OtherClass::$nonIndentedAttribute" title="Permalink to this definition">&#xB6;</a>
<a class="headerlink" href="#OtherClass::$nonIndentedProperty" title="Permalink to this definition">&#xB6;</a>
</dt>
<dd>
<p>This attribute wasn&#x2019;t indented</p>
<p>This property wasn&#x2019;t indented</p>
</dd>
</dl>
<dl class="php const">
Expand Down Expand Up @@ -338,18 +338,18 @@ <h2>Interfaces<a class="headerlink" href="#interfaces" title="Permalink to this
<p>Y-m-dTH:i:sP</p>
</dd>
</dl>
<dl class="php attr">
<dt class="sig sig-object php" id="DateTimeInterface::$testattr">
<dl class="php property">
<dt class="sig sig-object php" id="DateTimeInterface::$testprop">
<em class="property">
<span class="pre">property</span>
</em>
<span class="sig-name descname">
<span class="pre">testattr</span>
<span class="pre">testprop</span>
</span>
<a class="headerlink" href="#DateTimeInterface::$testattr" title="Permalink to this definition">&#xB6;</a>
<a class="headerlink" href="#DateTimeInterface::$testprop" title="Permalink to this definition">&#xB6;</a>
</dt>
<dd>
<p>Value of some attribute</p>
<p>Value of some property</p>
</dd>
</dl>
</dd>
Expand Down Expand Up @@ -484,9 +484,9 @@ <h3>Test Case - Global symbols with no namespaces<a class="headerlink" href="#te
</a>
</p>
<p>
<a class="reference internal" href="#DateTime::$testattr" title="DateTime::$testattr">
<code class="xref php php-attr docutils literal notranslate">
<span class="pre">DateTime::$testattr</span>
<a class="reference internal" href="#DateTime::$testprop" title="DateTime::$testprop">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">DateTime::$testprop</span>
</code>
</a>
</p>
Expand All @@ -498,9 +498,9 @@ <h3>Test Case - Global symbols with no namespaces<a class="headerlink" href="#te
</a>
</p>
<p>
<a class="reference internal" href="#OtherClass::$nonIndentedAttribute" title="OtherClass::$nonIndentedAttribute">
<code class="xref php php-attr docutils literal notranslate">
<span class="pre">OtherClass::$nonIndentedAttribute</span>
<a class="reference internal" href="#OtherClass::$nonIndentedProperty" title="OtherClass::$nonIndentedProperty">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">OtherClass::$nonIndentedProperty</span>
</code>
</a>
</p>
Expand Down Expand Up @@ -547,9 +547,9 @@ <h3>Test Case - Global symbols with no namespaces<a class="headerlink" href="#te
</a>
</p>
<p>
<a class="reference internal" href="#DateTimeInterface::$testattr" title="DateTimeInterface::$testattr">
<code class="xref php php-attr docutils literal notranslate">
<span class="pre">DateTimeInterface::$testattr</span>
<a class="reference internal" href="#DateTimeInterface::$testprop" title="DateTimeInterface::$testprop">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">DateTimeInterface::$testprop</span>
</code>
</a>
</p>
Expand Down Expand Up @@ -586,9 +586,9 @@ <h3>Test Case - Prefix less links<a class="headerlink" href="#test-case-prefix-l
</a>
</p>
<p>
<a class="reference internal" href="#DateTime::$testattr" title="DateTime::$testattr">
<code class="xref php php-attr docutils literal notranslate">
<span class="pre">$testattr</span>
<a class="reference internal" href="#DateTime::$testprop" title="DateTime::$testprop">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">$testprop</span>
</code>
</a>
</p>
Expand Down Expand Up @@ -678,7 +678,7 @@ <h2>Namespaced elements<a class="headerlink" href="#namespace-LibraryName" title
<p>Test constant</p>
</dd>
</dl>
<dl class="php attr">
<dl class="php property">
<dt class="sig sig-object php" id="LibraryName\LibraryClass::$property">
<em class="property">
<span class="pre">property</span>
Expand Down Expand Up @@ -717,7 +717,7 @@ <h2>Namespaced elements<a class="headerlink" href="#namespace-LibraryName" title
<p>A normal instance method.</p>
</dd>
</dl>
<dl class="php attr">
<dl class="php property">
<dt class="sig sig-object php" id="LibraryName\NamespaceClass::$property">
<em class="property">
<span class="pre">property</span>
Expand Down Expand Up @@ -944,7 +944,7 @@ <h3>Test Case - not including namespace<a class="headerlink" href="#test-case-no
</p>
<p>
<a class="reference internal" href="#LibraryName\LibraryClass::$property" title="LibraryName\LibraryClass::$property">
<code class="xref php php-attr docutils literal notranslate">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">LibraryClass::$property</span>
</code>
</a>
Expand Down Expand Up @@ -979,7 +979,7 @@ <h3>Test Case - not including namespace<a class="headerlink" href="#test-case-no
</p>
<p>
<a class="reference internal" href="#LibraryName\NamespaceClass::$property" title="LibraryName\NamespaceClass::$property">
<code class="xref php php-attr docutils literal notranslate">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">NamespaceClass::$property</span>
</code>
</a>
Expand Down Expand Up @@ -1110,7 +1110,7 @@ <h3>Test Case - Links with prefix trimming<a class="headerlink" href="#test-case
</p>
<p>
<a class="reference internal" href="#LibraryName\LibraryClass::$property" title="LibraryName\LibraryClass::$property">
<code class="xref php php-attr docutils literal notranslate">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">$property</span>
</code>
</a>
Expand Down Expand Up @@ -1155,12 +1155,12 @@ <h3>Test Case - global access<a class="headerlink" href="#test-case-global-acces
</p>
<p>
<a class="reference internal" href="#LibraryName\LibraryClass::$property" title="LibraryName\LibraryClass::$property">
<code class="xref php php-attr docutils literal notranslate">
<code class="xref php php-property docutils literal notranslate">
<span class="pre">LibraryName\LibraryClass::$property</span>
</code>
</a>
</p>
<p><a class="reference internal" href="#LibraryName\LibraryClass::$property" title="LibraryName\LibraryClass::$property"><code class="xref php php-attr docutils literal notranslate"><span class="pre">$property</span></code></a> Should not be prefixed with classname.</p>
<p><a class="reference internal" href="#LibraryName\LibraryClass::$property" title="LibraryName\LibraryClass::$property"><code class="xref php php-property docutils literal notranslate"><span class="pre">$property</span></code></a> Should not be prefixed with classname.</p>
<p>
<a class="reference internal" href="#LibraryName\LibraryClass::TEST_CONST" title="LibraryName\LibraryClass::TEST_CONST">
<code class="xref php php-const docutils literal notranslate">
Expand Down
Loading

0 comments on commit f395c49

Please sign in to comment.