Add phan as static code analyser#31807
Conversation
20a7d77 to
04adc14
Compare
Codecov Report
@@ Coverage Diff @@
## master #31807 +/- ##
===========================================
+ Coverage 63.25% 64.26% +1%
Complexity 18459 18459
===========================================
Files 1158 1097 -61
Lines 69328 62193 -7135
Branches 1261 0 -1261
===========================================
- Hits 43854 39967 -3887
+ Misses 25104 22226 -2878
+ Partials 370 0 -370
Continue to review full report at Codecov.
|
| use OCP\IRequest; | ||
| use OCP\IUserManager; | ||
| use OCP\Share; | ||
| use OCP\Share\IShare; |
There was a problem hiding this comment.
phan was complaining about this missing import:
apps/federatedfilesharing/lib/RequestHandler.php:574 PhanUndeclaredClassMethod Call to method getId from undeclared class \OCA\FederatedFileSharing\IShare (Did you mean interface \Icewind\SMB\IShare)
| * | ||
| * @param string $path | ||
| * @return \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject|bool object | ||
| * @return DataObject | bool object |
There was a problem hiding this comment.
Fixes:
apps/files_external/lib/Lib/Storage/Swift.php:304 PhanUndeclaredClassMethod Call to method getLastModified from undeclared class \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject
apps/files_external/lib/Lib/Storage/Swift.php:310 PhanUndeclaredClassMethod Call to method getMetadata from undeclared class \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject
apps/files_external/lib/Lib/Storage/Swift.php:321 PhanUndeclaredClassMethod Call to method getContentLength from undeclared class \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject
apps/files_external/lib/Lib/Storage/Swift.php:438 PhanUndeclaredClassMethod Call to method saveMetadata from undeclared class \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject
apps/files_external/lib/Lib/Storage/Swift.php:467 PhanUndeclaredClassMethod Call to method copy from undeclared class \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject
apps/files_external/lib/Lib/Storage/Swift.php:482 PhanUndeclaredClassMethod Call to method copy from undeclared class \OpenCloud\OpenStack\ObjectStorage\Resource\DataObject
ad0fbd8 to
f386358
Compare
| // namespace | ||
| const ZSYNC_PROPERTYNAME = '{http://owncloud.org/ns}zsync'; | ||
|
|
||
| /** @var OC\Files\View */ |
There was a problem hiding this comment.
fixes:
[php-phan:L12:73s] apps/dav/lib/Files/ZsyncPlugin.php:42 PhanUndeclaredClassMethod Call to method mkdir from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L13:73s] apps/dav/lib/Files/ZsyncPlugin.php:73 PhanUndeclaredClassMethod Call to method file_exists from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L14:73s] apps/dav/lib/Files/ZsyncPlugin.php:78 PhanUndeclaredClassMethod Call to method getFileInfo from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L15:73s] apps/dav/lib/Files/ZsyncPlugin.php:80 PhanUndeclaredClassMethod Call to method file_exists from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L16:73s] apps/dav/lib/Files/ZsyncPlugin.php:81 PhanUndeclaredClassMethod Call to method file_get_contents from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L17:73s] apps/dav/lib/Files/ZsyncPlugin.php:108 PhanUndeclaredClassMethod Call to method file_exists from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L18:73s] apps/dav/lib/Files/ZsyncPlugin.php:113 PhanUndeclaredClassMethod Call to method getFileInfo from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L19:73s] apps/dav/lib/Files/ZsyncPlugin.php:115 PhanUndeclaredClassMethod Call to method file_exists from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L20:73s] apps/dav/lib/Files/ZsyncPlugin.php:116 PhanUndeclaredClassMethod Call to method unlink from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L21:73s] apps/dav/lib/Files/ZsyncPlugin.php:134 PhanUndeclaredClassMethod Call to method is_file from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L22:73s] apps/dav/lib/Files/ZsyncPlugin.php:137 PhanUndeclaredClassMethod Call to method getFileInfo from undeclared class \OCA\DAV\Files\OC\Files\View
[php-phan:L23:73s] apps/dav/lib/Files/ZsyncPlugin.php:139 PhanUndeclaredClassMethod Call to method file_exists from undeclared class \OCA\DAV\Files\OC\Files\View
f386358 to
1b7c6c7
Compare
| use OCP\Files\StorageNotAvailableException; | ||
| use OCP\Util; | ||
| use Sabre\DAV\Xml\Property\ResourceType; | ||
| use Sabre\HTTP\Client; |
There was a problem hiding this comment.
fixes:
[php-phan:L18:73s] lib/private/Files/Storage/DAV.php:198 PhanUndeclaredClassMethod Call to method propfind from undeclared class \OC\Files\Storage\Client
[php-phan:L19:73s] lib/private/Files/Storage/DAV.php:255 PhanUndeclaredClassMethod Call to method propfind from undeclared class \OC\Files\Storage\Client
[php-phan:L20:73s] lib/private/Files/Storage/DAV.php:421 PhanUndeclaredClassMethod Call to method propfind from undeclared class \OC\Files\Storage\Client
[php-phan:L21:73s] lib/private/Files/Storage/DAV.php:447 PhanUndeclaredClassMethod Call to method proppatch from undeclared class \OC\Files\Storage\Client
[php-phan:L22:73s] lib/private/Files/Storage/DAV.php:449 PhanUndeclaredClassMethod Call to method propfind from undeclared class \OC\Files\Storage\Client
[php-phan:L23:73s] lib/private/Files/Storage/DAV.php:525 PhanUndeclaredClassMethod Call to method request from undeclared class \OC\Files\Storage\Client
[php-phan:L24:73s] lib/private/Files/Storage/DAV.php:557 PhanUndeclaredClassMethod Call to method request from undeclared class \OC\Files\Storage\Client
[php-phan:L25:73s] lib/private/Files/Storage/DAV.php:654 PhanUndeclaredClassMethod Call to method request from undeclared class \OC\Files\Storage\Client
@PVince81 @DeepDiver1975 - this should be the correct client to be parsed right? (at least that's what https://github.com/owncloud/core/blob/92b658a60e6c28ef9dd7594384180e0d73e96660/lib/public/Http/Client/IWebDavClientService.php typehints )
|
Having a stub for a using stub for this is sensible - but I would prefer of having a default theme app ? |
| Reference: http://tools.ietf.org/html/rfc7231#section-4.3.4 | ||
| */ | ||
| throw new Exception\BadRequest('Content-Range on PUT requests are forbidden.'); | ||
| throw new BadRequest('Content-Range on PUT requests are forbidden.'); |
There was a problem hiding this comment.
solves [php-phan:L11:67s] apps/dav/lib/Connector/Sabre/AutorenamePlugin.php:73 PhanUndeclaredClassMethod Call to method __construct from undeclared class \OCA\DAV\Connector\Sabre\Exception\BadRequest
@PVince81 - please check if the intention is the same as back then (found you as sole author of this class)
|
Since we moved encryption app into its own repository - this needs to be addressed somehow @sharidas @PVince81 https://github.com/owncloud/core/blob/master/lib/private/Encryption/Util.php#L123 |
| */ | ||
|
|
||
| use OCA\Files_External\AppInfo\Application; | ||
| use OCP\Files\External\Backend\Backend; |
There was a problem hiding this comment.
fix for
apps/files_external/lib/config.php:54 PhanUndeclaredClassMethod Call to method checkDependencies from undeclared class \Backend (Did you mean class \OCA\DAV\DAV\Sharing\Backend or class \OCA\Files_External\Lib\Backend\Backend)
| \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); | ||
| break; | ||
| case 'dummy': | ||
| /* @phan-suppress-next-line PhanUndeclaredClassMethod */ |
There was a problem hiding this comment.
fixes
lib/private/legacy/user.php:102 PhanUndeclaredClassMethod Call to method __construct from undeclared class \Test\Util\User\Dummy
right now its the right approach - ondering through if a dummy user backend should be provided by an app?
.drone.yml
Outdated
| TEST_SUITE: php-cs-fixer | ||
|
|
||
| php-phan: | ||
| image: owncloudci/php:71_add_phpast |
There was a problem hiding this comment.
this needs to be switched once owncloud-ci/php#61 is merged
|
|
||
| /** | ||
| * @var \Icewind\SMB\IFileInfo[] | ||
| * @var ICache |
There was a problem hiding this comment.
Fix for:
apps/files_external/lib/Lib/Storage/SMB.php:293 PhanNonClassMethodCall Call to method clear on non-class type \Icewind\SMB\IFileInfo[]|array<string,\Icewind\SMB\IFileInfo>|array<string,\Icewind\SMB\Wrapped\FileInfo>
the implementation used is a OC\Cache\CappedMemoryCache -> it implements ICache and I rather propose to typehint the interface and not the implementation
| * @param integer $timestamp when the file was deleted | ||
| * @param IStorage|null $sourceStorage | ||
| * @param bool $forceCopy true to only make a copy of the versions into the trashbin | ||
| * @throws Exceptions\CopyRecursiveException |
There was a problem hiding this comment.
exception was missing from doc block - made phpstorm a little happier
| * @param string $owner owner user id | ||
| * @param string $ownerPath path relative to the owner's home storage | ||
| * @param integer $timestamp when the file was deleted | ||
| * @param IStorage|null $sourceStorage |
There was a problem hiding this comment.
This takes care of
apps/files_trashbin/lib/Trashbin.php:414 PhanNonClassMethodCall Call to method deleteAllFileKeys on non-class type ?mixed
However - it was introduced by this pr #28899 - and it seems to be 🍝 - there is no proper check if the storage provided at this stage is actually an encrypted storage / or inherits an interface. Also no tests were provided with that patch
@PVince81 @sharidas - please shed some light on this code path, as I am very hesitant to simply add this typehint
There was a problem hiding this comment.
as I see there is only a null check, so if not null it assumed it's the IStorage.
this one https://github.com/owncloud/core/pull/28899/files#diff-6425524450ee2e3178dec599f98a6f63R370 has no null check because the value of $copyKeysResult is set in the other block that has the null check. Maybe the static code checker is not able to understand this kind of code path ?
We should probably change the way we wrote this because a human reading this will be confused as well.
There was a problem hiding this comment.
The code analysis tool checks what information is given - if there is no type hinting - or no proper type declaration, it will assume mixed. Which essentially will creep in bugs as developers do not know what values can/should be passed.
As there are not tests that explicitly cover this behavior - it is also not documented - so it is not understandable for humans ( and not for any tool).
So the typehinting assumed is correct right? That at some point later we should move forward with the refactoring - this is however out of scope for this PR
| } | ||
| self::$cache->watch($this->getNameSpace() . $key); | ||
| if ($this->get($key) === $old) { | ||
| /** @phan-suppress-next-line PhanNonClassMethodCall */ |
There was a problem hiding this comment.
adresses:
lib/private/Memcache/Redis.php:142 PhanNonClassMethodCall Call to method exec on non-class type bool
lib/private/Memcache/Redis.php:161 PhanNonClassMethodCall Call to method exec on non-class type bool
suggestions to supress came from phan maintainers directly - phan/phan#1804 - will later look into creating a plugin as suggested
| public function cad($key, $old) { | ||
| self::$cache->watch($this->getNameSpace() . $key); | ||
| if ($this->get($key) === $old) { | ||
| /** @phan-suppress-next-line PhanNonClassMethodCall */ |
There was a problem hiding this comment.
|
Fixing needs input from @PVince81 and @DeepDiver1975 as they're the ones who moved the code to core code in question: https://github.com/owncloud/core/blob/master/lib/private/Files/External/LegacyUtil.php#L196-L214 from my pov - the second catch block is useless - https://github.com/owncloud/core/blob/master/lib/private/Files/External/LegacyUtil.php#L211-L214 - as it catches |
| namespace OC\Share20; | ||
|
|
||
| use OCP\Files\File; | ||
| use OCP\Share\IShare; |
There was a problem hiding this comment.
fixes:
lib/private/Share20/DefaultShareProvider.php:1232 PhanUndeclaredClassMethod Call to method getName from undeclared class \OC\Share20\IShare (Did you mean interface \Icewind\SMB\IShare)
| class AssemblyStreamZsync extends AssemblyStream { | ||
|
|
||
| /** @var array */ | ||
| /** @var IFile */ |
There was a problem hiding this comment.
adresses:
apps/dav/lib/Upload/AssemblyStreamZsync.php:79 PhanNonClassMethodCall Call to method getSize on non-class type array
There was a problem hiding this comment.
This will crash loudly with php7.2 latest :)
There was a problem hiding this comment.
care to elaborate? because of the typehinting? - that shouldn't be a problem - but we can also get phan to run on php7.2 as targeted version
| $multiStatus = $xml->expect('{DAV:}multistatus', $body); | ||
|
|
||
| $result = []; | ||
| /** @phan-suppress-next-line PhanNonClassMethodCall */ |
There was a problem hiding this comment.
this suppresses
apps/dav/lib/CardDAV/SyncService.php:203 PhanNonClassMethodCall Call to method getResponses on non-class type void
apps/dav/lib/CardDAV/SyncService.php:207 PhanNonClassMethodCall Call to method getSyncToken on non-class type void
would require this commit to be fixed sabre-io/xml@3bac738#diff-de76feda74829916defbb14d089c7c08
| $result[$response->getHref()] = $response->getResponseProperties(); | ||
| } | ||
|
|
||
| /** @phan-suppress-next-line PhanNonClassMethodCall */ |
There was a problem hiding this comment.
… normal set hints a bool - but multi wraps it into a pipeline
f3c7ccb to
a479f8a
Compare
|
can we backport this or will it have too big a hit ? @DeepDiver1975 @patrickjahns |
|
@PVince81 Over-time we should gradually increase the strictness of php-phan to have a cleaner + more-stable code base |
|
Agreed. @patrickjahns will you take care (as you are the original submitter) or should I ? |
|
@patrickjahns @PVince81 backport is still outstanding. |
|
I'd love to get it in - but then would need to be done by tonight/tomorrow |
|
I'll backport this |
|
stable10: #32492 |
Description
https://github.com/phan/phan is a static code analysis tool that can help us improve our code basis and help find bugs.
Right now the
.phan/configis very lenient - we should first get it to be ✅ for this lenient definition, merge / introduce it to our code basis and then gradually increase the ruleset to further improve our code base.note: phan is currently introduced as phar - this allows us for backporting it to stable10 - without having dependencie issues, as phan officialy needs to run on php7+ ( however it can analyse code in 7 to be backward compatible to php5.6 )
Motivation and Context
Improve code quality and ownCloud as project
pending fixes
Types of changes
Checklist: