FormStateValueResolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Drupal\mongodb_watchdog\Controller\ArgumentResolver;
4
5
use Drupal\Core\Form\FormStateInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Form\FormStateInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...tValueResolverInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...tadata\ArgumentMetadata was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Yields a form_state argument for FormStateInterface $formState arguments.
12
 *
13
 * This resolver supports form methods with a FormStateInterface argument
14
 * regardless of its name.
15
 */
16
class FormStateValueResolver implements ArgumentValueResolverInterface {
17
18
  const NAME_LEGACY = 'form_state';
19
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public function supports(Request $request, ArgumentMetadata $argument): bool {
24
    $argumentInterfaceMatches = $argument->getType() === FormStateInterface::class;
25
    $requestAttributeExists = $request->attributes->has(static::NAME_LEGACY);
26
    return $argumentInterfaceMatches && $requestAttributeExists;
27
  }
28
29
  /**
30
   * {@inheritdoc}
31
   *
32
   * @return \Generator
33
   *   Returns the argument values.
34
   */
35
  public function resolve(Request $request, ArgumentMetadata $argument): iterable {
36
    $formState = $request->attributes->has(static::NAME_LEGACY)
37
      ? $request->attributes->get(static::NAME_LEGACY)
38
      : NULL;
39
    yield $formState;
40
  }
41
42
}
43