Passed
Push — 8.x-2.x ( 9af07d...3011f1 )
by Frédéric G.
05:35
created

ClearConfirmForm::getQuestion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Drupal\mongodb_watchdog\Form;
6
7
use Drupal\Core\Form\ConfirmFormBase;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Form\ConfirmFormBase 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 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...
9
use Drupal\Core\StringTranslation\TranslatableMarkup;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\StringTranslation\TranslatableMarkup 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...
10
use Drupal\Core\Url;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Url 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...
11
use Drupal\mongodb_watchdog\Logger;
12
use MongoDB\Database;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface 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...
14
15
/**
16
 * Provides a confirmation form before clearing out the logs.
17
 *
18
 * D8 has no session API, so use of $_SESSION is required, so ignore warnings.
19
 *
20
 * @SuppressWarnings("PHPMD.Superglobals")
21
 */
22
class ClearConfirmForm extends ConfirmFormBase {
23
24
  /**
25
   * The logger database.
26
   *
27
   * @var \MongoDB\Database
28
   */
29
  protected $database;
30
31
  /**
32
   * The MongoDB watchdog "logger" service.
33
   *
34
   * @var \Drupal\mongodb_watchdog\Logger
35
   */
36
  protected $logger;
37
38
  /**
39
   * ClearConfirmForm constructor.
40
   *
41
   * @param \MongoDB\Database $database
42
   *   The MongoDB logger database.
43
   * @param \Drupal\mongodb_watchdog\Logger $logger
44
   *   The mongodb.logger service.
45
   */
46
  public function __construct(Database $database, Logger $logger) {
47
    $this->database = $database;
48
    $this->logger = $logger;
49
  }
50
51
  /**
52
   * {@inheritdoc}
53
   */
54
  public static function create(ContainerInterface $container): self {
55
    return new static(
56
      $container->get('mongodb.watchdog_storage'),
57
      $container->get(Logger::SERVICE_LOGGER)
58
    );
59
  }
60
61
  /**
62
   * {@inheritdoc}
63
   */
64
  public function getFormId(): string {
65
    return 'mongodb_watchdog_clear_confirm';
66
  }
67
68
  /**
69
   * {@inheritdoc}
70
   */
71
  public function getQuestion(): TranslatableMarkup {
72
    return $this->t('Are you sure you want to delete the recent logs?');
73
  }
74
75
  /**
76
   * {@inheritdoc}
77
   */
78
  public function getCancelUrl(): Url {
79
    return new Url('mongodb_watchdog.reports.overview');
80
  }
81
82
  /**
83
   * {@inheritdoc}
84
   */
85
  public function submitForm(array &$form, FormStateInterface $formState): void {
86
    $_SESSION['mongodb_watchdog_overview_filter'] = [];
87
    $this->database->drop();
88
    $this->logger->ensureSchema();
89
    $this->messenger()->addMessage($this->t('Database log cleared.'));
90
    $formState->setRedirectUrl($this->getCancelUrl());
91
  }
92
93
}
94