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

abstract method reported but method is implemented in parent class (1.7.5 and 1.7.6) #7360

Closed
phil-davis opened this issue May 31, 2022 · 10 comments

Comments

@phil-davis
Copy link

phil-davis commented May 31, 2022

Bug report

With phpstan 1.7.5 and 1.7.6 I now get a new error reported:

After doing phpstan clear-result-cache and a full run:

php -d zend.enable_gc=0 vendor-bin/phpstan/vendor/bin/phpstan analyse --memory-limit=2G --configuration=./phpstan.neon --level=0 apps core settings lib/private lib/public ocs ocs-provider
 1466/1466  100%

 ------ ------------------------------------------------------------------------------------------------------------- 
  Line   lib/private/Files/Cache/HomeCache.php                                                                        
 ------ ------------------------------------------------------------------------------------------------------------- 
  32     Non-abstract class OC\Files\Cache\HomeCache contains abstract method put() from class OC\Files\Cache\Cache.  
 ------ ------------------------------------------------------------------------------------------------------------- 
 [ERROR] Found 1 error                                                                                                  
make: *** [Makefile:237: test-php-phpstan] Error 1

That is a new error. But:
https://github.com/owncloud/core/blob/master/lib/private/Files/Cache/HomeCache.php has no implementation of function put

class HomeCache extends Cache - https://github.com/owncloud/core/blob/master/lib/private/Files/Cache/Cache.php and that does have a real implementation of function put:

	public function put($file, array $data) {
		if (($id = $this->getId($file)) > -1) {
			$this->update($id, $data);
			return $id;
		} else {
			return $this->insert($file, $data);
		}
	}

class Cache implements ICache - https://github.com/owncloud/core/blob/master/lib/public/Files/Cache/ICache.php
And that has just the function definition:

	public function put($file, array $data);

Am I missing something? That inheritance should be OK?

Code snippet that reproduces the problem

Expected output

phpstan passes

Did PHPStan help you today? Did it make you happy in any way?

@mergeable
Copy link

mergeable bot commented May 31, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@phil-davis
Copy link
Author

Sorry to report a new thing. I need to think now for a few minutes. Maybe I am wrong and I have to also implement put in HomeCache - but I don't see why, since put has a code implementation in Cache

@phil-davis
Copy link
Author

https://drone.owncloud.com/owncloud/core/35901/6/8

------ ----------------------------------------------------------------------- 
  Line   apps/files_sharing/lib/External/Cache.php                              
 ------ ----------------------------------------------------------------------- 
  26     Non-abstract class OCA\Files_Sharing\External\Cache contains abstract  
         method put() from class OC\Files\Cache\Cache.                          
 ------ ----------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   lib/private/Files/Cache/HomeCache.php                                 
 ------ ---------------------------------------------------------------------- 
  32     Non-abstract class OC\Files\Cache\HomeCache contains abstract method  
         put() from class OC\Files\Cache\Cache.                                
 ------ ---------------------------------------------------------------------- 
 [ERROR] Found 2 errors                                                         

Hmmm - the CI run on drone finds this error in 2 places. But my local run only finds it once. Now I need to dig into why that difference is happening.

@phil-davis phil-davis changed the title abstract method reported but method is implemented in parent class (1.7.6) abstract method reported but method is implemented in parent class (1.7.5) May 31, 2022
@phil-davis phil-davis changed the title abstract method reported but method is implemented in parent class (1.7.5) abstract method reported but method is implemented in parent class (1.7.5 and 1.7.6) May 31, 2022
@phil-davis
Copy link
Author

https://drone.owncloud.com/owncloud/core/35903/6/8

The same 2 errors are reported in CI by phpstan 1.7.5

------ ----------------------------------------------------------------------- 
  Line   apps/files_sharing/lib/External/Cache.php                              
 ------ ----------------------------------------------------------------------- 
  26     Non-abstract class OCA\Files_Sharing\External\Cache contains abstract  
         method put() from class OC\Files\Cache\Cache.                          
 ------ ----------------------------------------------------------------------- 
 ------ ---------------------------------------------------------------------- 
  Line   lib/private/Files/Cache/HomeCache.php                                 
 ------ ---------------------------------------------------------------------- 
  32     Non-abstract class OC\Files\Cache\HomeCache contains abstract method  
         put() from class OC\Files\Cache\Cache.                                
 ------ ---------------------------------------------------------------------- 
 [ERROR] Found 2 errors                                                         

@ondrejmirtes
Copy link
Member

I was able to make your project work locally. This is my output:

 ------ -----------------------------------------------------------------------------------------------
  Line   apps/files_sharing/lib/External/Cache.php
 ------ -----------------------------------------------------------------------------------------------
  26     Non-abstract class OCA\Files_Sharing\External\Cache contains abstract method put() from class
         OC\Files\Cache\Cache.
 ------ -----------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------
  Line   lib/private/Files/Cache/HomeCache.php
 ------ ---------------------------------------------------------------------------------------
  32     Non-abstract class OC\Files\Cache\HomeCache contains abstract method put() from class
         OC\Files\Cache\Cache.
 ------ ---------------------------------------------------------------------------------------

 -- ----------------------------------------------------------------------------------------------------------
     Error
 -- ----------------------------------------------------------------------------------------------------------
     Child process error (exit code 255): PHP Fatal error:  require_once(): Failed opening required
     'Console/Getopt.php'
     (include_path='/Users/ondrej/Downloads/owncloud-core/apps:/Users/ondrej/Downloads/owncloud-core/apps-ext
     ernal') in /Users/ondrej/Downloads/owncloud-core/lib/composer/pear/pear-core-minimal/src/system.php on
     line 20

     Child process error (exit code 255): PHP Fatal error:  Cannot declare class
     OCA\Files_Sharing\DeleteOrphanedSharesJob, because the name is already in use in
     /Users/ondrej/Downloads/owncloud-core/apps/files_sharing/lib/deleteorphanedsharesjob.php on line 31

 -- ----------------------------------------------------------------------------------------------------------

Can you tell me how to get rid of the 'Console/Getopt.php' error? Looks like I'm missing something in my include path...

Abou the abstract put method - looks actually like a BetterReflection bug, gonna look into it, thanks!

@phil-davis
Copy link
Author

phil-davis commented May 31, 2022

Can you tell me how to get rid of the 'Console/Getopt.php' error? Looks like I'm missing something in my include path

That all occurs in dependency pear/pear-core-minimal. After doing make on my system, I have:
lib/composer/composer/autoload_classmap.php with:

`    'Console_Getopt' => $vendorDir . '/pear/console_getopt/Console/Getopt.php',

lib/composer/composer/autoload_static.php with:

        'Console_Getopt' => __DIR__ . '/..' . '/pear/console_getopt/Console/Getopt.php',

And lib/composer/pear/pear-core-minimal/src/System.php has:

require_once 'Console/Getopt.php';

And I have `lib/composer/pear/console_getopt/Console/Getopt.php with:

class Console_Getopt
...

It is all internal to the "pear" library. I wonder how that could get confused - I don't get the error.

The class is not Console\Getopt. So the class name and the path to it do not match. I wonder if that is causing a problem?

@ondrejmirtes
Copy link
Member

I have a solution phpstan/phpstan-src#1373

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#1373

Please test PHPStan 1.7.7 once I release it later today.

@phil-davis
Copy link
Author

@github-actions
Copy link

github-actions bot commented Jul 2, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants