Skip to content

Commit

Permalink
PHPLIB-1250 Split encoders and fix psalm issues (#46)
Browse files Browse the repository at this point in the history
* Split encoders into multiple files

* Remove unnecessary factory method

* Add missing template annotation

* Add MixedArgument and MixedAssignment to psalm baseline

* Fix type issues in query classes

* Extract common builder code and fix template annotations

* Update psalm baseline

* Define ENCODE constant in OperatorInterface

* Simplify canEncode check in BuilderEncoder

* Use strict comparison

* Fix checkstyle errors

* Fix wrong object type check

* Update todo for properties in interfaces

* Fix return type of PipelineEncoder::encode

* Update comment in OperatorEncoder

Co-authored-by: Jeremy Mikola <jmikola@gmail.com>

* Optimise cached encoders structure

* Add undefined case for Encode enum

---------

Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
  • Loading branch information
alcaeus and jmikola authored Jan 29, 2024
1 parent aa7cffc commit 397ff5d
Show file tree
Hide file tree
Showing 16 changed files with 709 additions and 288 deletions.
1 change: 0 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<exclude name="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn" />
<exclude name="SlevomatCodingStandard.Functions.StaticClosure" />
<exclude name="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators" />

<!-- ********************* -->
<!-- Exclude broken sniffs -->
Expand Down
133 changes: 132 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="src/Builder/Encoder/AbstractExpressionEncoder.php">
<MixedAssignment>
<code>$val</code>
<code>$val</code>
<code>$value[$key]</code>
</MixedAssignment>
</file>
<file src="src/Builder/Encoder/CombinedFieldQueryEncoder.php">
<MixedAssignment>
<code>$filter</code>
<code>$filterValue</code>
</MixedAssignment>
</file>
<file src="src/Builder/Encoder/FieldPathEncoder.php">
<NoInterfaceProperties>
<code><![CDATA[$value->name]]></code>
</NoInterfaceProperties>
</file>
<file src="src/Builder/Encoder/OperatorEncoder.php">
<MixedAssignment>
<code>$result</code>
<code>$result[]</code>
<code>$val</code>
<code>$val</code>
<code>$val</code>
<code>$val</code>
<code>$val</code>
</MixedAssignment>
</file>
<file src="src/Builder/Encoder/OutputWindowEncoder.php">
<MixedArgument>
<code>$result</code>
</MixedArgument>
</file>
<file src="src/Builder/Encoder/QueryEncoder.php">
<MixedArgument>
<code><![CDATA[$this->recursiveEncode($value)]]></code>
</MixedArgument>
<MixedAssignment>
<code>$subValue</code>
<code>$value</code>
</MixedAssignment>
</file>
<file src="src/Builder/Projection/ElemMatchOperator.php">
<MixedArgumentTypeCoercion>
<code>$query</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Builder/Query.php">
<ArgumentTypeCoercion>
<code>$query</code>
</ArgumentTypeCoercion>
</file>
<file src="src/Builder/Query/ElemMatchOperator.php">
<MixedArgumentTypeCoercion>
<code>$query</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Builder/Stage/AddFieldsStage.php">
<PropertyTypeCoercion>
<code>$expression</code>
</PropertyTypeCoercion>
<TooManyTemplateParams>
<code>stdClass</code>
</TooManyTemplateParams>
</file>
<file src="src/Builder/Stage/FacetStage.php">
<PropertyTypeCoercion>
<code>$facet</code>
</PropertyTypeCoercion>
<TooManyTemplateParams>
<code>stdClass</code>
</TooManyTemplateParams>
</file>
<file src="src/Builder/Stage/GeoNearStage.php">
<MixedArgumentTypeCoercion>
<code>$query</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Builder/Stage/GraphLookupStage.php">
<MixedArgumentTypeCoercion>
<code>$restrictSearchWithMatch</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Builder/Stage/GroupStage.php">
<PropertyTypeCoercion>
<code>$field</code>
</PropertyTypeCoercion>
<TooManyTemplateParams>
<code>stdClass</code>
</TooManyTemplateParams>
</file>
<file src="src/Builder/Stage/MatchStage.php">
<MixedArgumentTypeCoercion>
<code>$query</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Builder/Stage/ProjectStage.php">
<PropertyTypeCoercion>
<code>$specification</code>
</PropertyTypeCoercion>
<TooManyTemplateParams>
<code>stdClass</code>
</TooManyTemplateParams>
</file>
<file src="src/Builder/Stage/SetStage.php">
<PropertyTypeCoercion>
<code>$field</code>
</PropertyTypeCoercion>
<TooManyTemplateParams>
<code>stdClass</code>
</TooManyTemplateParams>
</file>
<file src="src/Builder/Type/OutputWindow.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_string($documents[1]) && ! is_int($documents[1])]]></code>
<code><![CDATA[! is_string($range[1]) && ! is_numeric($range[1])]]></code>
</DocblockTypeContradiction>
</file>
<file src="src/Builder/Type/QueryObject.php">
<MixedAssignment>
<code>$queries[$fieldPath]</code>
<code>$query</code>
</MixedAssignment>
<RedundantConditionGivenDocblockType>
<code><![CDATA[count($queriesOrArrayOfQueries) === 1 &&
isset($queriesOrArrayOfQueries[0]) &&
is_array($queriesOrArrayOfQueries[0]) &&
count($queriesOrArrayOfQueries[0]) > 0]]></code>
</RedundantConditionGivenDocblockType>
</file>
</files>
Loading

0 comments on commit 397ff5d

Please sign in to comment.