Conversation
This change updates the Composer configuration to only support PHP 8.2, 8.3, and 8.4, and then updates the relevant packages to the latest version that supports at least PHP 8.2 as well. Along with that, it updates PHPUnit to version 11 as it's the latest version that at least supports PHP 8.2.
This change removes usage of deprecated code in the codebase, either replacing it with the recommended replacement, or the standard replacement. So, MarkdownConverterInterface was replaced with the recommended replacement of ConverterInterface, and the applicable function call was replaced. Then, getMockForAbstractClass, which is deprecated without replacement in PHPUnit 12 was replaced with createMock.
This change makes explicit use of types throughout the codebase wherever they were missing. In addition, it uses union types for nulls, as that's required in PHP 8.4.
This change updates the GitHub Workflow to support only PHP 8.2 - 8.4.
On attempting to run the workflow, I encountered the following error: "Missing download info for actions/cache@v2". After some searching on the error, the recommended fix was to update from version 2 to 4. So, this change is being made to test the solution and, all being well, correct the issue.
mnapoli
left a comment
There was a problem hiding this comment.
Thanks a lot! I added a few questions inline
| private ConverterInterface|null $parser; | ||
|
|
||
| public function __construct(MarkdownConverterInterface $commonMarkConverter = null) | ||
| public function __construct(ConverterInterface|null $commonMarkConverter = null) |
There was a problem hiding this comment.
Just to be sure: this isn't a BC break?
There was a problem hiding this comment.
Hmm, good question. I'd not thought of that. Will check.
There was a problem hiding this comment.
I'll admit that I cannot say with 100% certainty that it isn't. However, I believe it's not as, up until now, the parameter has been allowed to be null, marking it as a null type implicitly. I believe that this change just makes that state explicit.
There was a problem hiding this comment.
No I mean the change from MarkdownConverterInterface to ConverterInterface
There was a problem hiding this comment.
Sorry, I misunderstood. Thanks for clarifying. Will look into it today.
There was a problem hiding this comment.
I hope that I've better understood you this time. ConverterInterface has been available since 2.2.0, back in early 2022. I suspect that it likely wouldn't be a BC break, but hope that I've assessed this correctly.
There was a problem hiding this comment.
This is a BC break, we can't merge that as-is.
Here's an example:
// This is userland code
$parser = new ...(); // class that implements MarkdownConverterInterface
new Mni\FrontYAML\Bridge\CommonMark\CommonMarkParser($parser);the code above works today. With your PR, it wouldn't work.
There was a problem hiding this comment.
Thanks for discussing this further. I don't think I fully understood your point, originally.
|
@mnapoli, thanks for taking the time to review my PR. |
As was pointed out by @mnapoli, https://github.com/mnapoli/FrontYAML/pull/32/files#r2061309338, yamlParser and markdownParser should not be allowed to be null. So, this change removes that, specific, part of cd4c2dd.
This reverts the change to CommonMarkParser in 803e158 allowing $parser to be both null and an instance of ConverterInterface, as pointed out by @mnapoli in mnapoli#32 (comment).
|
Hey @mnapoli, any further feedback? |
|
Ping @mnapoli. |
|
Hey @settermjd Catching up with this, is my comment above not relevant anymore?
|
Thank you to @mnapoli for pointing out that the original change would have been a BC break.
This change continues adding type declarations, where applicable, both in source and test code, and makes a few minor style changes.
|
@mnapoli thanks for catching my mistake, earlier. I've added a further commit, adding further type support. Otherwise, I've left the code as is. I'm up for creating a further PR adding in more QA tooling, and improving the code styling. |
mnapoli
left a comment
There was a problem hiding this comment.
I'm not sure what happened there but there are so many unrelated changes to code formatting that we don't want. I started reviewing but it's beyond just 1 file, please don't reformat the project for unrelated code changes.
| <?php declare(strict_types=1); | ||
| <?php | ||
|
|
||
| declare(strict_types=1); |
| * Bridge to the League CommonMark parser | ||
| */ | ||
| class CommonMarkParser implements MarkdownParser | ||
| final class CommonMarkParser implements MarkdownParser |
| public function __construct(MarkdownConverterInterface|null $commonMarkConverter = null) | ||
| { | ||
| $this->parser = $commonMarkConverter ?: new CommonMarkConverter; | ||
| $this->parser = $commonMarkConverter ?: new CommonMarkConverter(); |
| public function parse(string $markdown): string | ||
| { | ||
| return $this->parser->convertToHtml($markdown)->getContent(); | ||
| return $this->parser?->convertToHtml($markdown)?->getContent() ?? ''; |
I've been refactoring and modernising an older code base recently and hit a wall using PHP 8.4 because of the current implementation of FrontYaml. Given that I love using it and want to continue, I've created this PR to modernise it for PHP 8.4 (and to remove explicit support for older versions that are long since EOL).
Specifically, the PR: