Skip to content

[test] Bump phan 1.3.5#34023

Closed
phil-davis wants to merge 5 commits intomasterfrom
bump-phan-1.1.10
Closed

[test] Bump phan 1.3.5#34023
phil-davis wants to merge 5 commits intomasterfrom
bump-phan-1.1.10

Conversation

@phil-davis
Copy link
Contributor

Get a snapshot of what the latest phan version is reporting

@phil-davis phil-davis self-assigned this Jan 4, 2019
@codecov
Copy link

codecov bot commented Jan 4, 2019

Codecov Report

Merging #34023 into master will decrease coverage by 11.67%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #34023       +/-   ##
=============================================
- Coverage     64.77%   53.09%   -11.68%     
=============================================
  Files          1198       61     -1137     
  Lines         69418     7193    -62225     
  Branches       1276     1276               
=============================================
- Hits          44964     3819    -41145     
+ Misses        24085     3005    -21080     
  Partials        369      369
Flag Coverage Δ Complexity Δ
#javascript 53.09% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit ? ?
Impacted Files Coverage Δ Complexity Δ
apps/updatenotification/templates/admin.php
lib/private/Encryption/Keys/Storage.php
lib/private/App/CodeChecker/NodeVisitor.php
lib/private/RedisFactory.php
apps/dav/lib/Avatars/AvatarNode.php
...s/dav/appinfo/Migrations/Version20170202213905.php
apps/dav/lib/Upload/ChunkLocationProvider.php
apps/files/lib/AppInfo/Application.php
apps/systemtags/list.php
apps/files_external/lib/Lib/Backend/DAV.php
... and 1127 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4eb971a...db8b2d7. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 4, 2019

Codecov Report

Merging #34023 into master will decrease coverage by 0.92%.
The diff coverage is 59.37%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #34023      +/-   ##
============================================
- Coverage     65.68%   64.76%   -0.93%     
+ Complexity    18735    18348     -387     
============================================
  Files          1221     1198      -23     
  Lines         70793    69432    -1361     
  Branches       1288     1276      -12     
============================================
- Hits          46503    44969    -1534     
- Misses        23913    24094     +181     
+ Partials        377      369       -8
Flag Coverage Δ Complexity Δ
#javascript 53.09% <ø> (-0.61%) 0 <ø> (ø)
#phpunit 66.11% <59.37%> (-0.95%) 18348 <0> (-387)
Impacted Files Coverage Δ Complexity Δ
apps/dav/lib/Connector/Sabre/ServerFactory.php 95.65% <ø> (-0.24%) 10 <0> (ø)
apps/dav/lib/DAV/CopyPlugin.php 95.23% <ø> (ø) 8 <0> (ø) ⬇️
apps/dav/lib/Connector/Sabre/Node.php 75% <ø> (ø) 49 <0> (ø) ⬇️
apps/dav/lib/Connector/Sabre/QuotaPlugin.php 88.52% <ø> (ø) 26 <0> (ø) ⬇️
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php 63.63% <ø> (ø) 20 <0> (ø) ⬇️
apps/dav/lib/DAV/Sharing/Plugin.php 68.57% <ø> (+0.27%) 7 <0> (-7) ⬇️
lib/private/Streamer.php 0% <ø> (ø) 13 <0> (ø) ⬇️
apps/dav/lib/Connector/Sabre/AutorenamePlugin.php 0% <0%> (ø) 9 <0> (ø) ⬇️
apps/dav/lib/CalDAV/CalendarHome.php 0% <0%> (ø) 19 <0> (ø) ⬇️
core/register_command.php 0% <0%> (ø) 0 <0> (ø) ⬇️
... and 209 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65991b3...23e815a. Read the comment docs.

@phil-davis phil-davis force-pushed the bump-phan-1.1.10 branch 5 times, most recently from be76a5d to bafef21 Compare January 4, 2019 09:21
public function updateShares(array $add, array $remove) {
/** @var CalDavBackend $calDavBackend */
$calDavBackend = $this->caldavBackend;
\assert($calDavBackend instanceof CalDavBackend);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

phan does not understand (or believe or...) a variable doc like above. So it thinks that $calDavBackend can be just any old BackendInterface and it complains that BackendInterface has no method called updateShares

The "easy" fix is to put this assert() here. Then phan really believes it is a CalDavBackend and so knows about method updateShares.

The question I have is why is the constructor here got BackendInterface $caldavBackend. Maybe it could/should be CalDavBackend $caldavBackend ?


$view = $this->server->tree->getView();
$tree = $this->server->tree;
\assert($tree instanceof ObjectTree);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

phan and PHPstorm tell me that $this->server->tree might not have a getView() method.
At run-time if it really does not have a getView() method, then I guess it is already going to explode.
Adding assert() here makes both phan and PHPstorm happy that getView() is going to exist.
As long as ObjectTree is really the only object type that happens here, then this assert() will only die when the line after would die anyway. But if there are other object types that have a getView() and happen here, then not so good.

Copy link
Contributor

Choose a reason for hiding this comment

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

At run-time if it really does not have a getView() method, then I guess it is already going to explode.

This implicit assumption is asking for trouble. If Either the code only receives proper objects, or it needs to explicitly protect itself from doing invalid things

if (!$tree instanceof ObjectTree) { throw new \RuntimeException("...") }

*/
public function addFileFromStream($stream, $internalName, $size) {
if ($this->streamerInstance instanceof ZipStreamer) {
/* @phan-suppress-next-line PhanParamTooFew */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

phan does not work out that this is a ZipStreamer - it thinks it is a TarStreamer and complains that there must be 3 parameters. (Maybe an assert() will help it?)

@phil-davis
Copy link
Contributor Author

This is a demo of what can be done to implement phan 1.1.* and "fix" the things it reports.
It reports lots of PhanUndeclaredMethod usually because some object is returned to a variable somewhere, and the return value is some wider more general base object. Then the code goes on to call a method that only exists in some child object. See the comments I have made to get an idea of the situation.

https://github.com/phan/phan/wiki/Annotating-Your-Source-Code has hints about putting assert() in the code to force checks that the type of object really is correct. That makes phan and PHPstorm happy. It means that stuff could die at the assert(). But if the correct assert() is used, then it will only die in the same situation as when it would die trying to call a method that does not exist.

Perhaps the return types of various methods could be tightened up to stop this problem? Perhaps there are other ways to "fix" this stuff? Or perhaps we ignore PhanUndeclaredMethod?

Anyway, this is a little demo of what can be done.

Discussion @PVince81 @DeepDiver1975 @patrickjahns and anyone else.

@phil-davis phil-davis force-pushed the bump-phan-1.1.10 branch 2 times, most recently from de4c126 to 87c9929 Compare January 4, 2019 11:00
@patrickjahns
Copy link
Contributor

patrickjahns commented Jan 4, 2019

Please also see: #32493

Suggestion for the next iteration would actually be, to pair with one of the core developers and go over these findings and fix them. These changes should not be done lightly. Some of the changes even if they seem innocent, change object types and not all scenarios will be covered by unit tests here.

Related to assert - I am highly against using assert in a normal code path. assert will not protect the code against problems (ref: http://php.net/manual/de/function.assert.php ) - instead of using asserts I prefer to use the file annotations of phan, so it is clear that this is related to the static code analysis and not relevant to business logic

If we are doing code changes related to static code analysis, please include the relevant error the change is fixing to be able to discuss if the change is just hiding an error, or if the change actually solves a deeper issue.

Example:
#31807 (comment)

@phil-davis
Copy link
Contributor Author

Some of the changes even if they seem innocent, change object types and not all scenarios will be covered by unit tests here.

I agree. For the demonstration changes I made here, I was a bit surprised that I did not break any unit tests. Maybe what I did was fine and only assumed/asserted the correct object types actually used by the code, or maybe the code path(s) were not covered by unit tests, maybe the pigs can help before they fly ;)

I certainly did not feel comfortable asserting a particular object type in some of the situations where it was not obvious to me that it would be the only object type to ever be passed through that code path.

@phil-davis phil-davis mentioned this pull request Feb 15, 2019
10 tasks
@phil-davis phil-davis changed the title [test] Bump phan 1.1.10 [test] Bump phan 1.3.5 Jun 11, 2019
@phil-davis
Copy link
Contributor Author

See PR #35817

@phil-davis phil-davis closed this Jul 20, 2019
@phil-davis phil-davis deleted the bump-phan-1.1.10 branch July 20, 2019 03:00
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.

2 participants