Complex classes like Validator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Validator, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Limoncello\Flute\Validation; |
||
| 43 | class Validator extends BaseValidator implements JsonApiValidatorInterface |
||
| 44 | { |
||
| 45 | use RelationshipsTrait, HasContainerTrait; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Namespace for string resources. |
||
| 49 | */ |
||
| 50 | const RESOURCES_NAMESPACE = 'Limoncello.Flute.Validation'; |
||
| 51 | |||
| 52 | /** Rule description index */ |
||
| 53 | const RULE_INDEX = 0; |
||
| 54 | |||
| 55 | /** Rule description index */ |
||
| 56 | const RULE_ATTRIBUTES = self::RULE_INDEX + 1; |
||
| 57 | |||
| 58 | /** Rule description index */ |
||
| 59 | const RULE_TO_ONE = self::RULE_ATTRIBUTES + 1; |
||
| 60 | |||
| 61 | /** Rule description index */ |
||
| 62 | const RULE_TO_MANY = self::RULE_TO_ONE + 1; |
||
| 63 | |||
| 64 | /** Rule description index */ |
||
| 65 | const RULE_UNLISTED_ATTRIBUTE = self::RULE_TO_MANY + 1; |
||
| 66 | |||
| 67 | /** Rule description index */ |
||
| 68 | const RULE_UNLISTED_RELATIONSHIP = self::RULE_UNLISTED_ATTRIBUTE + 1; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var int |
||
| 72 | */ |
||
| 73 | private $errorStatus; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var ContextStorageInterface |
||
| 77 | */ |
||
| 78 | private $contextStorage; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var JsonApiErrorCollection |
||
| 82 | */ |
||
| 83 | private $jsonApiErrors; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var array |
||
| 87 | */ |
||
| 88 | private $blocks; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var array |
||
| 92 | */ |
||
| 93 | private $idRule; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var array |
||
| 97 | */ |
||
| 98 | private $typeRule; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var int[] |
||
| 102 | */ |
||
| 103 | private $attributeRules; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var int[] |
||
| 107 | */ |
||
| 108 | private $toOneRules; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var int[] |
||
| 112 | */ |
||
| 113 | private $toManyRules; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var bool |
||
| 117 | */ |
||
| 118 | private $isIgnoreUnknowns; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var FormatterInterface|null |
||
| 122 | */ |
||
| 123 | private $messageFormatter; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $name |
||
| 127 | * @param array $data |
||
| 128 | * @param ContainerInterface $container |
||
| 129 | * @param int $errorStatus |
||
| 130 | * |
||
| 131 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 132 | */ |
||
| 133 | 20 | public function __construct( |
|
| 155 | |||
| 156 | /** |
||
| 157 | * @inheritdoc |
||
| 158 | */ |
||
| 159 | 13 | public function assert($jsonData): JsonApiValidatorInterface |
|
| 167 | |||
| 168 | /** |
||
| 169 | * @inheritdoc |
||
| 170 | * |
||
| 171 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 172 | */ |
||
| 173 | 19 | public function validate($input): bool |
|
| 193 | |||
| 194 | /** |
||
| 195 | * @inheritdoc |
||
| 196 | */ |
||
| 197 | 6 | public function getJsonApiErrors(): array |
|
| 201 | |||
| 202 | /** |
||
| 203 | * @inheritdoc |
||
| 204 | */ |
||
| 205 | 8 | public function getJsonApiCaptures(): array |
|
| 209 | |||
| 210 | /** |
||
| 211 | * @return BaseValidator |
||
|
|
|||
| 212 | */ |
||
| 213 | 20 | protected function resetAggregators(): BaseValidator |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @param array $jsonData |
||
| 225 | * |
||
| 226 | * @return self |
||
| 227 | * |
||
| 228 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 229 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 230 | */ |
||
| 231 | 18 | private function validateType(array $jsonData): self |
|
| 232 | { |
||
| 233 | // execute start(s) |
||
| 234 | 18 | $starts = JsonApiRuleSerializer::getRuleStartIndexes($this->getTypeRule()); |
|
| 235 | 18 | $this->executeStarts($starts); |
|
| 236 | |||
| 237 | 18 | if (array_key_exists(DI::KEYWORD_DATA, $jsonData) === true && |
|
| 238 | 18 | array_key_exists(DI::KEYWORD_TYPE, $data = $jsonData[DI::KEYWORD_DATA]) === true |
|
| 239 | ) { |
||
| 240 | // execute main validation block(s) |
||
| 241 | 17 | $index = JsonApiRuleSerializer::getRuleIndex($this->getTypeRule()); |
|
| 242 | 17 | $this->executeBlock($data[DI::KEYWORD_TYPE], $index); |
|
| 243 | } else { |
||
| 244 | 1 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 245 | 1 | $details = $this->formatMessage(ErrorCodes::TYPE_MISSING); |
|
| 246 | 1 | $this->getJsonApiErrorCollection()->addDataTypeError($title, $details, $this->getErrorStatus()); |
|
| 247 | } |
||
| 248 | |||
| 249 | // execute end(s) |
||
| 250 | 18 | $ends = JsonApiRuleSerializer::getRuleEndIndexes($this->getTypeRule()); |
|
| 251 | 18 | $this->executeEnds($ends); |
|
| 252 | |||
| 253 | 18 | if (count($this->getErrorAggregator()) > 0) { |
|
| 254 | 1 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 255 | 1 | foreach ($this->getErrorAggregator()->get() as $error) { |
|
| 256 | 1 | $this->getJsonApiErrorCollection() |
|
| 257 | 1 | ->addDataTypeError($title, $this->getMessage($error), $this->getErrorStatus()); |
|
| 258 | } |
||
| 259 | 1 | $this->getErrorAggregator()->clear(); |
|
| 260 | } |
||
| 261 | |||
| 262 | 18 | return $this; |
|
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param array $jsonData |
||
| 267 | * |
||
| 268 | * @return self |
||
| 269 | * |
||
| 270 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 271 | */ |
||
| 272 | 18 | private function validateId(array $jsonData): self |
|
| 273 | { |
||
| 274 | // execute start(s) |
||
| 275 | 18 | $starts = JsonApiRuleSerializer::getRuleStartIndexes($this->getIdRule()); |
|
| 276 | 18 | $this->executeStarts($starts); |
|
| 277 | |||
| 278 | // execute main validation block(s) |
||
| 279 | 18 | if (array_key_exists(DI::KEYWORD_DATA, $jsonData) === true && |
|
| 280 | 18 | array_key_exists(DI::KEYWORD_ID, $data = $jsonData[DI::KEYWORD_DATA]) === true |
|
| 281 | ) { |
||
| 282 | 16 | $index = JsonApiRuleSerializer::getRuleIndex($this->getIdRule()); |
|
| 283 | 16 | $this->executeBlock($data[DI::KEYWORD_ID], $index); |
|
| 284 | } |
||
| 285 | |||
| 286 | // execute end(s) |
||
| 287 | 13 | $ends = JsonApiRuleSerializer::getRuleEndIndexes($this->getIdRule()); |
|
| 288 | 13 | $this->executeEnds($ends); |
|
| 289 | |||
| 290 | 13 | if (count($this->getErrorAggregator()) > 0) { |
|
| 291 | 1 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 292 | 1 | foreach ($this->getErrorAggregator()->get() as $error) { |
|
| 293 | 1 | $this->getJsonApiErrorCollection() |
|
| 294 | 1 | ->addDataIdError($title, $this->getMessage($error), $this->getErrorStatus()); |
|
| 295 | } |
||
| 296 | 1 | $this->getErrorAggregator()->clear(); |
|
| 297 | } |
||
| 298 | |||
| 299 | 13 | return $this; |
|
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param array $jsonData |
||
| 304 | * |
||
| 305 | * @return self |
||
| 306 | * |
||
| 307 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 308 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 309 | */ |
||
| 310 | 13 | private function validateAttributes(array $jsonData): self |
|
| 311 | { |
||
| 312 | // execute start(s) |
||
| 313 | 13 | $starts = JsonApiRuleSerializer::getRulesStartIndexes($this->getAttributeRules()); |
|
| 314 | 13 | $this->executeStarts($starts); |
|
| 315 | |||
| 316 | 13 | if (array_key_exists(DI::KEYWORD_DATA, $jsonData) === true && |
|
| 317 | 13 | array_key_exists(DI::KEYWORD_ATTRIBUTES, $data = $jsonData[DI::KEYWORD_DATA]) === true |
|
| 318 | ) { |
||
| 319 | 12 | if (is_array($attributes = $data[DI::KEYWORD_ATTRIBUTES]) === false) { |
|
| 320 | 2 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 321 | 2 | $details = $this->formatMessage(ErrorCodes::INVALID_ATTRIBUTES); |
|
| 322 | 2 | $this->getJsonApiErrorCollection()->addAttributesError($title, $details, $this->getErrorStatus()); |
|
| 323 | } else { |
||
| 324 | // execute main validation block(s) |
||
| 325 | 10 | foreach ($attributes as $name => $value) { |
|
| 326 | 8 | if (($index = $this->getAttributeIndex($name)) !== null) { |
|
| 327 | 7 | $this->executeBlock($value, $index); |
|
| 328 | 1 | } elseif ($this->isIgnoreUnknowns() === false) { |
|
| 329 | 1 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 330 | 1 | $details = $this->formatMessage(ErrorCodes::UNKNOWN_ATTRIBUTE); |
|
| 331 | 1 | $status = $this->getErrorStatus(); |
|
| 332 | 8 | $this->getJsonApiErrorCollection()->addDataAttributeError($name, $title, $details, $status); |
|
| 333 | } |
||
| 334 | } |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | // execute end(s) |
||
| 339 | 13 | $ends = JsonApiRuleSerializer::getRulesEndIndexes($this->getAttributeRules()); |
|
| 340 | 13 | $this->executeEnds($ends); |
|
| 341 | |||
| 342 | 13 | if (count($this->getErrorAggregator()) > 0) { |
|
| 343 | 2 | foreach ($this->getErrorAggregator()->get() as $error) { |
|
| 344 | 2 | $this->getJsonApiErrorCollection()->addValidationAttributeError($error); |
|
| 345 | } |
||
| 346 | 2 | $this->getErrorAggregator()->clear(); |
|
| 347 | } |
||
| 348 | |||
| 349 | 13 | return $this; |
|
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @param array $jsonData |
||
| 354 | * |
||
| 355 | * @return self |
||
| 356 | * |
||
| 357 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 358 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 359 | */ |
||
| 360 | 13 | private function validateRelationships(array $jsonData): self |
|
| 361 | { |
||
| 362 | // execute start(s) |
||
| 363 | 13 | $starts = array_merge( |
|
| 364 | 13 | JsonApiRuleSerializer::getRulesStartIndexes($this->getToOneRules()), |
|
| 365 | 13 | JsonApiRuleSerializer::getRulesStartIndexes($this->getToManyRules()) |
|
| 366 | ); |
||
| 367 | 13 | $this->executeStarts($starts); |
|
| 368 | |||
| 369 | 13 | if (array_key_exists(DI::KEYWORD_DATA, $jsonData) === true && |
|
| 370 | 13 | array_key_exists(DI::KEYWORD_RELATIONSHIPS, $data = $jsonData[DI::KEYWORD_DATA]) === true |
|
| 371 | ) { |
||
| 372 | 9 | if (is_array($relationships = $data[DI::KEYWORD_RELATIONSHIPS]) === false) { |
|
| 373 | 1 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 374 | 1 | $details = $this->formatMessage(ErrorCodes::INVALID_RELATIONSHIP_TYPE); |
|
| 375 | 1 | $this->getJsonApiErrorCollection()->addRelationshipsError($title, $details, $this->getErrorStatus()); |
|
| 376 | } else { |
||
| 377 | // ok we got to something that could be null or a valid relationship |
||
| 378 | 8 | $toOneIndexes = JsonApiRuleSerializer::getRulesIndexes($this->getToOneRules()); |
|
| 379 | 8 | $toManyIndexes = JsonApiRuleSerializer::getRulesIndexes($this->getToManyRules()); |
|
| 380 | |||
| 381 | 8 | foreach ($relationships as $name => $relationship) { |
|
| 382 | 8 | if (array_key_exists($name, $toOneIndexes) === true) { |
|
| 383 | // it might be to1 relationship |
||
| 384 | 7 | $this->validateAsToOneRelationship($toOneIndexes[$name], $name, $relationship); |
|
| 385 | 7 | } elseif (array_key_exists($name, $toManyIndexes) === true) { |
|
| 386 | // it might be toMany relationship |
||
| 387 | 6 | $this->validateAsToManyRelationship($toManyIndexes[$name], $name, $relationship); |
|
| 388 | } else { |
||
| 389 | // unknown relationship |
||
| 390 | 1 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 391 | 1 | $details = $this->formatMessage(ErrorCodes::UNKNOWN_RELATIONSHIP); |
|
| 392 | 1 | $status = $this->getErrorStatus(); |
|
| 393 | 7 | $this->getJsonApiErrorCollection()->addRelationshipError($name, $title, $details, $status); |
|
| 394 | } |
||
| 395 | } |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | // execute end(s) |
||
| 400 | 12 | $ends = array_merge( |
|
| 401 | 12 | JsonApiRuleSerializer::getRulesEndIndexes($this->getToOneRules()), |
|
| 402 | 12 | JsonApiRuleSerializer::getRulesEndIndexes($this->getToManyRules()) |
|
| 403 | ); |
||
| 404 | 12 | $this->executeEnds($ends); |
|
| 405 | |||
| 406 | 12 | if (count($this->getErrorAggregator()) > 0) { |
|
| 407 | 3 | foreach ($this->getErrorAggregator()->get() as $error) { |
|
| 408 | 3 | $this->getJsonApiErrorCollection()->addValidationRelationshipError($error); |
|
| 409 | } |
||
| 410 | 3 | $this->getErrorAggregator()->clear(); |
|
| 411 | } |
||
| 412 | |||
| 413 | 12 | return $this; |
|
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @param int $index |
||
| 418 | * @param string $name |
||
| 419 | * @param mixed $mightBeRelationship |
||
| 420 | * |
||
| 421 | * @return void |
||
| 422 | * |
||
| 423 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 424 | */ |
||
| 425 | 7 | private function validateAsToOneRelationship(int $index, string $name, $mightBeRelationship): void |
|
| 439 | |||
| 440 | /** |
||
| 441 | * @param int $index |
||
| 442 | * @param string $name |
||
| 443 | * @param mixed $mightBeRelationship |
||
| 444 | * |
||
| 445 | * @return void |
||
| 446 | * |
||
| 447 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 448 | */ |
||
| 449 | 6 | private function validateAsToManyRelationship(int $index, string $name, $mightBeRelationship): void |
|
| 450 | { |
||
| 451 | 6 | $isParsed = true; |
|
| 452 | 6 | $collectedPairs = []; |
|
| 453 | 6 | if (is_array($mightBeRelationship) === true && |
|
| 454 | 6 | array_key_exists(DI::KEYWORD_DATA, $mightBeRelationship) === true && |
|
| 455 | 6 | is_array($data = $mightBeRelationship[DI::KEYWORD_DATA]) === true |
|
| 456 | ) { |
||
| 457 | 4 | foreach ($data as $mightTypeAndId) { |
|
| 458 | // we accept only pairs of type and id (no `null`s are accepted). |
||
| 459 | 3 | if (is_array($parsed = $this->parseSingleRelationship($mightTypeAndId)) === true) { |
|
| 460 | 2 | $collectedPairs[] = $parsed; |
|
| 461 | } else { |
||
| 462 | 1 | $isParsed = false; |
|
| 463 | 4 | break; |
|
| 464 | } |
||
| 465 | } |
||
| 466 | } else { |
||
| 467 | 2 | $isParsed = false; |
|
| 468 | } |
||
| 469 | |||
| 470 | 6 | if ($isParsed === true) { |
|
| 471 | // All right we got something. Now pass it to a validation rule. |
||
| 472 | 3 | $this->executeBlock($collectedPairs, $index); |
|
| 473 | } else { |
||
| 474 | 3 | $title = $this->formatMessage(ErrorCodes::INVALID_VALUE); |
|
| 475 | 3 | $details = $this->formatMessage(ErrorCodes::INVALID_RELATIONSHIP); |
|
| 476 | 3 | $this->getJsonApiErrorCollection()->addRelationshipError($name, $title, $details, $this->getErrorStatus()); |
|
| 477 | } |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @param mixed $data |
||
| 482 | * |
||
| 483 | * @return array|null|false Either `array` ($type => $id), or `null`, or `false` on error. |
||
| 484 | * |
||
| 485 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 486 | */ |
||
| 487 | 6 | private function parseSingleRelationship($data) |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Re-initializes internal aggregators for captures, errors, etc. |
||
| 507 | */ |
||
| 508 | 19 | private function reInitAggregatorsIfNeeded(): void |
|
| 512 | |||
| 513 | /** |
||
| 514 | * @param mixed $input |
||
| 515 | * @param int $index |
||
| 516 | * |
||
| 517 | * @return void |
||
| 518 | * |
||
| 519 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 520 | */ |
||
| 521 | 17 | private function executeBlock($input, int $index): void |
|
| 532 | |||
| 533 | /** |
||
| 534 | * @param array $indexes |
||
| 535 | * |
||
| 536 | * @return void |
||
| 537 | * |
||
| 538 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 539 | */ |
||
| 540 | 18 | private function executeStarts(array $indexes): void |
|
| 549 | |||
| 550 | /** |
||
| 551 | * @param array $indexes |
||
| 552 | * |
||
| 553 | * @return void |
||
| 554 | * |
||
| 555 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 556 | */ |
||
| 557 | 18 | private function executeEnds(array $indexes): void |
|
| 558 | { |
||
| 559 | 18 | BlockInterpreter::executeEnds( |
|
| 560 | 18 | $indexes, |
|
| 561 | 18 | $this->getBlocks(), |
|
| 562 | 18 | $this->getContextStorage(), |
|
| 563 | 18 | $this->getErrorAggregator() |
|
| 564 | ); |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @param ErrorInterface $error |
||
| 569 | * |
||
| 570 | * @return string |
||
| 571 | */ |
||
| 572 | 1 | private function getMessage(ErrorInterface $error): string |
|
| 573 | { |
||
| 574 | 1 | $context = $error->getMessageContext(); |
|
| 575 | 1 | $args = $context === null ? [] : $context; |
|
| 576 | 1 | $message = $this->formatMessage($error->getMessageCode(), $args); |
|
| 577 | |||
| 578 | 1 | return $message; |
|
| 579 | } |
||
| 580 | |||
| 581 | /** |
||
| 582 | * @return array |
||
| 583 | */ |
||
| 584 | 18 | protected function getIdRule(): array |
|
| 585 | { |
||
| 586 | 18 | return $this->idRule; |
|
| 587 | } |
||
| 588 | |||
| 589 | /** |
||
| 590 | * @return array |
||
| 591 | */ |
||
| 592 | 18 | protected function getTypeRule(): array |
|
| 596 | |||
| 597 | /** |
||
| 598 | * @return ContextStorageInterface |
||
| 599 | */ |
||
| 600 | 18 | protected function getContextStorage(): ContextStorageInterface |
|
| 604 | |||
| 605 | /** |
||
| 606 | * @return ContextStorageInterface |
||
| 607 | */ |
||
| 608 | 20 | protected function createContextStorage(): ContextStorageInterface |
|
| 612 | |||
| 613 | /** |
||
| 614 | * @return JsonApiErrorCollection |
||
| 615 | */ |
||
| 616 | 13 | protected function getJsonApiErrorCollection(): JsonApiErrorCollection |
|
| 620 | |||
| 621 | /** |
||
| 622 | * @return JsonApiErrorCollection |
||
| 623 | */ |
||
| 624 | 20 | protected function createJsonApiErrors(): JsonApiErrorCollection |
|
| 628 | |||
| 629 | /** |
||
| 630 | * @return int |
||
| 631 | */ |
||
| 632 | 20 | protected function getErrorStatus(): int |
|
| 636 | |||
| 637 | /** |
||
| 638 | * @return bool |
||
| 639 | */ |
||
| 640 | 1 | protected function isIgnoreUnknowns(): bool |
|
| 641 | { |
||
| 642 | 1 | return $this->isIgnoreUnknowns; |
|
| 643 | } |
||
| 644 | |||
| 645 | /** |
||
| 646 | * @return self |
||
| 647 | */ |
||
| 648 | 1 | protected function enableIgnoreUnknowns(): self |
|
| 654 | |||
| 655 | /** |
||
| 656 | * @return self |
||
| 657 | */ |
||
| 658 | 20 | protected function disableIgnoreUnknowns(): self |
|
| 664 | |||
| 665 | /** |
||
| 666 | * @param array $rules |
||
| 667 | * |
||
| 668 | * @return self |
||
| 669 | */ |
||
| 670 | 20 | private function setAttributeRules(array $rules): self |
|
| 678 | |||
| 679 | /** |
||
| 680 | * @param array $rules |
||
| 681 | * |
||
| 682 | * @return self |
||
| 683 | */ |
||
| 684 | 20 | private function setToOneIndexes(array $rules): self |
|
| 692 | |||
| 693 | /** |
||
| 694 | * @param array $rules |
||
| 695 | * |
||
| 696 | * @return self |
||
| 697 | */ |
||
| 698 | 20 | private function setToManyIndexes(array $rules): self |
|
| 706 | |||
| 707 | /** |
||
| 708 | * @return int[] |
||
| 709 | */ |
||
| 710 | 13 | protected function getAttributeRules(): array |
|
| 711 | { |
||
| 712 | 13 | return $this->attributeRules; |
|
| 713 | } |
||
| 714 | |||
| 715 | /** |
||
| 716 | * @return int[] |
||
| 717 | */ |
||
| 718 | 13 | protected function getToOneRules(): array |
|
| 719 | { |
||
| 720 | 13 | return $this->toOneRules; |
|
| 721 | } |
||
| 722 | |||
| 723 | /** |
||
| 724 | * @return int[] |
||
| 725 | */ |
||
| 726 | 13 | protected function getToManyRules(): array |
|
| 727 | { |
||
| 728 | 13 | return $this->toManyRules; |
|
| 729 | } |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @return array |
||
| 733 | */ |
||
| 734 | 20 | private function getBlocks(): array |
|
| 738 | |||
| 739 | /** |
||
| 740 | * @return FormatterInterface |
||
| 741 | */ |
||
| 742 | 7 | protected function getMessageFormatter(): FormatterInterface |
|
| 752 | |||
| 753 | /** |
||
| 754 | * @param string $name |
||
| 755 | * |
||
| 756 | * @return int|null |
||
| 757 | * |
||
| 758 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 759 | */ |
||
| 760 | 8 | private function getAttributeIndex(string $name): ?int |
|
| 761 | { |
||
| 762 | 8 | $indexes = JsonApiRuleSerializer::getRulesIndexes($this->getAttributeRules()); |
|
| 763 | 8 | $index = $indexes[$name] ?? null; |
|
| 764 | |||
| 765 | 8 | return $index; |
|
| 766 | } |
||
| 767 | |||
| 768 | /** |
||
| 769 | * @param int $messageId |
||
| 770 | * @param array $args |
||
| 771 | * |
||
| 772 | * @return string |
||
| 773 | */ |
||
| 774 | 7 | private function formatMessage(int $messageId, array $args = []): string |
|
| 780 | |||
| 781 | /** |
||
| 782 | * @param array $rules |
||
| 783 | * |
||
| 784 | * @return bool |
||
| 785 | * |
||
| 786 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 787 | */ |
||
| 788 | 20 | private function debugCheckIndexesExist(array $rules): bool |
|
| 804 | } |
||
| 805 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.