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

Refactor types and codestyle #7

Closed
wants to merge 10 commits into from

Conversation

mmachatschek
Copy link

@mmachatschek mmachatschek commented Jan 27, 2022

This updates the codebase to use types where appropriate and adds PHP 7.4 support.

Changes:

  • Add PHP 7.4 support, Fixes Support PHP 7 #9
  • Add typed properties
  • Add typed method parameters
  • Add typed return types
  • Optimize codestyle (php-cs-fixer, PHPStorm Code optimization)
  • Use abstract classes to remove redundent code for Marks and Nodes

Open:

Copy link
Contributor

@hanspagel hanspagel left a comment

Choose a reason for hiding this comment

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

Ha, that was fast! :-)

Comment on lines -16 to +19
return [];
return [
'HTMLAttributes' => [],
];
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, those options depend on the extension. Currently all nodes and marks support HTMLAttributes, but Heading also has levels for example.

Copy link
Author

Choose a reason for hiding this comment

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

I moved this to the abstract class, as all of the classes extending Mark have the array like that. The Heading class overrides the method and therefore adds its own implementation. In case one of the marks or nodes doesn't need the HTMLAttributes, you can simply override it with return [];

Comment on lines -13 to -18
public function addOptions()
{
return [
'HTMLAttributes' => [],
];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can’t we keep that? Technically, it’s not really required (yet), but I tried a lot to keep the API similar to the JavaScript API and it’s required there.

Copy link
Author

@mmachatschek mmachatschek Jan 27, 2022

Choose a reason for hiding this comment

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

This is inherited by the Mark abstract class and would be redundant if every class that extends it, implements the same code

{
return [];
}
abstract public function renderHTML($mark, array $HTMLAttributes = []): array;
Copy link
Author

Choose a reason for hiding this comment

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

@hanspagel the $mark parameter and $node parameter on the Node class is unused. Did you have think of any future usecase, where you need to access those values inside the renderHTML method? It's probably for own implementations. Am I write about this?

@@ -12,6 +12,7 @@
<ignoreFiles>
<directory name="vendor"/>
<file name="src/NewDOMSerializer.php" />
<file name="src/DOMSerializerPointer.php" />
Copy link
Author

Choose a reason for hiding this comment

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

@hanspagel I think the two files can be completely removed? Do they serve some future ideas?

@@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0]
php: [7.4, '8.0', 8.1]
Copy link
Author

Choose a reason for hiding this comment

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

Added PHP 7.4 support for people still stuck to older versions. I'm not 100% sure (didn't test it) but I think you can even install it on 7.3 but I would not suggest to add it as its already out of the maintainance and security support.

Others can use e.g. RectorPHP to generate a <7.4 compatible version of the library

@mmachatschek mmachatschek changed the title WIP Refactor types and codestyle Feb 1, 2022
@hanspagel
Copy link
Contributor

Thanks! There are multiple things I do like about the PR, but also some things I don’t like about the PR.

One thing I’m hesitant is to change the style of how the nodes and marks are created, because it’s by design that they are plain translations from JavaScript to PHP, even if I’d maybe do some things different if it would only be a PHP package.

I’d suggest that I go through the changes and incorporate what I like, and we’ll talk about the rest then. What do you think?

@mmachatschek
Copy link
Author

I guess I'll revert 80497b1 so it's easier to see my changes. The code optimization will be put in a separate PR

@hanspagel
Copy link
Contributor

Sounds good! Wait a little bit though. I have a pending branch I somewhow failed to push. It includes a few core changes.

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.

Support PHP 7
2 participants