Skip to content

Commit

Permalink
Change order of conditions to please psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jan 29, 2025
1 parent 9b29819 commit 663418d
Show file tree
Hide file tree
Showing 32 changed files with 147 additions and 148 deletions.
5 changes: 2 additions & 3 deletions generator/config/accumulator/accumulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tests:
function(state, numCopies) {
return { count: state.count + 1, sum: state.sum + numCopies }
}
accumulateArgs: [ "$copies" ],
accumulateArgs: [ "$copies" ]
merge:
$code: |-
function(state1, state2) {
Expand Down Expand Up @@ -115,8 +115,7 @@ tests:
}
return state;
}
accumulateArgs:
- '$name'
accumulateArgs: ['$name']
merge:
$code: |-
function(state1, state2) {
Expand Down
24 changes: 12 additions & 12 deletions generator/src/OperatorClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
$constructorParam->setDefaultValue($argument->default);
}

if ($type->dollarPrefixedString) {
$namespace->addUseFunction('is_string');
$namespace->addUseFunction('str_starts_with');
$namespace->addUse(InvalidArgumentException::class);
$constructor->addBody(<<<PHP
if (is_string(\${$argument->propertyName}) && ! str_starts_with(\${$argument->propertyName}, '$')) {
throw new InvalidArgumentException('Argument \${$argument->propertyName} can be an expression, field paths and variable names must be prefixed by "$" or "$$".');
}
PHP);
}

// List type must be validated with array_is_list()
if ($type->list) {
$namespace->addUseFunction('is_array');
Expand Down Expand Up @@ -169,18 +181,6 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
PHP);
}

if ($type->dollarPrefixedString) {
$namespace->addUseFunction('is_string');
$namespace->addUseFunction('str_starts_with');
$namespace->addUse(InvalidArgumentException::class);
$constructor->addBody(<<<PHP
if (is_string(\${$argument->propertyName}) && ! str_starts_with(\${$argument->propertyName}, '$')) {
throw new InvalidArgumentException('Argument \${$argument->propertyName} can be an expression, field paths and variable names must be prefixed by "$" or "$$".');
}
PHP);
}
}

// Set property from constructor argument
Expand Down
16 changes: 8 additions & 8 deletions src/Builder/Accumulator/AccumulatorAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Accumulator/LastNAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Accumulator/MaxNAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Accumulator/MinNAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Accumulator/PercentileAccumulator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/AllElementsTrueOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/AnyElementTrueOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/ArrayElemAtOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/ArrayToObjectOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/FilterOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/FirstNOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/FirstOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/InOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/IndexOfArrayOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/LastNOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/LastOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Builder/Expression/MapOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 663418d

Please sign in to comment.