Skip to content

Initial psalm integration and fixes - #108

Open
SergiuBota1 wants to merge 4 commits into
laminas:2.22.xfrom
SergiuBota1:psalm-integration
Open

Initial psalm integration and fixes#108
SergiuBota1 wants to merge 4 commits into
laminas:2.22.xfrom
SergiuBota1:psalm-integration

Conversation

@SergiuBota1

Copy link
Copy Markdown
Q A
Documentation no
Bugfix no
BC Break no
New Feature yes
RFC yes
QA no

Description

Here is the initial commit for psalm integrations.

I know that there are several unresolved errors, including PropertyNotSetInConstructor, considering that constructors are not used but setters, should the properties be initialized with null?

@gsteel

gsteel commented Apr 15, 2025

Copy link
Copy Markdown
Member

Thanks for starting this @SergiuBota1

I don't have time to review right now, but can I suggest you enable Roave BC Checker in CI like this:

https://github.com/laminas/laminas-filter/blob/2.41.x/.laminas-ci.json#L5

There are a few BC breaks here that I've noticed which will have to be reverted and BC checker will help identify those.

Also, yes, initialising nullable class properties with null is fine. Often these properties don't declare null in the doc blocks, but should if that property is not set in the constructor.

Signed-off-by: bota <Bota@dotkernel.com>
Signed-off-by: bota <Bota@dotkernel.com>
Signed-off-by: bota <Bota@dotkernel.com>
Signed-off-by: bota <Bota@dotkernel.com>
@arhimede arhimede linked an issue Apr 24, 2025 that may be closed by this pull request

@gsteel gsteel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SergiuBota1 - This is just a partial review, but there's a fair bit to go through already and I've run out of time 👍

Comment thread psalm.xml
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findUnusedPsalmSuppress is helpful too

Comment thread src/AbstractMessage.php
Comment on lines +28 to 29
/** @var null|string */
protected $version = self::VERSION_11;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never null as far as I can see. If inheritors make it null, that's their problem

Comment thread src/AbstractMessage.php

/** @var Headers|null */
/** @var Headers|null|string */
protected $headers;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $headers;
protected $headers = null;

Comment thread src/AbstractMessage.php
* Return the HTTP version for this request
*
* @return string
* @return string|null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this should never be null

Comment thread src/AbstractMessage.php
* Return the header container responsible for headers
*
* @return Headers
* @return Headers|bool|HeaderInterface|ArrayIterator|mixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

Comment thread src/Request.php
* @param string|null $name Header name to retrieve, or null to get the whole container.
* @param mixed|null $default Default value to use when the requested header is missing.
* @return Headers|bool|HeaderInterface|ArrayIterator
* @return Headers|bool|HeaderInterface|ArrayIterator|mixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
 * @template T
 * @param  string|null $name
 * @param T $default 
 * @return ($name is null ? Headers : HeaderInterface|ArrayIterator|T)
 */

All of the getHeaders() implementations can use this doc block - it should solve a fair amount of unnecessary @var annotations and psalm issues

Comment thread src/Request.php
* @param string|null $name Header name to retrieve, or null to get the whole container.
* @param mixed|null $default Default value to use when the requested header is missing.
* @return Headers|bool|HeaderInterface|ArrayIterator
* @return Headers|bool|HeaderInterface|ArrayIterator|mixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs here can be copied from getHeaders

Comment thread src/Request.php
return false !== $header && $header->getFieldValue() === 'XMLHttpRequest';
$headers = $this->getHeaders();

if (! $headers instanceof Headers) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional can be dropped when getHeaders is documented correctly

Comment thread src/Request.php
return false !== $header && stristr($header->getFieldValue(), ' flash');
$headers = $this->getHeaders();

if (! $headers instanceof Headers) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional can be dropped when getHeaders is documented correctly

Comment thread src/Request.php
return false;
}

return stripos((string) $header->getFieldValue(), ' flash') !== false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also add a deprecation here. I mean Flash has been dead for a really long time now 😂 - perhaps leave it for a separate patch - this one is already huge

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

Successfully merging this pull request may close these issues.

Add Psalm Configuration and Initial Baseline

2 participants