Skip to content

Commit 25d723e

Browse files
Bernhard Schmittmficzel
authored andcommitted
Adjust Neos.Flow Validation subcontext
1 parent 5e02f0c commit 25d723e

22 files changed

+98
-73
lines changed

Neos.Flow/Classes/Validation/Validator/AbstractCompositeValidator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ abstract class AbstractCompositeValidator implements ObjectValidatorInterface, \
2424
/**
2525
* This contains the supported options, their default values and descriptions.
2626
*
27-
* @var array
27+
* @var array<mixed>
2828
*/
2929
protected $supportedOptions = [];
3030

3131
/**
32-
* @var array
32+
* @var array<mixed>
3333
*/
3434
protected $options = [];
3535

3636
/**
37-
* @var \SplObjectStorage
37+
* @var \SplObjectStorage<ValidatorInterface,mixed>
3838
*/
3939
protected $validators;
4040

4141
/**
42-
* @var \SplObjectStorage
42+
* @var \SplObjectStorage<object,mixed>
4343
*/
4444
protected $validatedInstancesContainer;
4545

4646
/**
4747
* Constructs the composite validator and sets validation options
4848
*
49-
* @param array $options Options for the validator
49+
* @param array<mixed> $options Options for the validator
5050
* @api
5151
* @throws InvalidValidationOptionsException
5252
*/
@@ -84,7 +84,7 @@ function ($value) {
8484
/**
8585
* Allows to set a container to keep track of validated instances.
8686
*
87-
* @param \SplObjectStorage $validatedInstancesContainer A container to keep track of validated instances
87+
* @param \SplObjectStorage<object,mixed> $validatedInstancesContainer A container to keep track of validated instances
8888
* @return void
8989
* @api
9090
*/
@@ -102,7 +102,7 @@ public function setValidatedInstancesContainer(\SplObjectStorage $validatedInsta
102102
*/
103103
public function addValidator(ValidatorInterface $validator)
104104
{
105-
if ($validator instanceof ObjectValidatorInterface && isset($this->validatedInstancesContainer)) {
105+
if ($validator instanceof ObjectValidatorInterface) {
106106
$validator->setValidatedInstancesContainer($this->validatedInstancesContainer);
107107
}
108108
$this->validators->attach($validator);
@@ -115,7 +115,7 @@ public function addValidator(ValidatorInterface $validator)
115115
* @throws NoSuchValidatorException
116116
* @api
117117
*/
118-
public function removeValidator(ValidatorInterface $validator)
118+
public function removeValidator(ValidatorInterface $validator): void
119119
{
120120
if (!$this->validators->contains($validator)) {
121121
throw new NoSuchValidatorException('Cannot remove validator because its not in the conjunction.', 1207020177);
@@ -137,7 +137,7 @@ public function count(): int
137137
/**
138138
* Returns the child validators of this Composite Validator
139139
*
140-
* @return \SplObjectStorage
140+
* @return \SplObjectStorage<ValidatorInterface,mixed>
141141
*/
142142
public function getValidators()
143143
{
@@ -147,7 +147,7 @@ public function getValidators()
147147
/**
148148
* Returns the options for this validator
149149
*
150-
* @return array
150+
* @return array<mixed>
151151
*/
152152
public function getOptions()
153153
{

Neos.Flow/Classes/Validation/Validator/AbstractValidator.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ abstract class AbstractValidator implements ValidatorInterface
4141
* 2 => type
4242
* 3 => required (boolean, optional)
4343
*
44-
* @var array
44+
* @var array<mixed>
4545
*/
4646
protected $supportedOptions = [];
4747

4848
/**
49-
* @var array
49+
* @var array<mixed>
5050
*/
5151
protected $options = [];
5252

5353
/**
54-
* @var ErrorResult
54+
* @var ErrorResult|null
5555
*/
5656
private $result;
5757

@@ -63,7 +63,7 @@ abstract class AbstractValidator implements ValidatorInterface
6363
/**
6464
* Constructs the validator and sets validation options
6565
*
66-
* @param array $options Options for the validator
66+
* @param array<mixed> $options Options for the validator
6767
* @throws InvalidValidationOptionsException if unsupported options are found
6868
* @api
6969
*/
@@ -117,7 +117,7 @@ protected function pushResult()
117117
/**
118118
* Pop and return the current Result from the stack and make $this->result point to the last Result again.
119119
* @since Flow 4.3
120-
* @return ErrorResult
120+
* @return ErrorResult|null
121121
*/
122122
protected function popResult()
123123
{
@@ -143,7 +143,7 @@ protected function getResult()
143143
* the Error Messages object which occurred.
144144
*
145145
* @param mixed $value The value that should be validated
146-
* @return ErrorResult
146+
* @return ErrorResult|null
147147
* @throws InvalidValidationOptionsException
148148
* @api
149149
*/
@@ -171,19 +171,22 @@ abstract protected function isValid($value);
171171
*
172172
* @param string $message The error message
173173
* @param integer $code The error code (a unix timestamp)
174-
* @param array $arguments Arguments to be replaced in message
174+
* @param array<mixed> $arguments Arguments to be replaced in message
175175
* @return void
176176
* @api
177177
*/
178178
protected function addError($message, $code, array $arguments = [])
179179
{
180+
if ($this->result === null) {
181+
$this->result = new ErrorResult();
182+
}
180183
$this->result->addError(new ValidationError($message, $code, $arguments));
181184
}
182185

183186
/**
184187
* Returns the options of this validator
185188
*
186-
* @return array
189+
* @return array<mixed>
187190
*/
188191
public function getOptions()
189192
{

Neos.Flow/Classes/Validation/Validator/BooleanValueValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class BooleanValueValidator extends AbstractValidator
2323
{
2424
/**
25-
* @var array
25+
* @var array<string,mixed>
2626
*/
2727
protected $supportedOptions = [
2828
'expectedValue' => [true, 'The expected boolean value', 'boolean']

Neos.Flow/Classes/Validation/Validator/CollectionValidator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class CollectionValidator extends GenericObjectValidator
2323
{
2424
/**
25-
* @var array
25+
* @var array<string,mixed>
2626
*/
2727
protected $supportedOptions = [
2828
'elementValidator' => [null, 'The validator type to use for the collection elements', 'string'],
@@ -52,7 +52,7 @@ protected function isValid($value)
5252
{
5353
if ($value instanceof \Doctrine\Common\Collections\AbstractLazyCollection && !$value->isInitialized()) {
5454
return;
55-
} elseif ((is_object($value) && !TypeHandling::isCollectionType(get_class($value))) && !is_array($value)) {
55+
} elseif (is_object($value) && !TypeHandling::isCollectionType(get_class($value))) {
5656
$this->addError('The given subject was not a collection.', 1317204797);
5757
return;
5858
} elseif (is_object($value) && $this->isValidatedAlready($value)) {
@@ -75,7 +75,9 @@ protected function isValid($value)
7575
$collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer);
7676
}
7777

78-
$this->getResult()->forProperty($index)->merge($collectionElementValidator->validate($collectionElement));
78+
if ($this->getResult() && $collectionElementValidator) {
79+
$this->getResult()->forProperty($index)->merge($collectionElementValidator->validate($collectionElement));
80+
}
7981
}
8082
}
8183
}

Neos.Flow/Classes/Validation/Validator/ConjunctionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ConjunctionValidator extends AbstractCompositeValidator
2525
* Every validator has to be valid, to make the whole conjunction valid.
2626
*
2727
* @param mixed $value The value that should be validated
28-
* @return ErrorResult
28+
* @return ErrorResult|null
2929
* @api
3030
*/
3131
public function validate($value)

Neos.Flow/Classes/Validation/Validator/CountValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class CountValidator extends AbstractValidator
2121
{
2222
/**
23-
* @var array
23+
* @var array<string,mixed>
2424
*/
2525
protected $supportedOptions = [
2626
'minimum' => [0, 'The minimum count to accept', 'integer'],

Neos.Flow/Classes/Validation/Validator/DateTimeRangeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class DateTimeRangeValidator extends AbstractValidator
2222
{
2323
/**
24-
* @var array
24+
* @var array<string,mixed>
2525
*/
2626
protected $supportedOptions = [
2727
'latestDate' => [null, 'The latest date to accept', 'string'],

Neos.Flow/Classes/Validation/Validator/DateTimeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class DateTimeValidator extends AbstractValidator
2424
{
2525
/**
26-
* @var array
26+
* @var array<string,mixed>
2727
*/
2828
protected $supportedOptions = [
2929
'locale' => [null, 'The locale to use for date parsing', 'string|Locale'],

Neos.Flow/Classes/Validation/Validator/DisjunctionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DisjunctionValidator extends AbstractCompositeValidator
2828
* Errors are only returned if all validators failed.
2929
*
3030
* @param mixed $value The value that should be validated
31-
* @return ErrorResult
31+
* @return ErrorResult|null
3232
* @api
3333
*/
3434
public function validate($value)

Neos.Flow/Classes/Validation/Validator/EmailAddressValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class EmailAddressValidator extends AbstractValidator
2828
{
2929
/**
30-
* @var array
30+
* @var array<string,mixed>
3131
*/
3232
protected $supportedOptions = [
3333
'strict' => [false, 'Whether to fail validation on RFC warnings', 'bool'],

0 commit comments

Comments
 (0)