MongodbWatchdogServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A alter() 0 25 4
1
<?php
2
3
namespace Drupal\mongodb_watchdog;
4
5
use Drupal\Core\DependencyInjection\ContainerBuilder;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\DependencyInjection\ContainerBuilder 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 Drupal\Core\DependencyInjection\ServiceModifierInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\DependencyIn...erviceModifierInterface 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\DependencyInjection\Reference;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\DependencyInjection\Reference 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
9
/**
10
 * MongodbWatchdogServiceProvider add $formState support to forms.
11
 */
12
class MongodbWatchdogServiceProvider implements ServiceModifierInterface {
13
14
  const KERNEL_RESOLVER = 'http_kernel.controller.argument_resolver';
15
16
  // Individual resolvers.
17
  const RESOLVER_DEFAULT = 'argument_resolver.default';
18
  const RESOLVER_FORM_STATE = 'argument_resolver.mongodb_watchdog.form_state';
19
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public function alter(ContainerBuilder $container): void {
24
    $kernelResolverDefinition = $container
25
      ->getDefinition(static::KERNEL_RESOLVER);
26
    $resolvers = $kernelResolverDefinition->getArgument(1);
27
    $defaultIndex = $count = count($resolvers);
28
    /** @var \Symfony\Component\DependencyInjection\Reference $reference */
29
    foreach ($resolvers as $index => $reference) {
30
      if ("$reference" === static::RESOLVER_DEFAULT) {
31
        $defaultIndex = $index;
32
        break;
33
      }
34
    }
35
36
    $formStateResolverReference = new Reference(static::RESOLVER_FORM_STATE);
37
38
    // If the default resolved is present, insert just before it.
39
    if ($defaultIndex != $count) {
40
      array_splice($resolvers, $defaultIndex, 0, [$formStateResolverReference]);
41
    }
42
    // Else add the formState resolver at the end of the list.
43
    else {
44
      array_push($resolvers, [$formStateResolverReference]);
45
    }
46
47
    $kernelResolverDefinition->setArgument(1, $resolvers);
48
  }
49
50
}
51