Skip to content

PHP 7.4 types - #586

Merged
phil-davis merged 17 commits into
sabre-io:masterfrom
phil-davis:php-7.4-types
Aug 23, 2022
Merged

phil-davis merged 17 commits into
sabre-io:masterfrom
phil-davis:php-7.4-types

Conversation

@phil-davis

@phil-davis phil-davis commented Aug 19, 2022 •

Copy link
Copy Markdown
Contributor

Add parameter and return types etc. that are available in PHP 7,4 and upwards.

Drop support for PHP older than 7.4

code from @tcitworld plus cs-fixer changes.

I went through the code and added whatever else that I could see for declaring types in PHP 7.4

And went through the test code (see last commit) to add type declarations, and make use of newer assert methods that my IDE suggested now exist.

tcitworld and others added 4 commits August 19, 2022 14:16
* Require PHP 7.4
* Add typing everywhere possible
* Small internal improvements

Signed-off-by: Thomas Citharel <[email protected]>
Signed-off-by: Thomas Citharel <[email protected]>
@phil-davis phil-davis self-assigned this Aug 19, 2022
@codecov

codecov Bot commented Aug 19, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #586 (521e509) into master (d1fdc0c) will increase coverage by 0.18%.
The diff coverage is 98.47%.

@@             Coverage Diff              @@
##             master     #586      +/-   ##
============================================
+ Coverage     98.35%   98.53%   +0.18%     
+ Complexity     1897     1865      -32     
============================================
  Files            71       71              
  Lines          4550     4159     -391     
============================================
- Hits           4475     4098     -377     
+ Misses           75       61      -14     
Impacted Files Coverage Δ
lib/ITip/Message.php 100.00% <ø> (ø)
lib/Property/Boolean.php 58.33% <80.00%> (+8.33%) ⬆️
lib/Recur/RDateIterator.php 97.29% <88.88%> (-0.33%) ⬇️
lib/Component.php 98.62% <93.93%> (-0.54%) ⬇️
lib/Recur/RRuleIterator.php 99.43% <94.73%> (-0.02%) ⬇️
lib/Cli.php 97.64% <96.87%> (-0.43%) ⬇️
lib/DateTimeParser.php 97.58% <97.43%> (-0.87%) ⬇️
lib/Property.php 98.84% <97.72%> (-0.16%) ⬇️
lib/BirthdayCalendarGenerator.php 97.95% <100.00%> (-0.23%) ⬇️
lib/Component/Available.php 100.00% <100.00%> (ø)
... and 103 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment thread composer.json Resolved
Comment thread lib/BirthdayCalendarGenerator.php Resolved
Comment thread lib/Cli.php Resolved
@phil-davis

Copy link
Copy Markdown
Contributor Author

Most of this code is a rebase of code that @tcitworld has handed over to me. I am looking through to see what else can/needs to be done. That will take "some time" because there is a lot to look at...

Comment thread lib/DateTimeParser.php
Comment on lines -97 to +89
public static function parseDuration($duration, $asString = false)
public static function parseDuration(string $duration): DateInterval

@phil-davis phil-davis Aug 19, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ToDo: understand why we can remove the $asString parameter here. This parameter is never used internally, but people using sabre/vobject could call this Sabre\VObject\DateTimeParser::parseDuration static function and use the $asString parameter.

@tcitworld do you remember why you removed the parameter? (and added parseDurationAsString below)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I probably thought it would be nicer to have consistent parameters types and return types. Sounds a sane BC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will start making notes for the release notes - need to mention this sort of stuff.

@staabm staabm Aug 23, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can do such changes more easily/with confidence when we declare the classes which are not designed to be subclassed as final.

@phil-davis
phil-davis marked this pull request as ready for review August 22, 2022 16:49
@phil-davis
phil-davis requested review from staabm and tcitworld and removed request for tcitworld August 22, 2022 16:51
@phil-davis

Copy link
Copy Markdown
Contributor Author

@staabm @tcitworld IMO this is all good, and as close as I can see to implementing all the PHP 7.4 features throughout the code.

Please let me know what you think (I know that you will not likely to be able to look at every line of the diffs!). If you are OK with this, then I could make a major version 5.0.0-RC1 which would not be an official release, but I (and anyone else) could try it in their projects and give feedback about anything that explodes unexpectedly.

@phil-davis phil-davis mentioned this pull request Aug 23, 2022
@phil-davis
phil-davis requested a review from tcitworld August 23, 2022 02:42

@staabm staabm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should level up phpstan in a future PR.

Comment thread .php-cs-fixer.dist.php Resolved
Comment thread bin/bench_freebusygenerator.php Resolved
@@ -15,23 +17,19 @@ class BirthdayCalendarGenerator
{
/**
* Input objects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

defining array key/value brings a lot of benefits. in the next PR we maybe should increase the phpstan level, so these types are required

Suggested change
* Input objects.
* Input objects.
*
* @var list<Component\VCard>

but feel free to do these in a followup as this PR already is pretty big

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I will followup with a next PR...

Comment thread lib/DateTimeParser.php
Comment on lines -97 to +89
public static function parseDuration($duration, $asString = false)
public static function parseDuration(string $duration): DateInterval

@staabm staabm Aug 23, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can do such changes more easily/with confidence when we declare the classes which are not designed to be subclassed as final.

@phil-davis
phil-davis merged commit 49dbd1b into sabre-io:master Aug 23, 2022
@phil-davis

Copy link
Copy Markdown
Contributor Author

Merged - I will followup an increased phpstan level in a next PR, before making a 5.0.0-RC1 pre-release that can be easily used to test in projects that use this.

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.

3 participants