Commit db399a75 authored by Tim Rohaly's avatar Tim Rohaly Committed by Tim Rohaly
Browse files

Issue #3276530 by TR: Add return type hints to service methods

parent a1eae61f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ class HoneypotService implements HoneypotServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function getProtectedForms() {
  public function getProtectedForms(): array {
    $forms = &drupal_static(__METHOD__);

    // If the data isn't already in memory, get from cache or look it up fresh.
@@ -167,7 +167,7 @@ class HoneypotService implements HoneypotServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function getTimeLimit(array $form_values = []) {
  public function getTimeLimit(array $form_values = []): int {
    $honeypot_time_limit = $this->config->get('time_limit');

    // Only calculate time limit if honeypot_time_limit has a value > 0.
@@ -207,7 +207,7 @@ class HoneypotService implements HoneypotServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function addFormProtection(array &$form, FormStateInterface $form_state, array $options = []) {
  public function addFormProtection(array &$form, FormStateInterface $form_state, array $options = []): void {
    // Allow other modules to alter the protections applied to this form.
    $this->moduleHandler->alter('honeypot_form_protections', $options, $form);

@@ -354,7 +354,7 @@ class HoneypotService implements HoneypotServiceInterface {
   *   - honeypot: If honeypot field was filled in.
   *   - honeypot_time: If form was completed before the configured time limit.
   */
  protected function log($form_id, $type) {
  protected function log($form_id, $type): void {
    $this->logFailure($form_id, $type);
    if ($this->config->get('log')) {
      $variables = [
@@ -368,7 +368,7 @@ class HoneypotService implements HoneypotServiceInterface {
  /**
   * {@inheritdoc}
   */
  public function logFailure($form_id, $type) {
  public function logFailure($form_id, $type): void {
    $uid = $this->account->id();

    // Log failed submissions.
+4 −4
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ interface HoneypotServiceInterface {
   *   An array whose values are the form_ids of all the protected forms
   *   on the site.
   */
  public function getProtectedForms();
  public function getProtectedForms(): array;

  /**
   * Looks up the time limit for the current user.
@@ -27,7 +27,7 @@ interface HoneypotServiceInterface {
   * @return int
   *   The time limit in seconds.
   */
  public function getTimeLimit(array $form_values = []);
  public function getTimeLimit(array $form_values = []): int;

  /**
   * Adds honeypot protection to provided form.
@@ -40,7 +40,7 @@ interface HoneypotServiceInterface {
   *   (optional) Array of options to be added to form. Currently accepts
   *   'honeypot' and 'time_restriction'.
   */
  public function addFormProtection(array &$form, FormStateInterface $form_state, array $options = []);
  public function addFormProtection(array &$form, FormStateInterface $form_state, array $options = []): void;

  /**
   * Logs the failed submission with timestamp and hostname.
@@ -52,6 +52,6 @@ interface HoneypotServiceInterface {
   *   - honeypot: If honeypot field was filled in.
   *   - honeypot_time: If form was completed before the configured time limit.
   */
  public function logFailure($form_id, $type);
  public function logFailure($form_id, $type): void;

}