It seems like you code against a concrete implementation and not the interface ONGR\ElasticsearchDSL\BuilderInterface as the method getName() does only exist in the following implementations of said interface: ONGR\ElasticsearchDSL\Ag...ion\AbstractAggregation, ONGR\ElasticsearchDSL\Ag...acencyMatrixAggregation, ONGR\ElasticsearchDSL\Ag...ateHistogramAggregation, ONGR\ElasticsearchDSL\Ag...ing\ChildrenAggregation, ONGR\ElasticsearchDSL\Ag...ng\CompositeAggregation, ONGR\ElasticsearchDSL\Ag...ateHistogramAggregation, ONGR\ElasticsearchDSL\Ag...ng\DateRangeAggregation, ONGR\ElasticsearchDSL\Ag...ifiedSamplerAggregation, ONGR\ElasticsearchDSL\Ag...eting\FilterAggregation, ONGR\ElasticsearchDSL\Ag...ting\FiltersAggregation, ONGR\ElasticsearchDSL\Ag...\GeoDistanceAggregation, ONGR\ElasticsearchDSL\Ag...\GeoHashGridAggregation, ONGR\ElasticsearchDSL\Ag...eting\GlobalAggregation, ONGR\ElasticsearchDSL\Ag...ng\HistogramAggregation, ONGR\ElasticsearchDSL\Ag...ng\Ipv4RangeAggregation, ONGR\ElasticsearchDSL\Ag...ting\MissingAggregation, ONGR\ElasticsearchDSL\Ag...eting\NestedAggregation, ONGR\ElasticsearchDSL\Ag...keting\RangeAggregation, ONGR\ElasticsearchDSL\Ag...everseNestedAggregation, ONGR\ElasticsearchDSL\Ag...ting\SamplerAggregation, ONGR\ElasticsearchDSL\Ag...ificantTermsAggregation, ONGR\ElasticsearchDSL\Ag...nificantTextAggregation, ONGR\ElasticsearchDSL\Ag...keting\TermsAggregation, ONGR\ElasticsearchDSL\Ag...n\Matrix\MaxAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\AvgAggregation, ONGR\ElasticsearchDSL\Ag...\CardinalityAggregation, ONGR\ElasticsearchDSL\Ag...xtendedStatsAggregation, ONGR\ElasticsearchDSL\Ag...ic\GeoBoundsAggregation, ONGR\ElasticsearchDSL\Ag...\GeoCentroidAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\MaxAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\MinAggregation, ONGR\ElasticsearchDSL\Ag...centileRanksAggregation, ONGR\ElasticsearchDSL\Ag...\PercentilesAggregation, ONGR\ElasticsearchDSL\Ag...riptedMetricAggregation, ONGR\ElasticsearchDSL\Ag...Metric\StatsAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\SumAggregation, ONGR\ElasticsearchDSL\Ag...tric\TopHitsAggregation, ONGR\ElasticsearchDSL\Ag...c\ValueCountAggregation, ONGR\ElasticsearchDSL\Ag...ractPipelineAggregation, ONGR\ElasticsearchDSL\Ag...ne\AvgBucketAggregation, ONGR\ElasticsearchDSL\Ag...BucketScriptAggregation, ONGR\ElasticsearchDSL\Ag...cketSelectorAggregation, ONGR\ElasticsearchDSL\Ag...e\BucketSortAggregation, ONGR\ElasticsearchDSL\Ag...umulativeSumAggregation, ONGR\ElasticsearchDSL\Ag...e\DerivativeAggregation, ONGR\ElasticsearchDSL\Ag...dStatsBucketAggregation, ONGR\ElasticsearchDSL\Ag...ne\MaxBucketAggregation, ONGR\ElasticsearchDSL\Ag...ne\MinBucketAggregation, ONGR\ElasticsearchDSL\Ag...ovingAverageAggregation, ONGR\ElasticsearchDSL\Ag...vingFunctionAggregation, ONGR\ElasticsearchDSL\Ag...ntilesBucketAggregation, ONGR\ElasticsearchDSL\Ag...DifferencingAggregation, ONGR\ElasticsearchDSL\Ag...\StatsBucketAggregation, ONGR\ElasticsearchDSL\Ag...ne\SumBucketAggregation, ONGR\ElasticsearchDSL\InnerHit\NestedInnerHit, ONGR\ElasticsearchDSL\InnerHit\ParentInnerHit, ONGR\ElasticsearchDSL\Suggest\Suggest.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface ONGR\ElasticsearchDSL\BuilderInterface as the method getArray() does only exist in the following implementations of said interface: ONGR\ElasticsearchDSL\Ag...ion\AbstractAggregation, ONGR\ElasticsearchDSL\Ag...acencyMatrixAggregation, ONGR\ElasticsearchDSL\Ag...ateHistogramAggregation, ONGR\ElasticsearchDSL\Ag...ing\ChildrenAggregation, ONGR\ElasticsearchDSL\Ag...ng\CompositeAggregation, ONGR\ElasticsearchDSL\Ag...ateHistogramAggregation, ONGR\ElasticsearchDSL\Ag...ng\DateRangeAggregation, ONGR\ElasticsearchDSL\Ag...ifiedSamplerAggregation, ONGR\ElasticsearchDSL\Ag...eting\FilterAggregation, ONGR\ElasticsearchDSL\Ag...ting\FiltersAggregation, ONGR\ElasticsearchDSL\Ag...\GeoDistanceAggregation, ONGR\ElasticsearchDSL\Ag...\GeoHashGridAggregation, ONGR\ElasticsearchDSL\Ag...eting\GlobalAggregation, ONGR\ElasticsearchDSL\Ag...ng\HistogramAggregation, ONGR\ElasticsearchDSL\Ag...ng\Ipv4RangeAggregation, ONGR\ElasticsearchDSL\Ag...ting\MissingAggregation, ONGR\ElasticsearchDSL\Ag...eting\NestedAggregation, ONGR\ElasticsearchDSL\Ag...keting\RangeAggregation, ONGR\ElasticsearchDSL\Ag...everseNestedAggregation, ONGR\ElasticsearchDSL\Ag...ting\SamplerAggregation, ONGR\ElasticsearchDSL\Ag...ificantTermsAggregation, ONGR\ElasticsearchDSL\Ag...nificantTextAggregation, ONGR\ElasticsearchDSL\Ag...keting\TermsAggregation, ONGR\ElasticsearchDSL\Ag...n\Matrix\MaxAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\AvgAggregation, ONGR\ElasticsearchDSL\Ag...\CardinalityAggregation, ONGR\ElasticsearchDSL\Ag...xtendedStatsAggregation, ONGR\ElasticsearchDSL\Ag...ic\GeoBoundsAggregation, ONGR\ElasticsearchDSL\Ag...\GeoCentroidAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\MaxAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\MinAggregation, ONGR\ElasticsearchDSL\Ag...centileRanksAggregation, ONGR\ElasticsearchDSL\Ag...\PercentilesAggregation, ONGR\ElasticsearchDSL\Ag...riptedMetricAggregation, ONGR\ElasticsearchDSL\Ag...Metric\StatsAggregation, ONGR\ElasticsearchDSL\Ag...n\Metric\SumAggregation, ONGR\ElasticsearchDSL\Ag...tric\TopHitsAggregation, ONGR\ElasticsearchDSL\Ag...c\ValueCountAggregation, ONGR\ElasticsearchDSL\Ag...ractPipelineAggregation, ONGR\ElasticsearchDSL\Ag...ne\AvgBucketAggregation, ONGR\ElasticsearchDSL\Ag...BucketScriptAggregation, ONGR\ElasticsearchDSL\Ag...cketSelectorAggregation, ONGR\ElasticsearchDSL\Ag...e\BucketSortAggregation, ONGR\ElasticsearchDSL\Ag...umulativeSumAggregation, ONGR\ElasticsearchDSL\Ag...e\DerivativeAggregation, ONGR\ElasticsearchDSL\Ag...dStatsBucketAggregation, ONGR\ElasticsearchDSL\Ag...ne\MaxBucketAggregation, ONGR\ElasticsearchDSL\Ag...ne\MinBucketAggregation, ONGR\ElasticsearchDSL\Ag...ovingAverageAggregation, ONGR\ElasticsearchDSL\Ag...vingFunctionAggregation, ONGR\ElasticsearchDSL\Ag...ntilesBucketAggregation, ONGR\ElasticsearchDSL\Ag...DifferencingAggregation, ONGR\ElasticsearchDSL\Ag...\StatsBucketAggregation, ONGR\ElasticsearchDSL\Ag...ne\SumBucketAggregation.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: