@@ -79,17 +79,53 @@ private function parseApiReference($restApiReference): void
7979 $ refRoutes = [];
8080
8181 $ restApiRefDoc = new \DOMDocument ();
82+ $ restApiRefDoc ->preserveWhiteSpace = false ;
8283 $ restApiRefDoc ->loadHTMLFile ($ restApiReference , LIBXML_NOERROR );
8384 $ restApiRefXpath = new \DOMXpath ($ restApiRefDoc );
8485
8586 /** @var \DOMElement $urlElement */
8687 foreach ($ restApiRefXpath ->query ('//*[@data-field="url"] ' ) as $ urlElement ) {
87- if (!array_key_exists ($ urlElement ->nodeValue , $ refRoutes )) {
88- $ refRoutes [$ urlElement ->nodeValue ] = [
88+ $ route = $ urlElement ->nodeValue ;
89+ if (!array_key_exists ($ route , $ refRoutes )) {
90+ $ refRoutes [$ route ] = [
8991 'methods ' => [],
9092 ];
9193 }
92- $ refRoutes [$ urlElement ->nodeValue ]['methods ' ][$ urlElement ->previousSibling ->previousSibling ->nodeValue ] = true ;
94+ $ method = $ urlElement ->previousSibling ->previousSibling ->nodeValue ;
95+ $ displayName = trim (str_replace ('¶ ' , '' , $ urlElement ->parentNode ->parentNode ->previousSibling ->previousSibling ->nodeValue ));
96+ $ removed = '(removed) ' === substr ($ displayName , -strlen ('(removed) ' ));
97+ $ deprecated = '(deprecated) ' === substr ($ displayName , -strlen ('(deprecated) ' ));
98+ $ substitute = null ;
99+ if ($ removed || $ deprecated ) {
100+ $ matches = [];
101+ if (preg_match ('/use (?<method>[A-Z]+) (?<route>[{}\/a-zA-Z]+) instead./ ' , $ urlElement ->parentNode ->nextSibling ->nextSibling ->nodeValue , $ matches )) {
102+ $ substitute = array_intersect_key ($ matches , array_flip (array ('method ' , 'route ' )));
103+ if (!array_key_exists ($ substitute ['route ' ], $ refRoutes )) {
104+ $ refRoutes [$ substitute ['route ' ]] = [
105+ 'methods ' => [],
106+ ];
107+ }
108+ if (!array_key_exists ($ substitute ['method ' ], $ refRoutes [$ substitute ['route ' ]]['methods ' ])) {
109+ $ refRoutes [$ substitute ['route ' ]]['methods ' ][$ substitute ['method ' ]] = [
110+ 'replace ' => [],
111+ ];
112+ }
113+ $ refRoutes [$ substitute ['route ' ]]['methods ' ][$ substitute ['method ' ]]['replace ' ][] = [
114+ 'method ' => $ method ,
115+ 'route ' => $ route ,
116+ ];
117+ }
118+ }
119+ $ replace = [];
120+ if (array_key_exists ($ method , $ refRoutes [$ route ]['methods ' ])) {
121+ $ replace = $ refRoutes [$ route ]['methods ' ][$ method ]['replace ' ];
122+ }
123+ $ refRoutes [$ route ]['methods ' ][$ method ] = [
124+ 'removed ' => $ removed ,
125+ 'deprecated ' => $ deprecated ,
126+ 'substitute ' => $ substitute ,
127+ 'replace ' => $ replace ,
128+ ];
93129 }
94130
95131 $ this ->refRoutes = $ refRoutes ;
@@ -268,6 +304,23 @@ public function run(int $testedRoutes = self::TEST_ALL_ROUTES)
268304 $ this ->output ("\t$ refRouteWithoutConf is a bit similar to $ confRoute " );
269305 $ this ->compareMethods ($ refRouteWithoutConf , $ confRoute , self ::TEST_REFERENCE_ROUTES );
270306 }
307+ continue ;
308+ }
309+ }
310+ foreach ($ refRoutes [$ refRouteWithoutConf ]['methods ' ] as $ method =>$ methodStatus ) {
311+ if ($ methodStatus ['removed ' ]) {
312+ $ this ->output ("\t$ method $ refRouteWithoutConf is flagged as removed " );
313+ } else if ($ methodStatus ['deprecated ' ]) {
314+ $ this ->output ("\t$ method $ refRouteWithoutConf is flagged as deprecated and can now be flagged as removed " );
315+ } else {
316+ $ this ->output ("\t$ method $ refRouteWithoutConf is not flagged. " );
317+ }
318+ if ($ methodStatus ['removed ' ] || $ methodStatus ['deprecated ' ]) {
319+ if ($ methodStatus ['substitute ' ]) {
320+ $ this ->output ("\tand the substitute {$ methodStatus ['substitute ' ]['method ' ]} {$ methodStatus ['substitute ' ]['route ' ]} is proposed. " );
321+ } else {
322+ $ this ->output ("\twithout substitute proposal. " );
323+ }
271324 }
272325 }
273326 }
0 commit comments