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

Improvements and fixes #19

Closed

Conversation

ondrejmirtes
Copy link
Contributor

@ondrejmirtes ondrejmirtes commented Jul 23, 2018

Hi,
I'm sending a few improvements, including implementation of @lcobucci's failing test case concerning prophets in class property. It now depends on dev version of PHPStan but after you test it and tell me it's okay, I can release the change.

FYI @Jean85 this commit 80f0f11 fixes your code upgrade to 0.10 - it was a mistake to return TrivialParametersAcceptor because it disabled all checks on the related object - it didn't see MethodProphecy return type but mixed.

@ondrejmirtes ondrejmirtes force-pushed the allow-using-attributes branch from 17a4a0d to 80f0f11 Compare July 23, 2018 19:12
@ondrejmirtes
Copy link
Contributor Author

ping @lcobucci @Jean85 in case the edited comment mentions do not reach you

@lcobucci
Copy link
Contributor

@ondrejmirtes I'll review it in a bit and let you know. Thanks!

@ondrejmirtes
Copy link
Contributor Author

I just realized that although a working proof of concept, the approach of extending TypeNodeResolver isn't viable in the longterm. Because multiple extensions extending it would clash and they wouldn't be usable all at the same time. I'll need to rework it with some sort of extension system. Stay tuned :)

@Jean85
Copy link
Contributor

Jean85 commented Jul 23, 2018

Thanks @ondrejmirtes! I have to admit that my prev PR was done by trial & error, so I was expecting some mistakes in there...

@lcobucci
Copy link
Contributor

@ondrejmirtes I was testing it locally in my project and it didn't really work (lots of Call to an undefined method $CLASSNAME::reveal()). Will do more tests tomorrow

@ondrejmirtes
Copy link
Contributor Author

ondrejmirtes commented Jul 24, 2018 via email

@lcobucci
Copy link
Contributor

@ondrejmirtes my bad, I didn't read your DM when I was doing the tests.

Apart from having to remove the cache all the time, it works fine for most cases. The one that didn't work was this:

final class BlahTest
{
    /** @var MyClass[]|ObjectProphecy[] */
    private $prophecies;

   // same setup as before but in an array instead...
}

This is an edge-case that doesn't need to be supported IMO, I can just reorganise the tests.

Thanks for your help!

Copy link
Contributor

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

Some some suggestions, thanks again @ondrejmirtes

@@ -12,8 +12,10 @@
"php": "^7.1",
"phpspec/prophecy": "^1.7",
"phpunit/phpunit": "^6.0||^7.0",
"phpstan/phpstan": "^0.10"
"phpstan/phpstan": "^0.10.3"
Copy link
Contributor

@lcobucci lcobucci Jul 24, 2018

Choose a reason for hiding this comment

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

I'd say that using ^0.10.3@dev would be more appropriated for testing, just to avoid issues with other deps.


protected function resolveUnionTypeNode(UnionTypeNode $typeNode, NameScope $nameScope): Type
{
if (count($typeNode->types) === 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can refactor this a bit to make things a bit more readable, my suggestion:

protected function resolveUnionTypeNode(UnionTypeNode $typeNode, NameScope $nameScope): Type
{
    if (count($typeNode->types) !== 2) {
        return parent::resolveUnionTypeNode($typeNode, $nameScope);
    }

    $objectProphecy = $this->getObjectProphecy($typeNode->types[0], $typeNode->types[1], $nameScope);

    return $objectProphecy ?? parent::resolveUnionTypeNode($typeNode, $nameScope);
}

private function getObjectProphecy(
    TypeNode $argumentOne,
    TypeNode $argumentTwo,
    NameScope $nameScope
): ?ObjectProphecyType {
    $typeOne = $this->resolve($argumentOne, $nameScope);
    $typeTwo = $this->resolve($argumentTwo, $nameScope);

    if (! $typeOne instanceof TypeWithClassName || ! $typeTwo instanceof TypeWithClassName) {
        return null;
    }

    if ($typeOne->getClassName() === ObjectProphecy::class) {
        return new ObjectProphecyType($typeTwo->getClassName());
    }

    if ($typeTwo->getClassName() === ObjectProphecy::class) {
        return new ObjectProphecyType($typeOne->getClassName());
    }

    return null;
}

use PHPStan\Type\TypeWithClassName;
use Prophecy\Prophecy\ObjectProphecy;

class TypeNodeResolver extends \PHPStan\PhpDoc\TypeNodeResolver
Copy link
Contributor

Choose a reason for hiding this comment

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

This class could be final

@ondrejmirtes ondrejmirtes force-pushed the allow-using-attributes branch from 80f0f11 to 14e004a Compare July 26, 2018 16:54
@ondrejmirtes
Copy link
Contributor Author

Commit updated with the latest (and hopefully final) extension API: 3953120

Feel free to refactor it, in my opinion the current code is fine 😊

@lcobucci
Copy link
Contributor

Commit updated with the latest (and hopefully final) extension API: 3953120

@ondrejmirtes it worked fine for me. Did you fix the cache handling issue? I had to manually clean it...

Feel free to refactor it, in my opinion the current code is fine 😊

That's up to @Jan0707, my suggestion was just to reduce to cyclomatic complexity of TypeNodeResolverExtension#resolve(), which is quite high IMO.

@ondrejmirtes
Copy link
Contributor Author

ondrejmirtes commented Jul 27, 2018 via email

@lcobucci
Copy link
Contributor

@ondrejmirtes if I run phpstan twice (with the extension enabled) the first time (clean cache) passes, the sencond doesn't.

@lcobucci
Copy link
Contributor

lcobucci commented Jul 27, 2018

The errors are related to the reveal() call (always resolving to object):

Full list
------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/Authentication/AccountInjectorTest.php                                                                                                                                        
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  47     Parameter #3 $arrayTransformer of method Usabilla\SearchApi\Tests\Unit\Authentication\AccountInjectorTest::injectData() expects JMS\Serializer\ArrayTransformerInterface, object given.  
  61     Parameter #3 $arrayTransformer of method Usabilla\SearchApi\Tests\Unit\Authentication\AccountInjectorTest::injectData() expects JMS\Serializer\ArrayTransformerInterface, object given.  
  75     Parameter #3 $arrayTransformer of method Usabilla\SearchApi\Tests\Unit\Authentication\AccountInjectorTest::injectData() expects JMS\Serializer\ArrayTransformerInterface, object given.  
  90     Parameter #3 $arrayTransformer of method Usabilla\SearchApi\Tests\Unit\Authentication\AccountInjectorTest::injectData() expects JMS\Serializer\ArrayTransformerInterface, object given.  
  113    Parameter #3 $arrayTransformer of method Usabilla\SearchApi\Tests\Unit\Authentication\AccountInjectorTest::injectData() expects JMS\Serializer\ArrayTransformerInterface, object given.  
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/Authorization/AuthorizationMiddlewareTest.php                                                                                                            
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  56     Parameter #2 $handler of method Usabilla\SearchApi\Authorization\AuthorizationMiddleware::process() expects Psr\Http\Server\RequestHandlerInterface, object given.  
  68     Parameter #2 $handler of method Usabilla\SearchApi\Authorization\AuthorizationMiddleware::process() expects Psr\Http\Server\RequestHandlerInterface, object given.  
  89     Parameter #2 $handler of method Usabilla\SearchApi\Authorization\AuthorizationMiddleware::process() expects Psr\Http\Server\RequestHandlerInterface, object given.  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/FeedbackIngestion/ConsumeCommandTest.php                                                                                                      
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 
  66     Parameter #1 $input of method Symfony\Component\Console\Command\Command::run() expects Symfony\Component\Console\Input\InputInterface, object given.     
  66     Parameter #2 $output of method Symfony\Component\Console\Command\Command::run() expects Symfony\Component\Console\Output\OutputInterface, object given.  
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/FeedbackIngestion/Feedback/Migration/MigrateCommandTest.php                                                                                   
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 
  59     Parameter #1 $input of method Symfony\Component\Console\Command\Command::run() expects Symfony\Component\Console\Input\InputInterface, object given.     
  59     Parameter #2 $output of method Symfony\Component\Console\Command\Command::run() expects Symfony\Component\Console\Output\OutputInterface, object given.  
  72     Parameter #1 $input of method Symfony\Component\Console\Command\Command::run() expects Symfony\Component\Console\Input\InputInterface, object given.     
  72     Parameter #2 $output of method Symfony\Component\Console\Command\Command::run() expects Symfony\Component\Console\Output\OutputInterface, object given.  
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/AppIdTokenTest.php                                                                                                                                          
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\AppIdToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                 
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/AppNameTokenTest.php                                                                                                                                          
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\AppNameToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                   
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/AppVersionTokenTest.php                                                                                                                                          
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\AppVersionToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/BrowserNameTokenTest.php                                                                                                                                   
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\BrowserNameToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder,  
         object given.                                                                                                                                                                                         
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/ChannelNameTokenTest.php                                                                                                                                   
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\ChannelNameToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder,  
         object given.                                                                                                                                                                                         
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/CompleteTokenTest.php                                                                                                                                  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  46     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\CompleteToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\BoolTokenBuilder, object given.  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/ContainerIdTokenTest.php                                                                                                                                   
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\ContainerIdToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder,  
         object given.                                                                                                                                                                                         
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/CreatedAtTokenTest.php                                                                                                                                       
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  59     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\CreatedAtToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\DateRangeTokenBuilder, object given.  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/DeviceManufacturerTokenTest.php                                                     
 ------ ------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\DeviceManufacturerToken constructor expects  
         Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object given.                                    
 ------ ------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/DeviceProductTokenTest.php                                                                                                                                   
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\DeviceProductToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder,  
         object given.                                                                                                                                                                                           
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/DeviceTypeTokenTest.php                                                                                                                                          
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\DeviceTypeToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/FormIdTokenTest.php                                                                                                                                          
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  64     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\FormIdToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/FormStructureVersionTokenTest.php                                                                                                                            
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  61     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\FormStructureVersionToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\NumericRangeTokenBuilder,  
         object given.                                                                                                                                                                                           
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/IdTokenTest.php                                                                                                                                                 
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  64     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\IdToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object given.  
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/IndustryTokenTest.php                                                                                                                                          
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\IndustryToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                    
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/PlatformDisplayNameTokenTest.php                                                     
 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\PlatformDisplayNameToken constructor expects  
         Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object given.                                     
 ------ -------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/PlatformNameTokenTest.php                                                                                                                                   
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\PlatformNameToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder,  
         object given.                                                                                                                                                                                          
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/ReceivedAtTokenTest.php                                                                                                                                       
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  59     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\ReceivedAtToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\DateRangeTokenBuilder, object given.  
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/ScriptIdTokenTest.php                                                                                                                                          
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\ScriptIdToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                    
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/StatusTokenTest.php                                                                                                                                          
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\StatusToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/Field/WidgetIdTokenTest.php                                                                                                                                          
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  57     Parameter #1 $builder of class Usabilla\SearchApi\QueryBuilding\FilterToken\Field\WidgetIdToken constructor expects Usabilla\SearchApi\QueryBuilding\FilterToken\SinglePropertyTermsTokenBuilder, object  
         given.                                                                                                                                                                                                    
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/Unit/QueryBuilding/FilterToken/TokenBuilder/TokenBuilderTest.php                                                                                                                                    
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  26     Parameter #1 $validator of class class@anonymous/tests/Unit/QueryBuilding/FilterToken/TokenBuilder/TokenBuilderTest.php:26 constructor expects Symfony\Component\Validator\Validator\ValidatorInterface,  
         object given.                                                                                                                                                                                             
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

@ondrejmirtes
Copy link
Contributor Author

@lcobucci That's really weird behaviour that I didn't replicate in my testing. Can you debug what's going on? Inside the TypeNodeResolver where the extensions are called (and also possibly inside the getCacheKey method).

@lcobucci
Copy link
Contributor

@ondrejmirtes sure, I'll do it tomorrow 👍

@lcobucci
Copy link
Contributor

@ondrejmirtes it seems that PhpDocStringResolver#resolve() is not being called when the cache exists.

@ondrejmirtes
Copy link
Contributor Author

@lcobucci Yes, that's what the cache is for 😀 The correct stuff should be already cached in FileTypeMapper (the getCacheKey() method is always called).

@lcobucci
Copy link
Contributor

@ondrejmirtes exactly, FileTypeMapper#getResolvedPhpDocMap() bypasses the extensions if there's something in the cache. That makes me wonder if the cache is being generated properly... I mean, the extensions' result should be stored as well, right?

@lcobucci
Copy link
Contributor

@ondrejmirtes the result of TypeNodeResolver#getCacheKey() is correct (always v46-prophecy-v1-phpunit-v1). So I'd say that the cache data is wrong...

@ondrejmirtes
Copy link
Contributor Author

For the cache key v46-prophecy-v1-phpunit-v1 the data should have all the extensions influences already projected. When the cache key changes (an extension gets registered/unregistered/updated), they are all called again and the new data (including the changes from the extensions) get saved again.

@ondrejmirtes
Copy link
Contributor Author

So the question is - what gets actually cached under the cache key v46-prophecy-v1-phpunit-v1 and why it's wrong...

@lcobucci
Copy link
Contributor

@ondrejmirtes I just saw that the map is indeed the same (regardless if fetched from cache or from doc blocks)

@lcobucci
Copy link
Contributor

The funny thing is that the call $calledOnType = $scope->getType($methodCall->var); in ObjectProphecyRevealDynamicReturnTypeExtension#getTypeFromMethodCall() returns JanGregor\Prophecy\Type\ObjectProphecyType when it's not cached and PHPStan\Type\ObjectType when it is.

@ondrejmirtes
Copy link
Contributor Author

That's super-weird, please investigate more 😊

@lcobucci
Copy link
Contributor

lcobucci commented Aug 1, 2018

@ondrejmirtes I don't have access to the repo anymore, @rdohms could you please take a look at this?

@ondrejmirtes ondrejmirtes force-pushed the allow-using-attributes branch from 14e004a to 1852454 Compare August 12, 2018 16:28
@ondrejmirtes
Copy link
Contributor Author

I just released stable PHPStan 0.10.3 (I'm gonna tweet about it tommorrow) so I updated this PR to use this version. I wasn't able to reproduce the cache problem so we'll see if someone else has more "luck" 😊

@rdohms
Copy link

rdohms commented Nov 16, 2018

so, what can I do to help this one along? do we still have to dive into the cache issue?

@Jan0707
Copy link
Owner

Jan0707 commented Nov 21, 2018

This needs to have the conflicts resolved - then we should be good to go.

@rdohms
Copy link

rdohms commented Nov 24, 2018

I've got it rebased, i'm just trying to figure out how to get that code into this PR 😝

@rdohms rdohms mentioned this pull request Nov 26, 2018
@Jan0707
Copy link
Owner

Jan0707 commented Jan 21, 2019

Closed in favor of #31

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.

6 participants