Change $options parameter to satisfy phpstan

Created on 26 June 2024, 5 months ago
Updated 17 August 2024, 3 months ago

Problem/Motivation

Getting php stan errors/flags when calling ApStyleDateFormatter->formatTimestamp with custom options.

Steps to reproduce

In custom code, call in the ApStyleDateFormatter service and call the formatTimestamp method to format a date, with custom options. For example:

$ap_date_formatter = \Drupal::service('date_ap_style.formatter');
$ap_date_format = [
    'display_time' => FALSE,
    'always_display_year' => TRUE,
  ];
...
$ap_date = $ap_date_formatter->formatTimestamp(strtotime($dates['start']), $ap_date_format);

Code works/executes just fine, but custom code gets flagged with php stan error:

Parameter #2 $options of method Drupal\date_ap_style\ApStyleDateFormatter::formatTimestamp() expects  array<string>, array<string, bool> given.   

Proposed resolution

Change codehint in declaration to:

   * @param array<string,bool> $options

Since all configs appear to be bool values this should be fine.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States billdaff

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024