WooCommerce Code Reference

OverlappingFieldsCanBeMerged extends ValidationRule
in package

ReasonOrReasons is recursive, but PHPStan does not support that.

Tags
phpstan-type

ReasonOrReasons string|array<array{string, string|array}>

phpstan-type

Conflict array{array{string, ReasonOrReasons}, array<int, FieldNode>, array<int, FieldNode>}

phpstan-type

FieldInfo array{Type|null, FieldNode, FieldDefinition|null}

phpstan-type

FieldMap array<string, array<int, FieldInfo>>

Table of Contents

$cachedFieldsAndFragmentNames  : SplObjectStorage
A cache for the "field map" and list of fragment names found in any given selection set. Selection sets may be asked for this information multiple times, so this improves the performance of this validator.
$comparedFragmentPairs  : PairSet
A memoization for when two fragments are compared "between" each other for conflicts. Two fragments may be compared many times, so memoizing this can dramatically improve the performance of this validator.
$name  : string
fieldsConflictMessage()  : string
getName()  : string
getSDLVisitor()  : array<string|int, mixed>
Returns structure suitable for @see \Automattic\WooCommerce\Vendor\GraphQL\Language\Visitor.
getVisitor()  : array<string|int, mixed>
Returns structure suitable for @see \Automattic\WooCommerce\Vendor\GraphQL\Language\Visitor.
reasonMessage()  : string
collectConflictsBetween()  : void
Collect all Conflicts between two collections of fields. This is similar to, but different from the `collectConflictsWithin` function above. This check assumes that `collectConflictsWithin` has already been called on each provided collection of fields. This is true because this validator traverses each individual selection set.
collectConflictsBetweenFieldsAndFragment()  : void
Collect all conflicts found between a set of fields and a fragment reference including via spreading in any nested fragments.
collectConflictsBetweenFragments()  : void
Collect all conflicts found between two fragments, including via spreading in any nested fragments.
collectConflictsWithin()  : void
Collect all Conflicts "within" one collection of fields.
deduplicateFields()  : array<string|int, mixed>
doTypesConflict()  : bool
Two types conflict if both types could not apply to a value simultaneously.
fieldFingerprint()  : string
findConflict()  : array<string|int, mixed>|null
Determines if there is a conflict between two particular fields, including comparing their sub-fields.
findConflictsBetweenSubSelectionSets()  : array<int, Conflict>
Find all conflicts found between two selection sets, including those found via spreading in fragments. Called when determining if conflicts exist between the sub-fields of two overlapping fields.
findConflictsWithinSelectionSet()  : array<string|int, mixed>
Find all conflicts found "within" a selection set, including those found via spreading in fragments. Called when visiting each SelectionSet in the Automattic\WooCommerce\Vendor\GraphQL Document.
getFieldsAndFragmentNames()  : array{: \Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\FieldMap, : array}
Given a selection set, return the collection of fields (a mapping of response name to field ASTs and definitions) as well as a list of fragment names referenced via fragment spreads.
getReferencedFieldsAndFragmentNames()  : array<string|int, mixed>
Given a reference to a fragment, return the represented collection of fields as well as a list of nested fragment names referenced via fragment spreads.
internalCollectFieldsAndFragmentNames()  : void
Given a reference to a fragment, return the represented collection of fields as well as a list of nested fragment names referenced via fragment spreads.
sameArguments()  : bool
sameValue()  : bool
subfieldConflicts()  : array<string|int, mixed>|null
Merge Conflicts between two sub-fields into a single Conflict.

Properties

$cachedFieldsAndFragmentNames

A cache for the "field map" and list of fragment names found in any given selection set. Selection sets may be asked for this information multiple times, so this improves the performance of this validator.

protected SplObjectStorage $cachedFieldsAndFragmentNames
Tags
phpstan-var

\SplObjectStorage<SelectionSetNode, array{FieldMap, array<int, string>}>

Methods

fieldsConflictMessage()

public static fieldsConflictMessage(string $responseName, string|array<string|int, mixed> $reasonOrReasons) : string
Parameters
$responseName : string
$reasonOrReasons : string|array<string|int, mixed>
Tags
phpstan-param

ReasonOrReasons $reasonOrReasons

Return values
string

collectConflictsBetween()

Collect all Conflicts between two collections of fields. This is similar to, but different from the `collectConflictsWithin` function above. This check assumes that `collectConflictsWithin` has already been called on each provided collection of fields. This is true because this validator traverses each individual selection set.

protected collectConflictsBetween(QueryValidationContext $context, array<string|int, mixed> &$conflicts, bool $parentFieldsAreMutuallyExclusive, array<string|int, mixed> $fieldMap1, array<string|int, mixed> $fieldMap2) : void
Parameters
$context : QueryValidationContext
$conflicts : array<string|int, mixed>
$parentFieldsAreMutuallyExclusive : bool
$fieldMap1 : array<string|int, mixed>
$fieldMap2 : array<string|int, mixed>
Tags
phpstan-param

array<int, Conflict> $conflicts

phpstan-param

FieldMap $fieldMap1

phpstan-param

FieldMap $fieldMap2

throws
Exception
Return values
void

collectConflictsBetweenFieldsAndFragment()

Collect all conflicts found between a set of fields and a fragment reference including via spreading in any nested fragments.

protected collectConflictsBetweenFieldsAndFragment(QueryValidationContext $context, array<string|int, mixed> &$conflicts, array<string, true> &$comparedFragments, bool $areMutuallyExclusive, array<string|int, mixed> $fieldMap, string $fragmentName) : void
Parameters
$context : QueryValidationContext
$conflicts : array<string|int, mixed>
$comparedFragments : array<string, true>
$areMutuallyExclusive : bool
$fieldMap : array<string|int, mixed>
$fragmentName : string
Tags
phpstan-param

array<int, Conflict> $conflicts

phpstan-param

FieldMap $fieldMap

throws
Exception
Return values
void

collectConflictsBetweenFragments()

Collect all conflicts found between two fragments, including via spreading in any nested fragments.

protected collectConflictsBetweenFragments(QueryValidationContext $context, array<string|int, mixed> &$conflicts, bool $areMutuallyExclusive, string $fragmentName1, string $fragmentName2) : void
Parameters
$context : QueryValidationContext
$conflicts : array<string|int, mixed>
$areMutuallyExclusive : bool
$fragmentName1 : string
$fragmentName2 : string
Tags
phpstan-param

array<int, Conflict> $conflicts

throws
Exception
Return values
void

deduplicateFields()

protected deduplicateFields(array<string|int, mixed> $fields) : array<string|int, mixed>
Parameters
$fields : array<string|int, mixed>
Tags
phpstan-param

array<int, FieldInfo> $fields

throws
JsonException
phpstan-return

array<int, FieldInfo>

Return values
array<string|int, mixed>

doTypesConflict()

Two types conflict if both types could not apply to a value simultaneously.

protected doTypesConflict(Type $type1, Type $type2) : bool

Composite types are ignored as their individual field types will be compared later recursively. However, List and Non-Null types must match.

Parameters
$type1 : Type
$type2 : Type
Return values
bool

findConflict()

Determines if there is a conflict between two particular fields, including comparing their sub-fields.

protected findConflict(QueryValidationContext $context, bool $parentFieldsAreMutuallyExclusive, string $responseName, array{: \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type|null, : \Automattic\WooCommerce\Vendor\GraphQL\Language\AST\FieldNode, : \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\FieldDefinition|null} $field1, array{: \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type|null, : \Automattic\WooCommerce\Vendor\GraphQL\Language\AST\FieldNode, : \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\FieldDefinition|null} $field2) : array<string|int, mixed>|null
Parameters
$context : QueryValidationContext
$parentFieldsAreMutuallyExclusive : bool
$responseName : string
$field1 : array{: \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type|null, : \Automattic\WooCommerce\Vendor\GraphQL\Language\AST\FieldNode, : \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\FieldDefinition|null}
$field2 : array{: \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type|null, : \Automattic\WooCommerce\Vendor\GraphQL\Language\AST\FieldNode, : \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\FieldDefinition|null}
Tags
throws
Exception
phpstan-return

Conflict|null

Return values
array<string|int, mixed>|null

findConflictsBetweenSubSelectionSets()

Find all conflicts found between two selection sets, including those found via spreading in fragments. Called when determining if conflicts exist between the sub-fields of two overlapping fields.

protected findConflictsBetweenSubSelectionSets(QueryValidationContext $context, bool $areMutuallyExclusive, Type|null $parentType1, SelectionSetNode $selectionSet1, Type|null $parentType2, SelectionSetNode $selectionSet2) : array<int, Conflict>
Parameters
$context : QueryValidationContext
$areMutuallyExclusive : bool
$parentType1 : Type|null
$selectionSet1 : SelectionSetNode
$parentType2 : Type|null
$selectionSet2 : SelectionSetNode
Tags
throws
Exception
Return values
array<int, Conflict>

findConflictsWithinSelectionSet()

Find all conflicts found "within" a selection set, including those found via spreading in fragments. Called when visiting each SelectionSet in the Automattic\WooCommerce\Vendor\GraphQL Document.

protected findConflictsWithinSelectionSet(QueryValidationContext $context, Type|null $parentType, SelectionSetNode $selectionSet) : array<string|int, mixed>
Parameters
$context : QueryValidationContext
$parentType : Type|null
$selectionSet : SelectionSetNode
Tags
throws
Exception
phpstan-return

array<int, Conflict>

Return values
array<string|int, mixed>

getFieldsAndFragmentNames()

Given a selection set, return the collection of fields (a mapping of response name to field ASTs and definitions) as well as a list of fragment names referenced via fragment spreads.

protected getFieldsAndFragmentNames(QueryValidationContext $context, Type|null $parentType, SelectionSetNode $selectionSet) : array{: \Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\FieldMap, : array}
Parameters
$context : QueryValidationContext
$parentType : Type|null
$selectionSet : SelectionSetNode
Tags
throws
Exception
Return values
array{: \Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\FieldMap, : array}

getReferencedFieldsAndFragmentNames()

Given a reference to a fragment, return the represented collection of fields as well as a list of nested fragment names referenced via fragment spreads.

protected getReferencedFieldsAndFragmentNames(QueryValidationContext $context, FragmentDefinitionNode $fragment) : array<string|int, mixed>
Parameters
$context : QueryValidationContext
$fragment : FragmentDefinitionNode
Tags
throws
Exception
phpstan-return

array{FieldMap, array<int, string>}

Return values
array<string|int, mixed>

internalCollectFieldsAndFragmentNames()

Given a reference to a fragment, return the represented collection of fields as well as a list of nested fragment names referenced via fragment spreads.

protected internalCollectFieldsAndFragmentNames(QueryValidationContext $context, Type|null $parentType, SelectionSetNode $selectionSet, array<string|int, mixed> &$astAndDefs, array<string, bool> &$fragmentNames) : void
Parameters
$context : QueryValidationContext
$parentType : Type|null
$selectionSet : SelectionSetNode
$astAndDefs : array<string|int, mixed>
$fragmentNames : array<string, bool>
Tags
phpstan-param

FieldMap $astAndDefs

throws
Exception
Return values
void

subfieldConflicts()

Merge Conflicts between two sub-fields into a single Conflict.

protected subfieldConflicts(array<string|int, mixed> $conflicts, string $responseName, FieldNode $ast1, FieldNode $ast2) : array<string|int, mixed>|null
Parameters
$conflicts : array<string|int, mixed>
$responseName : string
$ast1 : FieldNode
$ast2 : FieldNode
Tags
phpstan-param

array<int, Conflict> $conflicts

phpstan-return

Conflict|null

Return values
array<string|int, mixed>|null