Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psalm 5.14.0 and higher triggers issues with defined array-shapes #1346

Open
jaytaph opened this issue Aug 8, 2023 · 5 comments
Open

Psalm 5.14.0 and higher triggers issues with defined array-shapes #1346

jaytaph opened this issue Aug 8, 2023 · 5 comments

Comments

@jaytaph
Copy link

jaytaph commented Aug 8, 2023

Array shape declaration of certain methods are not compatible with psalm 5.14.0+.

InvalidArgument - src/Service/Elastic/IndexService.php:114:55 - Argument 1 of Elastic\Elasticsearch\Endpoints\Indices::exists expects array{allow_no_indices: bool, error_trace: bool, expand_wildcards: Elastic\Elasticsearch\Endpoints\enum, filter_path: list<mixed>, flat_settings: bool, human: bool, ignore_unavailable: bool, include_defaults: bool, index: list<mixed>, local: bool, pretty: bool, source: string}, but array{index: string} provided (see https://psalm.dev/004)
        $response = $this->elastic->indices()->exists(['index' => $indexName]);

This works correctly in psalm 5.13.1 or lower, but at 5.14.0 there has been some changes that will generate errors when not given all keys found in the definition.

	 * @param array{
	 *     index: list, // (REQUIRED) A comma-separated list of index names
	 *     local: boolean, // Return local information, do not retrieve the state from master node (default: false)
	 *     ignore_unavailable: boolean, // Ignore unavailable indexes (default: false)
	 *     allow_no_indices: boolean, // Ignore if a wildcard expression resolves to no concrete indices (default: false)
	 *     expand_wildcards: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open)
	 *     flat_settings: boolean, // Return settings in flat format (default: false)
	 *     include_defaults: boolean, // Whether to return all default setting for each of the indices.
	 *     pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false)
	 *     human: boolean, // Return human readable values for statistics. (DEFAULT: true)
	 *     error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false)
	 *     source: string, // The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
	 *     filter_path: list, // A comma-separated list of filters used to reduce the response.
	 * } $params

This will probably function properly by adding a ? after the keyname in the array-shape.

	 * @param array{
	 *     index: list, // (REQUIRED) A comma-separated list of index names
	 *     local?: boolean, // Return local information, do not retrieve the state from master node (default: false)
	 *     ignore_unavailable?: boolean, // Ignore unavailable indexes (default: false)
	 *     allow_no_indices?: boolean, // Ignore if a wildcard expression resolves to no concrete indices (default: false)
	 *     expand_wildcards?: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open)
	 *     flat_settings?: boolean, // Return settings in flat format (default: false)
	 *     include_defaults?: boolean, // Whether to return all default setting for each of the indices.
	 *     pretty?: boolean, // Pretty format the returned JSON response. (DEFAULT: false)
	 *     human?: boolean, // Return human readable values for statistics. (DEFAULT: true)
	 *     error_trace?: boolean, // Include the stack trace of returned errors. (DEFAULT: false)
	 *     source?: string, // The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
	 *     filter_path?: list, // A comma-separated list of filters used to reduce the response.
	 * } $params

See:

https://psalm.dev/r/fae4b76358 vs https://psalm.dev/r/9b72fe22b5

@ezimuel
Copy link
Contributor

ezimuel commented Aug 9, 2023

@jaytaph thanks for this PR, I'll have a look. Your proposal sounds good. I need to update the code generator, since these comments are generated using a separate tool.

@MidnightDesign
Copy link

@ezimuel Where can I find the codegen? I'd like to give it a shot.

@reinschaap
Copy link

@ezimuel what is the current status and planning for this issue?

@reinschaap
Copy link

@ezimuel again my question since you did not (yet) give us any answers.

what is the current status and planning for resolving this issue?

@pluk
Copy link

pluk commented Apr 29, 2024

Hi!

@ezimuel are there any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants