beaucollins / psalm-failure

Project for https://github.com/vimeo/psalm/issues/3018

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Psalm UndefinedMethod Failure

This project reproduces an error we're seeing in a project related to Psalm.

We are using WordPress which has a class WP_REST_Response. This class extends from WP_HTTP_Response.

In this project the class Collins\CustomResponse extends WP_REST_Response.

The assumption is that all non-private methods on WP_REST_Response and WP_HTTP_Response should be visiible/available on CustomResponse.

However, Psalm does not believe that to be the case:

		/**
		 * ::get_status() is defined by WP_HTTP_Response
		 *
		 * Psalm error is UndefinedMethod
		 */
		$status = $response->get_status();

This produces an UndefinedMethod error when running psalm.

UndefinedMethod
Method Collins\CustomResponse::get_status does not exist

For convenience the stubs used for these classes have been extracted and placed in ./sample-stubs.php:

Other Strangeness

Psalm in this project is not finding errors that it should be:

  • The @return of CustomResponse::custom_method is declared as @return string but returns an int of 1. No error.
  • The @param boolean $arg is declared on custom_method but it is being used without an $arg param and Psalm doesn't care.

About

Project for https://github.com/vimeo/psalm/issues/3018


Languages

Language:PHP 100.0%