Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USAGOV-2197 phpstan ssg postprocessing #2201

Merged
merged 20 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bc82474
USAGOV-2197-phpstan-ssg-postprocessing: First attempt at fixing PhpSt…
arpage Jan 27, 2025
6c307ea
USAGOV-2197-phpstan-ssg-postprocessing: Allow CCI build
arpage Jan 27, 2025
fb2a54f
USAGOV-2197-phpstan-ssg-postprocessing: Fix syntax errors
arpage Jan 27, 2025
1bf338c
USAGOV-2197-phpstan-ssg-postprocessing: Fix syntax error
arpage Jan 27, 2025
a8f4fe1
USAGOV-2197-phpstan-ssg-postprocessing: Fixed more syntax errors
arpage Jan 27, 2025
ddedc51
USAGOV-2197-phpstan-ssg-postprocessing: Syntax Errors
arpage Jan 27, 2025
b95c88c
USAGOV-2197-phpstan-ssg-postprocessing: Drupal syntax errors
arpage Jan 27, 2025
2c31a4a
USAGOV-2197-phpstan-ssg-postprocessing: if FormBase is given as the a…
arpage Jan 27, 2025
d6b53a0
USAGOV-2197-phpstan-ssg-postprocessing: Specifying LanguageManager as…
arpage Jan 28, 2025
600c547
USAGOV-2197-phpstan-ssg-postprocessing: Change mixed to static, fix i…
arpage Jan 29, 2025
8cbfff6
USAGOV-2197-phpstan-ssg-postprocessing: Remove CCI branch exception
arpage Jan 29, 2025
592be9a
Merge branch 'dev' into USAGOV-2197-phpstan-ssg-postprocessing
omerida Jan 29, 2025
7382a94
Merge branch 'dev' into USAGOV-2197-phpstan-ssg-postprocessing
arpage Feb 2, 2025
46af971
USAGOV-2197-phpstan-ssg-postprocessing: Update typehints per code review
arpage Feb 2, 2025
1336124
USAGOV-2197-phpstan-ssg-postprocessing: Merge branch 'USAGOV-2197-php…
arpage Feb 2, 2025
1687720
USAGOV-2197-phpstan-ssg-postprocessing: Testing build via CircleCI
arpage Feb 2, 2025
160a3a8
USAGOV-2197-phpstan-ssg-postprocessing: fix yaml syntax error
arpage Feb 2, 2025
75be8ac
USAGOV-2197-phpstan-ssg-postprocessing: Adding typehint for Taxonomy …
omerida Feb 3, 2025
9492d53
USAGOV-2197-phpstan-ssg-postprocessing: Remove testing branches from …
arpage Feb 3, 2025
b8ed2db
USAGOV-2197-phpstan-ssg-postprocessing: Merge branch 'USAGOV-2197-php…
arpage Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public function __construct(
) {
}

public function content() {
/**
* @return array<mixed>
*/
public function content(): array {
$date = $this->state()->get('ssg_stat_date');
$msg = $this->state()->get('ssg_stat_msg');

Expand All @@ -30,11 +33,13 @@ public function content() {
return ['#markup' => $markup, '#cache' => ['max-age' => 0]];
}

/*
* This is a utility use in order to test what the WAF and proxies will do with wait-timeouts.
* See ticket USAGOV-1927.
/**
* This is a utility. Use in order to test what the WAF and proxies will do with wait-timeouts
* See ticket USAGOV-1927
*
* @return array<mixed>
*/
public function siteLagTest() {
public function siteLagTest(): array {

$request = $this->requestStack->getCurrentRequest();
$waitParam = $request->query->get('wait');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function __construct(
public readonly string $pageLanguage,
) {}

/**
* @param array<mixed> $data
*/
private static function getHierarchy(array $data): int {
$texts = array_filter($data, fn($key) => str_starts_with($key, 'Taxonomy_URL_'), ARRAY_FILTER_USE_KEY);
return count(array_unique($texts));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Breadcrumb\ChainBreadcrumbBuilderInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteMatchInterface;
Expand All @@ -30,6 +31,9 @@
*/
final class PublishedPagesCommands extends DrushCommands {

/**
* @var array<string> $csvHeader
*/
private array $csvHeader = [
"Hierarchy Level",
"Page Type",
Expand Down Expand Up @@ -71,7 +75,7 @@ public function __construct(
parent::__construct();
}

public static function create(ContainerInterface $container) {
public static function create(ContainerInterface $container): static {
return new static(
entityTypeManager: $container->get('entity_type.manager'),
configFactory: $container->get('config.factory'),
Expand All @@ -93,7 +97,7 @@ public static function create(ContainerInterface $container) {
name: 'usagov_ssg_postprocessing:published-csv',
description: 'Usage description')
]
public function publishedCsv($outfile) {
public function publishedCsv(mixed $outfile): void {
$this->output()->writeln('<info>Publishing CSV to ' . $outfile . '</info>');

$out = fopen($outfile, 'w');
Expand All @@ -113,7 +117,7 @@ public function publishedCsv($outfile) {
fclose($out);
}

protected function saveNodeRows($out): void {
protected function saveNodeRows(mixed $out): void {
$nids = $this->entityTypeManager
->getStorage('node')
->getQuery()
Expand Down Expand Up @@ -168,7 +172,7 @@ protected function saveNodeRows($out): void {
}
}

protected function saveNodeRow($out, $node, $row): void {
protected function saveNodeRow(mixed $out, Node $node, mixed $row): void {

$row = array_map(fn($col) => trim($col), $row);
fputcsv($out, $row);
Expand All @@ -187,7 +191,7 @@ protected function saveNodeRow($out, $node, $row): void {
}
}

protected function saveWizardRows($out): void {
protected function saveWizardRows(mixed $out): void {
$tids = $this->entityTypeManager
->getStorage('taxonomy_term')
->getQuery()
Expand Down Expand Up @@ -263,6 +267,10 @@ protected function getWizardRow(Term $wizard): PublishedPagesRow {
return PublishedPagesRow::datalayerForWizard($data, $wizard, $baseURL);
}

/**
* @param array<mixed> $data
* @return array<mixed>
*/
private function alterDatalayer(array $data): array {
// Let other modules add to the datalayer payload.
$datalayerEvent = new DatalayerAlterEvent($data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PagerPathSubscriber implements EventSubscriberInterface {
* @param \Drupal\tome_static\Event\ModifyDestinationEvent $event
* The event.
*/
public function modifyDestination(ModifyDestinationEvent $event) {
public function modifyDestination(ModifyDestinationEvent $event): void {
$destination = $event->getDestination();
$new_destination = $this->modifyUrl($destination);
if ($destination != $new_destination) {
Expand All @@ -35,7 +35,7 @@ public function modifyDestination(ModifyDestinationEvent $event) {
* @param \Drupal\tome_static\Event\ModifyHtmlEvent $event
* The event.
*/
public function modifyHtml(ModifyHtmlEvent $event) {
public function modifyHtml(ModifyHtmlEvent $event): void {
$html = $event->getHtml();
$path = $event->getPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Lan
* @param \Drupal\tome_static\Event\CollectPathsEvent $event
* The collect paths event.
*/
public function excludeDirectories(CollectPathsEvent $event) {
public function excludeDirectories(CollectPathsEvent $event): void {
$excluded_directories = self::getExcludedDirectories();
$paths = $event->getPaths(TRUE);
foreach ($paths as $path => $metadata) {
Expand Down Expand Up @@ -117,10 +117,10 @@ public function excludeDirectories(CollectPathsEvent $event) {
/**
* Returns per-site excluded directory paths.
*
* @return array
* @return array<mixed>
* An array of excluded paths.
*/
public static function getExcludedDirectories() {
public static function getExcludedDirectories(): array {
$excluded_paths = [];
$site_paths = Settings::get('usagov_tome_static_path_exclude_directories', []);
if (is_array($site_paths)) {
Expand All @@ -138,7 +138,7 @@ public static function getExcludedDirectories() {
* @param \Drupal\tome_static\Event\ModifyHtmlEvent $event
* The event.
*/
public function modifyHtml(ModifyHtmlEvent $event) {
public function modifyHtml(ModifyHtmlEvent $event): void {
$html = $event->getHtml();
$html5 = new HTML5();

Expand Down Expand Up @@ -233,6 +233,9 @@ public function addAgencyIndexes(CollectPathsEvent $event): void {

}

/**
* @return array<mixed>
arpage marked this conversation as resolved.
Show resolved Hide resolved
*/
private function getLetters(ViewExecutable $view): array {
$view->execute();
$letters = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;

/**
* Implements hook_entity_view_alter().
* Implements hook_entity_view_alter()
*
* From Drupal.org -> "If a module wishes to act on the rendered HTML of the
* ntity rather than the structured content array, it may use this hook to add
* a #post_render callback."
*
* @param array<mixed> &$build
arpage marked this conversation as resolved.
Show resolved Hide resolved
*/
function usagov_ssg_postprocessing_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
function usagov_ssg_postprocessing_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display): void {
usagov_ssg_postprocessing_remove_shortlink($build);
usagov_ssg_postprocessing_modify_canonical_link($build);
}

function usagov_ssg_postprocessing_remove_shortlink(array &$attachments) {
function usagov_ssg_postprocessing_remove_shortlink(array &$attachments): void {
arpage marked this conversation as resolved.
Show resolved Hide resolved
if (!isset($attachments['#attached']['html_head_link'])) {
return;
}
Expand All @@ -27,7 +29,7 @@ function usagov_ssg_postprocessing_remove_shortlink(array &$attachments) {
}
}

function usagov_ssg_postprocessing_modify_canonical_link(array &$attachments) {
function usagov_ssg_postprocessing_modify_canonical_link(array &$attachments): void {
arpage marked this conversation as resolved.
Show resolved Hide resolved
if (!isset($attachments['#attached']['html_head_link'])) {
return;
}
Expand All @@ -44,10 +46,12 @@ function usagov_ssg_postprocessing_modify_canonical_link(array &$attachments) {
}

/**
* Implements hook_page_attachments_alter.
* We just want to add / to the alternate links on the home pages.
* Implements hook_page_attachments_alter
*
* @param array<mixed> &$attachments
arpage marked this conversation as resolved.
Show resolved Hide resolved
* We just want to add / to the alternate links on the home pages
*/
function usagov_ssg_postprocessing_page_attachments_alter(array &$attachments) {
function usagov_ssg_postprocessing_page_attachments_alter(array &$attachments): void {
if (!isset($attachments['#attached']['html_head_link'])) {
return;
}
Expand All @@ -70,29 +74,29 @@ function usagov_ssg_postprocessing_page_attachments_alter(array &$attachments) {
/**
* Static Site Generation Toggle State Form ID
*/
function usagov_ssg_postprocessing_get_static_state_form_id() {
function usagov_ssg_postprocessing_get_static_state_form_id(): string {
return 'toggle_static_site_generation_form';
}

/**
* Static Site Generation Toggle State Form Button Name
*/
function usagov_ssg_postprocessing_get_static_state_button_name() {
function usagov_ssg_postprocessing_get_static_state_button_name(): string {
return 'confirm_toggle';
}

/**
* Toggle State variable name for sset/sget/sdel
*/
function usagov_ssg_postprocessing_get_static_state_var() {
function usagov_ssg_postprocessing_get_static_state_var(): string {
return 'usagov.tome_run_disabled';
}

/**
* Implements hook_form_alter().
* Static Site Generation form text updates.
*/
function usagov_ssg_postprocessing_form_alter(&$form, &$form_state, $form_id) {
function usagov_ssg_postprocessing_form_alter(mixed &$form, mixed &$form_state, string $form_id): void {
arpage marked this conversation as resolved.
Show resolved Hide resolved
if ($form_id == usagov_ssg_postprocessing_get_static_state_form_id()) {
$toggle_state = \Drupal::state()->get(usagov_ssg_postprocessing_get_static_state_var()) ? 1 : 0;
$form_state->setValue(usagov_ssg_postprocessing_get_static_state_button_name(), $toggle_state ? TRUE : FALSE);
Expand Down
Loading