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 #778

Closed
wants to merge 46 commits into from
Closed

Psalm #778

wants to merge 46 commits into from

Conversation

SignpostMarv
Copy link
Contributor

No description provided.

@oliverklee
Copy link
Contributor

This will probably greatly benefit from #777.

@SignpostMarv
Copy link
Contributor Author

So there's an issue in that slevomat/coding-standard 5.0.4 requires php 7.1 & there's a sniff used that isn't in the latest version that supports php 7.0.

Rather than tinkering with the travis config, I'd recommend dropping php 7.0, given that it's been EOL for 8 months.

@oliverklee
Copy link
Contributor

So there's an issue in that slevomat/coding-standard 5.0.4 requires php 7.1 & there's a sniff used that isn't in the latest version that supports php 7.0.

If that's the case, then we need to revert part of #773. I wonder why the Travis build has not failed, though.

As for the minimum PHP version, we plan to require PHP >= 7.1 for Emogrifier 5.0 (i.e., for the next-after-next breaking release). As we have announced that PHP >= 7.0 will suffice for Emogrifier 4.0.0, I'd like to not break that promise.

(We could release 4.0.0 quite soon so we can drop PHP 7.0, though.)

@SignpostMarv
Copy link
Contributor Author

it's also worth noting that 7.1 goes EOL as of next year.

@oliverklee
Copy link
Contributor

I have created #779 to resolve the problem with PHP 7.0.

@SignpostMarv
Copy link
Contributor Author

SignpostMarv commented Oct 1, 2019

I'll rebase once that's merged, although possibly not this evening.

@oliverklee
Copy link
Contributor

oliverklee commented Oct 1, 2019

Thanks, that's perfectly fine. There is no hurry.

By the way, I'd prefer to have relatively low-impact PRs, e.g., one for adding psalm to the CI chain (without any code changes) and for adding a baseline, then others for fixing issues found by psalm, another for adding psalm-specific annotations, one for sorting the dependencies etc.

@SignpostMarv
Copy link
Contributor Author

By the way, I'd prefer to have relatively low-impact PRs, e.g.,

split ef33fbf into 3 on the rebase?

@oliverklee
Copy link
Contributor

split ef33fbf into 3 on the rebase?

Yes, thanks, that would be great.

composer.json Outdated Show resolved Hide resolved
Copy link
Contributor

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

I've added a few comments/suggestions/observations. @SignpostMarv, thanks for contributing, looks like a fair bit of work 🤩

composer.json Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
src/Emogrifier/HtmlProcessor/AbstractHtmlProcessor.php Outdated Show resolved Hide resolved
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 2, 2019
This commit updates the changelog in reference to the previous commits
implementing psalm checking & resolving issues.

regarding: MyIntervals#537, MyIntervals#778
@SignpostMarv
Copy link
Contributor Author

This is why I generally commit all psalm bug fixes en-masse.

@SignpostMarv SignpostMarv marked this pull request as ready for review October 2, 2019 22:35
Copy link
Contributor

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

Looks generally excellent. I am close to being happy for this to be meged to master, but not quite.

There are some changes relating to methods being static vs non-static I'm not totally happy with, because thier counterparts in PHPUnit are static.

There are also a few other tiny improvements that could be made (really minor issues). But I'd be happy for them to be addressed in a separate PR, so that we can get this one merged.

And I think the config files should be in the config directory. I'd be totally happy with this being addressed by a separate future PR – handling changes like this now in this PR I'm sure would be an unnecessary pain 😉

@oliverklee, what do you think?

composer.json Outdated
@@ -74,6 +76,7 @@
"ci:php:sniff": "phpcs config src tests",
"ci:php:fixer": "php-cs-fixer --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff-format=udiff config/ src/ tests/",
"ci:php:md": "phpmd src text config/phpmd.xml",
"ci:php:psalm": "psalm --show-info=false",
Copy link
Contributor

@JakeQZ JakeQZ Oct 2, 2019

Choose a reason for hiding this comment

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

Could we add this to Travis? If so, let's do it as a separate PR (and get this one merged sooner rather than later).

EDIT: see #736

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had overlooked this, was running composer run ci locally.

There's also vimeo/psalm#1192 to take into account, the fix for which wasn't yet introduced in 3.2 (which you're stuck using because of various dependencies).

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Let's do this as a separate PR. I've added #790 so that it is captured and this conversation can be resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see you've pushed a commit to this PR adding the step to Travis, but it's currently failing due to some remaining issues. I suggest also addressing the remaining issues as that (or another) separate PR - this one is beginning to become hard to follow and keep track of via the GitHub UI.

psalm.baseline.xml Show resolved Hide resolved
src/CssInliner.php Outdated Show resolved Hide resolved
src/HtmlProcessor/AbstractHtmlProcessor.php Outdated Show resolved Hide resolved
src/HtmlProcessor/AbstractHtmlProcessor.php Show resolved Hide resolved
int $expectedCount,
string $needle,
string $haystack
) {
self::assertSame(
$this->assertSame(
Copy link
Contributor

Choose a reason for hiding this comment

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

assertSame is a static method and should be called staticly. Is there an issue with Psalm that we need a workaround for here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that'd be NonStaticSelfCall 7d7a528#diff-db03589574d7c5d074966c97658929d9

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like an issue with Psalm then. assertSame is definitely a static method in PHPUnit.

I've added #792 to capture this. For now, can we revert changes relating to calls via self:: vs $this (and also any changes making methods static vs non-static), so that we can get this PR merged, and then move on to address the remaining issues separately?

tests/Unit/CssInlinerTest.php Outdated Show resolved Hide resolved
tests/Unit/CssInlinerTest.php Outdated Show resolved Hide resolved
tests/Unit/HtmlProcessor/HtmlPrunerTest.php Outdated Show resolved Hide resolved
tests/Unit/HtmlProcessor/HtmlPrunerTest.php Outdated Show resolved Hide resolved
@oliverklee
Copy link
Contributor

@SignpostMarv Thanks for this huge effort!

I'd like to keep "separate things in separate PRs", i.e., one separate PR for adding psalm to the build and adding the baseline, and then one (or more) separate PRs for fixing things found by psalm and adding psalm-specific annotations. Optimally, those separate PRs will start with one commit each.

@oliverklee
Copy link
Contributor

(Smaller PRs will also make the reviews easier and help get the parts merged a lot faster.)

@SignpostMarv
Copy link
Contributor Author

@oliverklee @JakeQZ When I split this into multiple PRs, should the NonStaticSelfCall be split onto it's own PR?

Optimally, those separate PRs will start with one commit each.

At present this would result in 30~ PRs.

@oliverklee
Copy link
Contributor

Optimally, those separate PRs will start with one commit each.

Sorry, my comment was a bit ambiguous. I meant "Define well-cut packages for each PR, and if necessary, squash several commits for the same package together before creating the PR for that package."

@oliverklee
Copy link
Contributor

When I split this into multiple PRs, should the NonStaticSelfCall be split onto it's own PR?

In principle, yes. (Although I do not agree with that particular change. I'll add a comment to that commit in a second.)

SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 3, 2019
This commit updates the changelog in reference to the previous commits
implementing psalm checking & resolving issues.

regarding: MyIntervals#537, MyIntervals#778
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 3, 2019
Comment on lines +32 to +34
/** @psalm-var array{0:string, 1:string, 2:string, 3:string} */
$matches = $matches;

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this instead be @psalm-param for the function/closure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see commit message for f6ea5a1

@JakeQZ
Copy link
Contributor

JakeQZ commented Oct 6, 2019

Everybody, please let's split this into smaller PRs and merge those.

PR by file is probably a good approach, given that I've been going up from the bottom of the baseline.

Can I suggest by specific Psalm check rather than by file?

i.e. Enable one-by-one the checks in <issueHandlers> in psalm.xml and address the code changes required for that specific issue. And each issueHandler in a separate PR. With a CHANGELOG entry for each one in the Fixed section "Issues detected by Psalm {name-of-issue-handler}".

If there are some <issueHandlers> that can be added without making any code changes, then we could add those as a single PR, and probably do not need a CHANGELOG entry since we already have "Check the code with Psalm" and there was nothing else to fix.

@SignpostMarv, @oliverklee, does that make sense?

@SignpostMarv
Copy link
Contributor Author

i.e. Enable one-by-one the checks in <issueHandlers> in psalm.xml and address the code changes required for that specific issue.

issues error by default.

@SignpostMarv
Copy link
Contributor Author

Can I suggest by specific Psalm check rather than by file?

PR by file would mean continuous blocks would be removed from ./psalm.baseline.xml, generally having a single block to merge- making rebasing and merging more straightforward.

PR by type can introduce issues of other types, possibly introducing issues a PR was already made for; there's a couple of those in this PR.

@JakeQZ
Copy link
Contributor

JakeQZ commented Oct 6, 2019

issues error by default.

So we could enable one issue, and fix the errors for that specific issue, and have that as a single PR? Rinse and repeat?

Those that cause errors we cannot address right now (e.g. this vs self due to version constraints) will have to wait until PHP 7.0 support is dropped (or we allow the Psalm step to be skipped for PHP 7.0 in Travis, but still run for PHP 7.1+).

@SignpostMarv
Copy link
Contributor Author

So we could enable one issue, and fix the errors for that specific issue, and have that as a single PR? Rinse and repeat?

prepping an explanation on #795 in response to query there.

@JakeQZ
Copy link
Contributor

JakeQZ commented Oct 6, 2019

prepping an explanation on #795 in response to query there.

OK, thanks. Just been reading https://erik.booij.me/a-year-with-psalm/

@SignpostMarv
Copy link
Contributor Author

prepping an explanation on #795 in response to query there.

following on from that explanation, what one could do is:

  1. set an issue type to "info",
  2. run psalm with --set-baseline
  3. remove the issue type entry added in step 1
  4. run psalm --show-info=false
  5. fix issues.

what I've been doing is:

  1. remove an issue type from a particular file in the baseline, or remove a single instance if there are many
  2. run psalm --show-info=false
  3. fix issues

@JakeQZ
Copy link
Contributor

JakeQZ commented Oct 6, 2019

following on from that explanation

Thanks for that. I'm beginning to get a grasp on how it works 🙂

what one could do is

I'm just wanting to be sure we're taking the best approach to make all our lives easier, both in terms of being able to keep track of what changes are being made to the code base and why, and to minimize the effort actually required to get to a good baseline.

@JakeQZ
Copy link
Contributor

JakeQZ commented Oct 6, 2019

...

Really, any way that breaks down the changes into small mangeable chunks would be good :)

@SignpostMarv, we very much appreciate the effort you've been putting in here, it's been amazing.

SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit updates the changelog in reference to the previous commits
implementing psalm checking & resolving issues.

regarding: MyIntervals#537, MyIntervals#778
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit resolves the yoda conditions introduced in previous
[BUGFIX] commits.

regarding: MyIntervals#794, MyIntervals#778 (comment)
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit updates the changelog in reference to the previous commits
implementing psalm checking & resolving issues.

regarding: MyIntervals#537, MyIntervals#778
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit resolves the yoda conditions introduced in previous
[BUGFIX] commits.

regarding: MyIntervals#794, MyIntervals#778 (comment)
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit updates the changelog in reference to the previous commits
implementing psalm checking & resolving issues.

regarding: MyIntervals#537, MyIntervals#778
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit resolves the yoda conditions introduced in previous
[BUGFIX] commits.

regarding: MyIntervals#794, MyIntervals#778 (comment)
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit resolves the yoda conditions introduced in previous
[BUGFIX] commits.

regarding:
* MyIntervals#794
* MyIntervals#778 (comment)
* MyIntervals#805 (review)
JakeQZ pushed a commit that referenced this pull request Oct 7, 2019
… updating baseline.

This commit resolves one of the PossiblyNullPropertyAssignmentValue
issues identified in src/HtmlProcessor/AbstractHtmlProcessor.php
at the expense of identifying various further Null issues

regarding: #537

(Note: the following commit messages from the PR are included for completeness, but may overlap with others due to merges/rebases.)

* [BUGFIX] partially satisfy psalm, updating baseline

This commit resolves the PossiblyNullReference issues introduced
by a previous [BUGFIX] in src/HtmlProcessor/AbstractHtmlProcessor.php
by refactoring `$this->domDocument->` to `$this->getDomDocument()->`

This necessarily alters the body of the previously identified
NullableReturnStatement issue.

regarding: #537

* [BUGFIX] partially satisfy psalm, updating baseline

This commit resolves 1 InvalidNullableReturnType and
1 NullableReturnStatement issue identified in
src/HtmlProcessor/AbstractHtmlProcessor.php by throwing an exception
if `AbstractHtmlProcessor::$domDocument` has not been set.

regarding: #537

* [BUGFIX] satisfy php-cs-fixer

This commit resolves the yoda conditions introduced in previous
[BUGFIX] commits.

regarding:
* #794
* #778 (comment)
* #805 (review)

* [TASK] Add exception code based on UNIX timestamp

regarding: #805 (comment)

* [CLEANUP] Adjust indentation

This commit adjusts the indentation separate from the addition of
parenthesis in a previous commit, on the basis of making indentation &
line break changes separate from functional changes.

regarding: #805 (comment)
JakeQZ pushed a commit that referenced this pull request Oct 7, 2019
* [BUGFIX] resolve PossiblyNull psalm issues via phpunit instanceof assertion, re: #537

This commit resolves the PossiblyNull issue identified in tests/Unit/CssInlinerTest.php
by adding an additional assertion that would force the test to fail
if the `DOMNodeList::item()` resolved to a non-element result (i.e.
null or other DOMNode type)

regarding: #537

* [CLEANUP] removing superfluous line breaks

regarding: #778 (comment)

* [BUGFIX] Partially satisfy psalm, update baseline

This commit resolves a set of InvalidOperand issues by using the
psalm-specific docblock tags `@psalm-return`, `@psalm-var`, and
`@psalm-param`

regarding: #801 (review)
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit updates the changelog in reference to the previous commits
implementing psalm checking & resolving issues.

regarding: MyIntervals#537, MyIntervals#778
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
SignpostMarv added a commit to SignpostMarv/emogrifier that referenced this pull request Oct 7, 2019
This commit resolves the yoda conditions introduced in previous
[BUGFIX] commits.

regarding: MyIntervals#794, MyIntervals#778 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants