classDeriver
final class Deriver
Public API: explicitly declared with
@visibility public.Derives candidate values repeatedly from one captured set of PHP sources.
$path = tempnam(sys_get_temp_dir(), 'deriver-example-');
file_put_contents($path, '<?php function answer() { return 42; } function other() { return 7; }');
$deriver = \Deriver\Deriver::prepare([$path]);
unlink($path);
$deriver->derive('answer#return')[0]->result // => 42
$deriver->derive('other#return')[0]->result // => 7Methods§
public static function prepare(
list<string> $files,
DeriverConfig|null $configuration = null,
): selfCaptures and parses the selected files without executing application code. Builds reverse indexes for calls, property writes, closure owners and script globals. Function, method and closure bodies are compiled on demand and reused by later queries. The returned instance keeps these contents even if the files later change or disappear.
Parameters
$files | list<string> | Local paths, for example the result of Finder::files() |
$configuration | DeriverConfig|null | Independent language and evaluation settings; null selects the defaults |
Returns
selfThrows
CollectorException If a selected file cannot be collectedParserException If a selected source cannot be parsedResolutionException If a selected source cannot be resolvedInvalidInputException If declarations are incomplete or declarations or evaluator registrations conflictTest cases 56
CliBench::benchPreparecallsCliBench::preparecallsCliBench::prepareWithBranchPruningcallsLaravelBench::benchPreparecallsLaravelBench::preparecallsLaravelBench::prepareWithBranchPruningcallsSymfonyBench::benchPreparecallsSymfonyBench::preparecallsSymfonyBench::prepareWithBranchPruningcallsWebBench::benchPreparecallsWebBench::preparecallsWebBench::prepareWithBranchPruningcallsPhpContext::derivecallsEnvironmentTest::testDeriveIdentifiesEnvironmentContentsAndSourceChangescallsEnvironmentTest::testDeriveKeepsUnspecifiedInputsAndEventsUnresolvedcallsEnvironmentTest::testDeriveUsesVariableAndEnvironmentNamescallsMicroEvaluatorTest::testCallbackFailureReportsTheEvaluatorIdentitycallsMicroEvaluatorTest::testCanReturnAPartialExpressionWithItsDemandedInputcallsMicroEvaluatorTest::testComposesOperandEvaluationWithBuiltInFunctionscallsMicroEvaluatorTest::testConditionalEvaluationDemandsOnlyTheSelectedBranchcallsMicroEvaluatorTest::testDecliningContinuesWithBuiltInAndSourceEvaluationcallsMicroEvaluatorTest::testDisabledStandardEvaluatorsDoNotDisableConfiguredEvaluatorscallsMicroEvaluatorTest::testEvaluatesOnlyDemandedArgumentscallsMicroEvaluatorTest::testEvaluationStateIsFreshForEachQuerycallsMicroEvaluatorTest::testInvalidInputDemandReportsTheEvaluatorIdentitycallsMicroEvaluatorTest::testPriorityAndEvidenceDoNotDependOnRegistrationOrdercallsMicroEvaluatorTest::testRejectsConflictingMicroEvaluatorsDuringPreparationcallsMicroEvaluatorTest::testUsesNamedArgumentsAndLeavesOtherArgumentsUnopenedcallsSelectorQueryTest::testDeriveDoesNotAddAFileNamedOnlyByTheSelectorcallsSelectorQueryTest::testDeriveFindsArgumentsInsideClosurescallsSelectorQueryTest::testDeriveRejectsAnUnknownFormalParametercallsSelectorQueryTest::testDeriveRejectsCallsSharingTheSameStartPositioncallsSelectorQueryTest::testDeriveResolvesRelativePathsAgainstTheWorkingDirectorycallsSelectorQueryTest::testDeriveSelectsArgumentExpressionsWithoutExecutingTheCallcallsSelectorQueryTest::testDeriveSelectsNamespacedReturnsAndFormalParameterOriginscallsSelectorQueryTest::testDeriveUsesByteColumnsWithUtf8AndCrLfSourcecallsSelectorQueryTest::testPreparedRelativeSourcesAndSelectorsKeepTheirOriginalDirectorycallsDeriverTest::testCandidateEvidenceSurvivesTheDerivercallsDeriverTest::testDeriverDoesNotRetainResultscallsDeriverTest::testNewPreparationIncludesAddedDeclarationscallsDeriverTest::testNewPreparationKeepsClosureReferencesWithinItsSnapshotcallsDeriverTest::testOnlyPreparationAndDerivationArePubliccallsDeriverTest::testPrepareAndDeriveDoNotExecuteApplicationCodecallsDeriverTest::testPrepareConvertsConfiguredMicroEvaluatorscallsDeriverTest::testPreparedSourcesSurviveChangesAndRemovalBeforeTheFirstQuerycallsDeriverTest::testPrepareReadsOnlyTheSelectedFilesAfterDiscoverycallsDeriverTest::testPrepareRejectsDirectoriesInsteadOfExpandingThemcallsDeriverTest::testPrepareRejectsFilesRemovedAfterDiscoverycallsDeriverTest::testPrepareRejectsIncompleteDeclarationscallsDeriverTest::testPrepareRejectsMalformedSourceWithoutAQuerycallsDeriverTest::testPrepareRejectsRepeatedPathscallsDeriverTest::testPrepareReportsResolutionFailuresSeparatelyFromSyntaxErrorscallsDeriverTest::testPrepareTranslatesThePhpVersionIntoParserConfigurationcallsDeriverTest::testPrepareUsesDefaultConfigurationcallsDeriverTest::testRejectedQueryDoesNotInvalidatePreparedSourcescallsDeriverTest::testRepeatedQueriesHaveIndependentEvaluationStatecalls
Called from 1
Calls 25
- static-call DeriverConfig::default() line 60
- method-call Collector::collect() line 61
- new Collector line 61
- new TargetProfile line 62
- function-call
array_mapline 63 - static-call Term::fromNative() line 63
- new EvaluatorConfig line 64
- method-call MicroEvaluatorConversion::convert() line 64
- new MicroEvaluatorConversion line 64
- new Evaluators line 65
- new SnapshotIdentity line 66
- new Parser line 67
- new ParserConfig line 67
- new Resolver line 68
- method-call Resolver::resolve() line 71
- method-call Parser::parse() line 71
- new Index line 73
- method-call Index::diagnostics() line 74
- new InvalidInputException line 77
- method-call SnapshotIdentity::snapshot() line 80
- static-call Frontier::fromDiagnostic() line 80
- new
selfline 81 - new SelectorResolution line 81
- new CandidateQuery line 81
- new DefinitionIndex line 81
public function derive(string $query): CandidateCollectionAnswers a selector against the prepared sources with fresh evaluation state. Each result owns its evidence; the deriver does not retain query results.
Parameters
$query | string | Callable or source-position selector |
Returns
CandidateCollection Candidates and their self-contained evidenceThrows
InvalidInputException If the selector cannot identify a supported targetTest cases 8
Calls 3
- method-call CandidateQuery::derive() line 93
- method-call SelectorResolution::resolve() line 93
- static-call Query::parse() line 93
Private surface 3§
Implementation details, listed for orientation only.
private SelectorResolution $selectionprivate CandidateQuery $evaluationprivate function __construct(
private SelectorResolution $selection,
private CandidateQuery $evaluation,
)Test cases 200§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 19
DeriverTest::testCandidateEvidenceSurvivesTheDerivercallsDeriverTest::testDeriverDoesNotRetainResultscallsDeriverTest::testNewPreparationIncludesAddedDeclarationscallsDeriverTest::testNewPreparationKeepsClosureReferencesWithinItsSnapshotcallsDeriverTest::testOnlyPreparationAndDerivationArePubliccallsDeriverTest::testPrepareAndDeriveDoNotExecuteApplicationCodecallsDeriverTest::testPrepareConvertsConfiguredMicroEvaluatorscallsDeriverTest::testPreparedSourcesSurviveChangesAndRemovalBeforeTheFirstQuerycallsDeriverTest::testPrepareReadsOnlyTheSelectedFilesAfterDiscoverycallsDeriverTest::testPrepareRejectsDirectoriesInsteadOfExpandingThemcallsDeriverTest::testPrepareRejectsFilesRemovedAfterDiscoverycallsDeriverTest::testPrepareRejectsIncompleteDeclarationscallsDeriverTest::testPrepareRejectsMalformedSourceWithoutAQuerycallsDeriverTest::testPrepareRejectsRepeatedPathscallsDeriverTest::testPrepareReportsResolutionFailuresSeparatelyFromSyntaxErrorscallsDeriverTest::testPrepareTranslatesThePhpVersionIntoParserConfigurationcallsDeriverTest::testPrepareUsesDefaultConfigurationcallsDeriverTest::testRejectedQueryDoesNotInvalidatePreparedSourcescallsDeriverTest::testRepeatedQueriesHaveIndependentEvaluationStatecalls
Other tests reaching this symbol 181
CliBench::benchFirstQuerycallsCliBench::benchPreparecallsCliBench::benchQueryBatchcallsCliBench::preparecallsCliBench::prepareWithBranchPruningcallsLaravelBench::benchFirstQuerycallsLaravelBench::benchPreparecallsLaravelBench::benchQueryBatchcallsLaravelBench::preparecallsLaravelBench::prepareWithBranchPruningcallsSymfonyBench::benchFirstQuerycallsSymfonyBench::benchPreparecallsSymfonyBench::benchQueryBatchcallsSymfonyBench::preparecallsSymfonyBench::prepareWithBranchPruningcallsWebBench::benchFirstQuerycallsWebBench::benchPreparecallsWebBench::benchQueryBatchcallsWebBench::preparecallsWebBench::prepareWithBranchPruningcallsPhpContext::derivecallsEnvironmentTest::testDeriveIdentifiesEnvironmentContentsAndSourceChangescallsEnvironmentTest::testDeriveKeepsUnspecifiedInputsAndEventsUnresolvedcallsEnvironmentTest::testDeriveUsesVariableAndEnvironmentNamescallsMicroEvaluatorTest::testCallbackFailureReportsTheEvaluatorIdentitycallsMicroEvaluatorTest::testCanReturnAPartialExpressionWithItsDemandedInputcallsMicroEvaluatorTest::testComposesOperandEvaluationWithBuiltInFunctionscallsMicroEvaluatorTest::testConditionalEvaluationDemandsOnlyTheSelectedBranchcallsMicroEvaluatorTest::testDecliningContinuesWithBuiltInAndSourceEvaluationcallsMicroEvaluatorTest::testDisabledStandardEvaluatorsDoNotDisableConfiguredEvaluatorscallsMicroEvaluatorTest::testEvaluatesOnlyDemandedArgumentscallsMicroEvaluatorTest::testEvaluationStateIsFreshForEachQuerycallsMicroEvaluatorTest::testInvalidInputDemandReportsTheEvaluatorIdentitycallsMicroEvaluatorTest::testPriorityAndEvidenceDoNotDependOnRegistrationOrdercallsMicroEvaluatorTest::testRejectsConflictingMicroEvaluatorsDuringPreparationcallsMicroEvaluatorTest::testUsesNamedArgumentsAndLeavesOtherArgumentsUnopenedcallsSelectorQueryTest::testDeriveDoesNotAddAFileNamedOnlyByTheSelectorcallsSelectorQueryTest::testDeriveFindsArgumentsInsideClosurescallsSelectorQueryTest::testDeriveRejectsAnUnknownFormalParametercallsSelectorQueryTest::testDeriveRejectsCallsSharingTheSameStartPositioncallsSelectorQueryTest::testDeriveResolvesRelativePathsAgainstTheWorkingDirectorycallsSelectorQueryTest::testDeriveSelectsArgumentExpressionsWithoutExecutingTheCallcallsSelectorQueryTest::testDeriveSelectsNamespacedReturnsAndFormalParameterOriginscallsSelectorQueryTest::testDeriveUsesByteColumnsWithUtf8AndCrLfSourcecallsSelectorQueryTest::testPreparedRelativeSourcesAndSelectorsKeepTheirOriginalDirectorycallsResultRefTestcallsSnapshotTestcallsStatisticsTestcallsDeriverConfigTestcallsArrayFunctionsTestcallsFunctionEvaluatorTestcallsLibraryTestcallsScalarFunctionsTestcallsTypePredicatesTestcallsCallDecisionTestcallsCallDescriptionTestcallsCallDescriptorTestcallsEvaluatorsTestcallsActionTestcallsExpressionTestcallsPlanCompilerTestcallsSemanticPlanTestcallsParameterTestcallsSignatureTestcallsLatticeTestcallsFrontierTestcallsAllocationTestcallsArgumentBindingTestcallsArgumentOrderTestcallsCallExecutorTestcallsCallResolutionTestcallsBindingTestcallsCaptureTestcallsAccessTestcallsInvocationTestcallsMethodInvocationTestcallsInvocationTestcallsParameterBindingTestcallsPassedArgumentTestcallsArgumentsTestcallsCreationTestcallsMethodsTestcallsResolutionTestcallsUnpackTestcallsTypeBindingTestcallsTypeCheckTestcallsUnknownCallTestcallsAlternativeTestcallsAssessmentTestcallsCompletionTestcallsExceptionalTestcallsConstraintsTestcallsContextTestcallsCollectionCallsTestcallsHandlerTestcallsIterationStepTestcallsIteratorCursorTestcallsLoopConvergenceTestcallsStateJoinTestcallsUnwindingTestcallsHavocTestcallsInstructionTransferTestcallsLocationTestcallsMemoryTestcallsObservationCollectorTestcallsProtocolTestcallsTransferTestcallsConversionsTestcallsCountableCallsTestcallsScalarErrorsTestcallsStateTestcallsEvaluationTestcallsInvocationTestcallsDerivationTestcallsExplanationTestcallsCallableTransferTestcallsCompoundAssignmentTestcallsConstantTransferTestcallsIntrinsicTransferTestcallsMemoryStepTestcallsObjectAccessTestcallsPropertyAccessCheckTestcallsPropertyMagicTestcallsPropertyReferenceTestcallsPropertyTransferTestcallsPureStepTestcallsReferenceAssignmentTestcallsProjectionTestcallsBudgetTestcallsEntryPointTestcallsObservationTestcallsQueryScopeTestcallsReturnQueryTestcallsStateQueryTestcallsTupleQueryTestcallsValueQueryTestcallsArithmeticTestcallsArraysTestcallsComparisonTestcallsOperationsTestcallsTargetProfileTestcallsTermTestcallsDerivationResultTestcallsQueryExecutionTestcallsResultAssessmentTestcallsValueGraphTestcallsAggregateLoweringTestcallsAssignmentLoweringTestcallsCallLoweringTestcallsConditionalLoweringTestcallsDestructuringLoweringTestcallsExceptionLoweringTestcallsGotoLoweringTestcallsLoopLoweringTestcallsMatchLoweringTestcallsStaticLoweringTestcallsSwitchLoweringTestcallsCallableSourceTestcallsIndexerTestcallsIndexTestcallsClassDeclarationTestcallsPropertyDeclarationTestcallsSymbolRefTestcallsEffectInspectionTestcallsExpressionLoweringTestcallsArgumentTestcallsBasicBlockTestcallsCallableGraphTestcallsCatchTargetTestcallsExceptionRegionTestcallsExpressionRefTestcallsInstructionTestcallsParameterTestcallsPointRefTestcallsTerminatorTestcallsDispatchTestcallsInstructionEmitterTestcallsLowererTestcallsLoweringScopeTestcallsStatementLoweringTestcallsCallObservationsTestcalls