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

[stable10] Introduce phpstan #35774

Merged
merged 18 commits into from
Jul 10, 2019
Merged

[stable10] Introduce phpstan #35774

merged 18 commits into from
Jul 10, 2019

Conversation

phil-davis
Copy link
Contributor

@phil-davis phil-davis commented Jul 7, 2019

Description

  1. Backport of various commits from PR Introduce phpstan #31810
  2. Then fix other stuff in stable10 that phpstan reports.

Also fixes #35773

Motivation and Context

When trying some things for "drop PHP 7.0" and for PHPunit7 I noticed some problems and ended up in some of the same code that was corrected/adjusted by master PR #31810

Issue

How Has This Been Tested?

Local run of:

make test-php-phpstan

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@phil-davis phil-davis self-assigned this Jul 7, 2019
@@ -89,7 +89,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
$sourceScanner = $this->getSourceScanner();
if ($sourceScanner instanceof NoopScanner) {
list(, $internalPath) = $this->storage->resolvePath($file);
return parent::scan($internalPath, $reuseExisting, $parentId, $cacheData, $lock);
return parent::scan($internalPath, self::SCAN_SHALLOW, $reuseExisting, $lock);
Copy link
Contributor Author

@phil-davis phil-davis Jul 7, 2019

Choose a reason for hiding this comment

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

Does this code ever get called?
The params were wrong.

See #32377 (comment)
#32377 has touched/fixed this code in master but never got backported.

@phil-davis phil-davis force-pushed the stable10-add-phpstan branch from e7a0568 to 686aa34 Compare July 7, 2019 14:22
@codecov
Copy link

codecov bot commented Jul 7, 2019

Codecov Report

Merging #35774 into stable10 will increase coverage by 0.25%.
The diff coverage is 76%.

Impacted file tree graph

@@              Coverage Diff               @@
##             stable10   #35774      +/-   ##
==============================================
+ Coverage       64.84%   65.09%   +0.25%     
+ Complexity      20243    20238       -5     
==============================================
  Files            1299     1300       +1     
  Lines           77220    77237      +17     
  Branches         1301     1301              
==============================================
+ Hits            50070    50278     +208     
+ Misses          26765    26574     -191     
  Partials          385      385
Flag Coverage Δ Complexity Δ
#javascript 53.85% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 66.28% <76%> (+0.28%) 20238 <30> (-5) ⬇️
Impacted Files Coverage Δ Complexity Δ
lib/private/Session/Session.php 100% <ø> (ø) 5 <0> (ø) ⬇️
lib/private/Files/Storage/Common.php 85.15% <ø> (+3.33%) 141 <0> (ø) ⬇️
lib/private/Session/CryptoWrapper.php 47.05% <ø> (ø) 6 <0> (ø) ⬇️
core/Command/Maintenance/DataFingerprint.php 100% <ø> (ø) 4 <0> (ø) ⬇️
lib/private/Files/Node/Folder.php 96.15% <ø> (-0.03%) 45 <0> (ø)
lib/private/Files/Cache/Wrapper/CacheWrapper.php 89.06% <ø> (+2.69%) 29 <0> (-1) ⬇️
apps/systemtags/appinfo/app.php 14.28% <ø> (ø) 0 <0> (ø) ⬇️
core/Command/Group/AddMember.php 100% <ø> (ø) 9 <0> (ø) ⬇️
lib/private/legacy/util.php 70.18% <ø> (+2.84%) 239 <0> (-2) ⬇️
lib/private/Console/TimestampFormatter.php 0% <ø> (ø) 8 <0> (ø) ⬇️
... and 93 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 305a8ec...1b368f7. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 7, 2019

Codecov Report

Merging #35774 into stable10 will decrease coverage by 19.3%.
The diff coverage is 0%.

Impacted file tree graph

@@               Coverage Diff               @@
##             stable10   #35774       +/-   ##
===============================================
- Coverage       64.99%   45.68%   -19.31%     
===============================================
  Files            1302      116     -1186     
  Lines           77354    11519    -65835     
  Branches         1301     1301               
===============================================
- Hits            50274     5263    -45011     
+ Misses          26695     5871    -20824     
  Partials          385      385
Flag Coverage Δ Complexity Δ
#javascript 53.85% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 31.14% <0%> (-35.03%) 0 <0> (-20279)
Impacted Files Coverage Δ Complexity Δ
apps/files_external/lib/Lib/Storage/Swift.php 66.16% <ø> (ø) 0 <0> (ø) ⬇️
apps/files_external/lib/Lib/Storage/SFTP.php 0% <ø> (ø) 0 <0> (ø) ⬇️
apps/files_external/lib/Lib/Storage/AmazonS3.php 7.73% <ø> (ø) 0 <0> (ø) ⬇️
...external/lib/Lib/LegacyDependencyCheckPolyfill.php 47.36% <0%> (ø) 0 <0> (ø) ⬇️
lib/private/Files/Storage/DAV.php 59.45% <0%> (-21.64%) 0 <0> (ø)
apps/updatenotification/templates/admin.php
lib/private/Encryption/Keys/Storage.php
lib/private/App/CodeChecker/NodeVisitor.php
lib/private/RedisFactory.php
... and 1104 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 45046f3...686aa34. Read the comment docs.

@phil-davis phil-davis force-pushed the stable10-add-phpstan branch 2 times, most recently from 645b3d7 to b42a0e9 Compare July 7, 2019 15:19
@phil-davis phil-davis mentioned this pull request Jul 7, 2019
10 tasks
@phil-davis phil-davis marked this pull request as ready for review July 8, 2019 00:31
@@ -9,6 +9,7 @@
/build/composer.phar
/build/dist
/build/phan.phar
/build/phpstan.phar*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this comes from the backport.
Similar to /build/phan.phar above it. these files should not even appear in the build directory these days - the tools are in vendor-bin

But we can remove these later. For now, this gets stable10 matching master

@@ -78,7 +78,7 @@ public function getStatus() {
public function getPrivateKey() {
$key = $this->session->get('privateKey');
if ($key === null) {
throw new Exceptions\PrivateKeyMissingException('please try to log-out and log-in again', 0);
throw new Exceptions\PrivateKeyMissingException('please try to log-out and log-in again');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit weird, but it happens in other places also - the first parameter is supposed to be the "text" version of the user name. Whatever text is passed ends up getting into the text of the exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is encryption app code - so was not being analyzed by phpstan in master because it does not exist in master

@@ -26,6 +26,8 @@

class InvalidStorage extends FailedStorage {
public function __construct($params) {
$params['exception'] = new StorageNotAvailableException();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

php (and phpstan) wants the constructor to have a $params arg like FailedStorage
But then phpstan complains that $params is not used.
So this code uses it ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mystery is that in master the constructor has no parameters, and phpstan does not complain in master ???

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 for answer: #32051 (comment)

if (!\is_array($arguments)) {
$arguments = [];
}
$arguments['datadir'] = \OC::$server->getTempManager()->getTemporaryFolder();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

phpstan complained about unused $arguments - so this code uses $arguments

@@ -61,7 +61,7 @@ public function __construct(ControllerMethodReflector $reflector,
public function beforeController($controller, $methodName) {
if (!$this->reflector->hasAnnotation('NoSubadminRequired')) {
if (!$this->isSubAdmin) {
throw new NotAdminException('Logged in user must be a subadmin');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NotAdminException does not accepts any parameter. And it inherits from a parent that has no parameter.
I made a new NotSubadminException which can have this text.
Is that the reasonable thing to do?

Copy link
Contributor Author

@phil-davis phil-davis Jul 8, 2019

Choose a reason for hiding this comment

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

This code went to the user_management app and disappeared from core master in core PR #30960
So that is why phpstan did not notice it in core master
The code in the user_management app has this same "feature"

@phil-davis phil-davis force-pushed the stable10-add-phpstan branch from b42a0e9 to 8559248 Compare July 8, 2019 06:13
@micbar
Copy link
Contributor

micbar commented Jul 8, 2019

Great! Passes CI

@phil-davis
Copy link
Contributor Author

Great! Passes CI

yes, I fought with that for a bit - there s a list of small commits in this PR that are extra to what happened in master. I am currently convincing myself about why master passes without those. One of the obvious reasons is that encryption is not in master.

phpstan.neon Outdated
@@ -22,12 +24,15 @@ parameters:
- %currentWorkingDirectory%/apps/*/appinfo/routes.php
- %currentWorkingDirectory%/apps/*/composer/*
- %currentWorkingDirectory%/apps/*/3rdparty/*
- %currentWorkingDirectory%/apps/files/appinfo/update.php
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because apps/files/appinfo/update.php was deleted from master by #33209 so it never had to be considered in the master PHPstan.

The code is not a class, it is just some old script. It gives:

 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  Line   apps/files/appinfo/update.php                                                                                                   
 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  52     Function owncloud_reset_encrypted_flag not found while trying to analyse it - autoloading is probably not configured properly.  
  72     Function owncloud_reset_encrypted_flag not found.                                                                               
  79     Function owncloud_reset_encrypted_flag not found.                                                                               
 ------ -------------------------------------------------------------------------------------------------------------------------------- 

and I couldn't work out how to "autoload" it. Seems not worth more time, so ignore it, and maybe delete it in #35781

@@ -78,7 +78,7 @@ public function getStatus() {
public function getPrivateKey() {
$key = $this->session->get('privateKey');
if ($key === null) {
throw new Exceptions\PrivateKeyMissingException('please try to log-out and log-in again', 0);
throw new Exceptions\PrivateKeyMissingException('please try to log-out and log-in again');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is encryption app code - so was not being analyzed by phpstan in master because it does not exist in master

/**
* @var string
*/
private $id;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole file does not exist any more in master so that is why phpstan did not report about it in master

@phil-davis phil-davis force-pushed the stable10-add-phpstan branch from be69acd to 28d8ccf Compare July 8, 2019 23:47
@phil-davis phil-davis force-pushed the stable10-add-phpstan branch from 28d8ccf to c1b5129 Compare July 8, 2019 23:53
@phil-davis phil-davis force-pushed the stable10-add-phpstan branch from c1b5129 to 1b368f7 Compare July 8, 2019 23:54
@phil-davis
Copy link
Contributor Author

@DeepDiver1975 @micbar @patrickjahns I don't see anything more that I can tidy up here.
It would be nice to fix these things in stable10 and also get phpstan running.

Please review.

@DeepDiver1975 DeepDiver1975 merged commit 2d2dbc1 into stable10 Jul 10, 2019
@delete-merged-branch delete-merged-branch bot deleted the stable10-add-phpstan branch July 10, 2019 13:45
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.

4 participants