8000 Initial psalm integration and fixes by SergiuBota1 · Pull Request #108 · laminas/laminas-http · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

8000 Initial psalm integration and fixes #108

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

Open
wants to merge 4 commits into
base: 2.22.x
Choose a base branch
from

Conversation

SergiuBota1
Copy link
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
Copy link
Member
gsteel commented Apr 15, 2025

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
Copy link
Member
@gsteel gsteel left a comment

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 👍

xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
Copy link
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 on lines +28 to 29
/** @var null|string */
protected $version = self::VERSION_11;
Copy link
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

protected $version = self::VERSION_11;

/** @var Headers|null */
/** @var Headers|null|string */
protected $headers;
Copy link
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;

@@ -51,7 +53,7 @@ public function setVersion($version)
/**
* Return the HTTP version for this request
*
* @return string
* @return string|null
Copy link
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

@@ -75,7 +77,7 @@ public function setHeaders(Headers $headers)
/**
* Return the header container responsible for headers
*
* @return Headers
* @return Headers|bool|HeaderInterface|ArrayIterator|mixed
Copy link
Member

Choose a reason for hiding this comment

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

Please revert

8000
@@ -359,7 +362,7 @@ public function getFiles($name = null, $default = null)
*
* @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
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

@@ -386,7 +389,7 @@ public function getHeaders($name = null, $default = false)
*
* @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
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

return false !== $header && $header->getFieldValue() === 'XMLHttpRequest';
$headers = $this->getHeaders();

if (! $headers instanceof Headers) {
Copy link
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

return false !== $header && stristr($header->getFieldValue(), ' flash');
$headers = $this->getHeaders();

if (! $headers instanceof Headers) {
Copy link
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

return false;
}

return stripos((string) $header->getFieldValue(), ' flash') !== false;
Copy link
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
0