phpsa icon indicating copy to clipboard operation
phpsa copied to clipboard

ScopePointer ::__construct and ::getObject not aligning

Open DannyvdSluijs opened this issue 9 years ago • 3 comments

When doing the UT for #170 I cam across the ScopePointer which takes in any parameter into the constructor (string, int, object etc.) And based on the @return tag for the getObject it should return ClassMethod or FunctionDefinition

https://github.com/ovr/phpsa/blob/master/src/ScopePointer.php#L23 https://github.com/ovr/phpsa/blob/master/src/ScopePointer.php#L51

I guess some type of type checking needs to be added, and an exception should be thrown if not type not permitted.

DannyvdSluijs avatar Oct 05 '16 07:10 DannyvdSluijs

Seems We are having 2 ways how to improve this 1. So I suggest to build a new Interface called like ScopePointerInterface Implement ClassMethod, FunctionDefinition with ScopePointerInterface

Add ScopePointerInterface strict https://github.com/ovr/phpsa/blob/master/src/ScopePointer.php#L23

  1. Check in __construct
  2. is null
  3. is object
  4. is method

If not, lets throw an InvalidArgumentException

ovr avatar Oct 05 '16 07:10 ovr

As we can see AbstractDefinition::getPointer, property ScopePointer::$object can be one of the following: ClassMethod, ClosureDefinition, FunctionDefinition, ReflectionClassMethod, RuntimeClassDefinition, TraitDefinition, ClassDefinition.

So what about this version of ScopePointer? https://github.com/Lexty/phpsa/blob/182-scope-pointer-strict-type/src/ScopePointer.php

Lexty avatar Oct 11 '16 10:10 Lexty

So what about this version of ScopePointer? https://github.com/Lexty/phpsa/blob/182-scope-pointer-strict-type/src/ScopePointer.php

ping @ovr @K-Phoen

ddmler avatar Oct 12 '16 15:10 ddmler