Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

phpstan fixes #157

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Conversation

thomasvargiu
Copy link
Contributor

@thomasvargiu thomasvargiu commented Oct 16, 2018

  • some fixes on PHPDoc
  • added checks on types when needed

Changed

  • Throw an exception when unable to uncompress response content
  • Relative URIs are not allowed anymore in Zend\Http\Client.
    Anyway, usage of relative URIs has no sense and no adapter can handle it.

Fixed

  • Fixed Zend\Http\Cookies::getAllCookies(Zend\Http\Cookies::COOKIE_STRING_ARRAY).
  • Fixed Zend\Http\Cookies::getAllCookies(Zend\Http\Cookies::COOKIE_STRING_CONCAT).
  • Fixed use of HTTP URIs with empty path in Request

src/Cookies.php Outdated Show resolved Hide resolved
src/Cookies.php Show resolved Hide resolved
src/Header/AbstractAccept.php Show resolved Hide resolved
src/Header/AbstractAccept.php Outdated Show resolved Hide resolved
src/Header/AbstractAccept.php Outdated Show resolved Hide resolved
src/Request.php Outdated Show resolved Hide resolved
src/Request.php Outdated Show resolved Hide resolved
src/Request.php Outdated Show resolved Hide resolved
src/Request.php Outdated Show resolved Hide resolved
src/Request.php Outdated Show resolved Hide resolved
@thomasvargiu thomasvargiu changed the title WIP: phpstan fixes phpstan fixes Oct 17, 2018
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

There's a lot of great changes here, but also a ton that look like potential backwards compatibility breaks and/or unrelated changes. Please review and address all comments from myself and @Ocramius, and we can then do a final review.

Thanks, @thomasvargiu !

src/Client.php Outdated Show resolved Hide resolved
src/Client.php Outdated Show resolved Hide resolved
/** @var Client\Adapter\AdapterInterface $adapter */
$adapter = $this->adapter;

return $adapter;
Copy link
Member

Choose a reason for hiding this comment

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

I disagree with this change. If $this->adapter was not previously set, we call setAdapter() which will either raise an exception, or set the adapter to an appropriate value.

I think the solution to the phpstan errors in this case would be to say that $adapter can only be an AdapterInterface instance, and not allow null. There are no paths through the client that will allow it to remain null when it needs to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can't say that $adapter can only be an AdapterInterface because is not set in constructor. $adapter will be null until some method will call getAdapter(), then a developer should know that $this->adapter can be null.

Maybe, can we initialize it in constructor?

test/ClientTest.php Outdated Show resolved Hide resolved

if (null === $nextHost) {
throw new InvalidArgumentException('Invalid URI provided. No host found');
}
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 new behavior, and does not have a corresponding test. Please revert, or add a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added

*/
public function isHttponly()
public function isHttpOnly()
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here as for setHttponly(); revert, or introduce the new method as a proxy to the original.

@@ -89,6 +90,10 @@ public static function fromString($string)

if (preg_match("/^[ \t][^\r\n]*$/", $line, $matches)) {
// continuation: append to current line
if (! isset($current['line'])) {
$current['line'] = '';
}
Copy link
Member

Choose a reason for hiding this comment

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

This likely needs a unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and tested

@@ -93,6 +96,9 @@ public function getContent()
{
if (empty($this->content)) {
$requestBody = file_get_contents('php://input');
if (false === $requestBody) {
throw new RuntimeException('Unable to get contents from php://input');
}
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 new behavior and requires a corresponding test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and replaced with simpler condition

@@ -198,6 +202,9 @@ public static function fromString($string)
if ($response->statusCode === static::STATUS_CODE_100) {
$next = array_shift($lines); // take next line
$next = empty($next) ? array_shift($lines) : $next; // take next or skip if empty
if (null === $next) {
throw new RuntimeException('Invalid response content');
}
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 new behavior and requires a corresponding test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added

if (false === $uncompressed) {
throw new Exception\RuntimeException(
'An error occurred during inflation'
);
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 new behavior and requires a corresponding test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added

@weierophinney weierophinney modified the milestone: 2.9.0 Jan 7, 2019
@weierophinney
Copy link
Member

Removing the milestone; I suspect this patch will take a bit of back and forth before it's ready, and we're otherwise ready for the 2.9.0 release. We can target 2.10.0 for this.

@weierophinney
Copy link
Member

@thomasvargiu You will need to rebase against current develop before you start applying changes.

@thomasvargiu
Copy link
Contributor Author

@thomasvargiu You will need to rebase against current develop before you start applying changes.

@weierophinney should I target develop branch for merge?

@weierophinney
Copy link
Member

weierophinney commented Jan 13, 2019 via email

@thomasvargiu thomasvargiu changed the base branch from master to develop January 13, 2019 13:19
src/ClientStatic.php Outdated Show resolved Hide resolved
@thomasvargiu thomasvargiu changed the title phpstan fixes WIP: phpstan fixes Jan 14, 2019
.travis.yml Outdated
@@ -9,6 +9,7 @@ env:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- TESTS_ZEND_HTTP_CLIENT_ONLINE=true
- PHPSTAN_DEPS="phpstan/phpstan:^0.10.3"
Copy link
Member

Choose a reason for hiding this comment

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

In other repositories we are adding it to composer dev requirements. Maybe we should do the same here?
Then it will be much easier to run it locally. See: https://github.com/zendframework/zend-expressive/blob/master/composer.json#L40

We can also update to version 0.11 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone else told me to remove it and to add it in CI.

@thomasvargiu thomasvargiu changed the title WIP: phpstan fixes phpstan fixes Feb 19, 2019
phpstan fixes

phpstan fixes

Removed deprecations

Fixed wrong condition

Better phpdoc types

Better tests with relative datetimes

Some fixes and removed false return types

Replaced return values $this with self

Replaced usage of stdClass with object in param doc

Removed useless check and getter of adapter

Fixed typo

Reverted rename of method setHttponly, fixed usage with incorrect case

PHPStan fixes

Fix variable overwrite

Reverted composer changes

Fix and test header factory

Added test for invalid 100 response

Test gzinflate error

Added test for default query argument separator

Fixed missing char in phpdoc

Added test to handle tmpname failure

Added test for dispatch() method

Fixed cookies usage
@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-http; a new issue has been opened at laminas/laminas-http#4.

@weierophinney
Copy link
Member

This repository has been moved to laminas/laminas-http. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-http to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-http.
  • In your clone of laminas/laminas-http, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

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

Successfully merging this pull request may close these issues.

5 participants