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

Fix few problems reported by PHPStan #192

Merged
merged 6 commits into from
Aug 27, 2023
Merged

Fix few problems reported by PHPStan #192

merged 6 commits into from
Aug 27, 2023

Conversation

szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented Aug 27, 2023

@spekulatius If you like robust code you may continue fixing the rest of the problems.

(otherwise just close it - this is an inspiration)

src/PHPScraper.php Outdated Show resolved Hide resolved
@szepeviktor
Copy link
Contributor Author

NavigationTest::testSurfWithAbsoluteLink fails as link on https://test-pages.phpscraper.de/navigation/1.html changed.

@spekulatius
Copy link
Owner

Hey @szepeviktor,

Thank you for taking the time to prepare a PR! I can see there are areas that need improving.

I've replied to your comments and changes. Could you have a look and check the PHPStan issues?

Do you think anything else should go into this?

Cheers,
Peter

@szepeviktor
Copy link
Contributor Author

Do you think anything else should go into this?

Yes. Your work :)

Comment on lines -30 to +36
public function __construct(?array $config = [])
/**
* @param PHPScraperConfig $config
*/
public function __construct(array $config = [])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed null as the base value of the configuration array.

source

Copy link
Owner

Choose a reason for hiding this comment

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

That should be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW arrays are not for carrying nonhomogeneous elements.
Arrays are for lists: keyless elements of the same type.
Configuration should be a self-contained object.

$config->followRedirects();
$config->dontFollowRedirects();
$config->getHttpClientConfiguration(); // returns that array

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, introducing an object to contain the config would be neat

@@ -39,9 +45,9 @@ public function __construct(?array $config = [])
/**
* Sets the config, generates the required Clients and updates the core with the new clients.
*
* @param ?array $config = []
* @param PHPScraperConfig $config
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These could be as follows if your IDE complains.

     * @param array<string, mixed> $config
     * @phpstan-param PHPScraperConfig $config

@szepeviktor
Copy link
Contributor Author

The next step is to remove ignoreErrors from PHPStan configuration.
It is up to you!

@@ -11,23 +11,29 @@
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\HttpClient\HttpClient as SymfonyHttpClient;

/**
Copy link
Owner

Choose a reason for hiding this comment

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

Nice, that's a great solution to telling PHPStan better what is in the variables. Thanks!

Comment on lines -30 to +36
public function __construct(?array $config = [])
/**
* @param PHPScraperConfig $config
*/
public function __construct(array $config = [])
Copy link
Owner

Choose a reason for hiding this comment

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

That should be fine

@spekulatius spekulatius merged commit 7e8cb3b into spekulatius:master Aug 27, 2023
5 checks passed
@szepeviktor szepeviktor deleted the fix-phpstan branch August 27, 2023 20:43
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.

None yet

2 participants