11<?php
22
3- function before_filter_classReference ($ data , $ folder ) {
4- // Replace with php:method since there is no difference
3+ declare (strict_types=1 );
4+
5+ function before_filter_classReference (string $ data , string $ folder ): ?string {
6+ // Sphinx renders static methods and functions the same way as methods.
57 $ staticMethod = '.. php:staticmethod:: ' ;
68 if (str_contains ($ data , $ staticMethod )) {
79 $ data = str_replace ($ staticMethod , '.. php:method:: ' , $ data );
810 }
911
10- // Replace with php:method since there is no difference
1112 $ function1 = '.. php:function:: ' ;
1213 if (str_contains ($ data , $ function1 )) {
1314 $ data = str_replace ($ function1 , '.. php:method:: ' , $ data );
1415 }
1516
16- // Replace with php:method since there is no difference
1717 $ function2 = '.. php:function:: ' ;
1818 if (str_contains ($ data , $ function2 )) {
1919 $ data = str_replace ($ function2 , '.. php:method:: ' , $ data );
2020 }
2121
22- // Remove indentation for the whole block
2322 $ indent = ' .. php:method:: ' ;
2423 if (str_contains ($ data , $ indent )) {
2524 $ data = removeIndentLevel ($ data , $ indent );
@@ -47,32 +46,27 @@ function before_filter_classReference($data, $folder) {
4746 $ insideBlock = true ;
4847 }
4948
50- // Replace namespace
5149 if (str_starts_with ($ line , $ stringNamespace )) {
5250 $ line = str_replace ([$ stringNamespace , '\\' ], ['## ' , '\\\\' ], $ line );
5351 }
5452
55- // Replace class
5653 if (str_starts_with ($ line , $ stringClass )) {
5754 $ line = str_replace ($ stringClass , '### ' , $ line );
5855 }
5956
60- // Replace method
6157 if (str_starts_with ($ line , $ stringMethod )) {
6258 $ line = str_replace ($ stringMethod , '#### ' , $ line );
6359 }
6460
6561 if ($ insideBlock ) {
66- $ line = ltrim ( $ line );
62+ $ line = preg_replace ( ' /^ {1,4}/ ' , '' , $ line );
6763
68- // Replace param
6964 if (str_starts_with ($ line , $ stringParam )) {
7065 if (! $ paramsStarted ) {
7166 $ paramsStarted = true ;
7267 $ lines [$ no - 1 ] = $ lines [$ no - 1 ] . PHP_EOL . "* **Parameters** " ;
7368 }
7469 $ line = str_replace ($ stringParam , " * " , $ line );
75- // Replace order of the data type and variable name
7670 $ pattern = '/\*\s*(\w+(?:\|\w+)*)\s*\$(\w+):\s*(.+)$/ ' ;
7771 if (preg_match ($ pattern , $ line , $ matches ) === 1 ) {
7872 $ dataType = $ matches [1 ];
@@ -91,20 +85,17 @@ function before_filter_classReference($data, $folder) {
9185 $ paramsStarted = false ;
9286 }
9387
94- // Replace returns
9588 if (str_starts_with ($ line , $ stringReturn )) {
9689 $ line = str_replace ($ stringReturn , '* **Returns** ' , $ line );
9790 }
9891
99- // Replace return type
10092 if (str_starts_with ($ line , $ stringReturnType )) {
10193 $ pattern = "/ $ stringReturnType:(.*)$/m " ;
102- $ line = preg_replace_callback ($ pattern , function ($ matches ) {
94+ $ line = preg_replace_callback ($ pattern , function (array $ matches ): string {
10395 return '* **Return type**: `` ' . str_replace ('\\\\' , '\\' , trim ($ matches [1 ])) . '`` ' ;
10496 }, $ line );
10597 }
10698
107- // Replace throws
10899 if (str_starts_with ($ line , $ stringThrows )) {
109100 $ line = str_replace ($ stringThrows , '* **Throws** ' , $ line );
110101 }
@@ -124,12 +115,12 @@ function before_filter_classReference($data, $folder) {
124115 return implode (PHP_EOL , $ lines );
125116}
126117
127- function after_filter_classReference ($ data , $ folder ) {
118+ function after_filter_classReference (string $ data , string $ folder ): ?string {
119+ // Python-Markdown nests list items by four spaces, not two.
128120 return str_replace (['\# ' , ' - ' ], ['# ' , ' - ' ], $ data );
129121}
130122
131- // helper function
132- function removeIndentLevel ($ data , $ indent ) {
123+ function removeIndentLevel (string $ data , string $ indent ): string {
133124 $ lines = explode (PHP_EOL , $ data );
134125
135126 $ insideBlock = false ;
@@ -145,10 +136,12 @@ function removeIndentLevel($data, $indent) {
145136
146137 $ next = $ no + 1 ;
147138
148- if ($ insideBlock
139+ if (
140+ $ insideBlock
149141 && isset ($ lines [$ next ])
150142 && $ lines [$ next ] !== ''
151- && $ lines [$ next ] === ltrim ($ lines [$ next ])) {
143+ && $ lines [$ next ] === ltrim ($ lines [$ next ])
144+ ) {
152145 $ insideBlock = false ;
153146 }
154147 }
0 commit comments