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

fix: strict types errors #401

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion localgov_directories.install
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function localgov_directories_update_8004() {
// Place under title field.
$form_group_description = $form_display->getThirdPartySetting('field_group', 'group_description');
if (!empty($form_group_description) &&
(($title_position = array_search('title', $form_group_description['children'])) !== FALSE)
(($title_position = array_search('title', $form_group_description['children'], TRUE)) !== FALSE)
) {
array_splice($form_group_description['children'], $title_position + 1, 0, 'localgov_directory_title_sort');
$form_display->setThirdPartySetting('field_group', 'group_description', $form_group_description);
Expand Down
2 changes: 1 addition & 1 deletion localgov_directories.module
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function localgov_directories_localgov_roles_default() {
* Implements hook_modules_installed().
*/
function localgov_directories_modules_installed($modules) {
$services = in_array('localgov_services_navigation', $modules);
$services = in_array('localgov_services_navigation', $modules, TRUE);
if ($services) {
\Drupal::service('config.installer')->installOptionalConfig(NULL, [
'config' => 'field.storage.node.localgov_services_parent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InstallTest extends KernelTestBase {
* {@inheritdoc}
*/
public function setUp(): void {
parent::setup();
parent::setUp();

$this->installEntitySchema('node');
$this->installEntitySchema('search_api_index');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function localgov_directories_location_field_config_insert(FieldConfigInterface
if (in_array($new_field_name, [
Directory::CHANNEL_SELECTION_FIELD,
Directory::TITLE_SORT_FIELD,
]) && $is_node_entity_type && $index) {
], TRUE) && $is_node_entity_type && $index) {
// The channel selection and title sort fields may have gone missing from
// the search index when we added localgov_location.
$proximity_search_setup->repairSearchIndex($index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function setupLocationSearch(FieldConfigInterface $field, SearchIndexInte

$entity_bundle = $field->getTargetBundle();
$datasrc_cfg = $index_datasrc->getConfiguration();
$is_bundle_indexed = in_array($entity_bundle, $datasrc_cfg['bundles']['selected']);
$is_bundle_indexed = in_array($entity_bundle, $datasrc_cfg['bundles']['selected'], TRUE);
if (!$is_bundle_indexed) {
$datasrc_cfg['bundles']['selected'][] = $entity_bundle;
$index_datasrc->setConfiguration($datasrc_cfg);
Expand Down
4 changes: 2 additions & 2 deletions modules/localgov_directories_or/src/FacetMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function synchroniseFacetMappings() {
->accessCheck(TRUE)
->execute();
foreach ($facet_query as $facet_type) {
if (in_array($facet_type, $openreferral_facets) &&
if (in_array($facet_type, $openreferral_facets, TRUE) &&
!$mapping_storage->load('localgov_directories_facets.' . $facet_type)
) {
$facet_mapping = $mapping_storage->create([
Expand All @@ -92,7 +92,7 @@ public function synchroniseFacetMappings() {
]);
$facet_mapping->save();
}
if (!in_array($facet_type, $openreferral_facets) &&
if (!in_array($facet_type, $openreferral_facets, TRUE) &&
($facet_mapping = $mapping_storage->load('localgov_directories_facets.' . $facet_type))
) {
$facet_mapping->delete();
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected function indexAddBundle(IndexInterface $index, string $entity_type_id,

$configuration = $datasource->getConfiguration();
$configuration['bundles']['default'] = FALSE;
if (!in_array($entity_bundle, $configuration['bundles']['selected'])) {
if (!in_array($entity_bundle, $configuration['bundles']['selected'], TRUE)) {
$configuration['bundles']['selected'][] = $entity_bundle;
}
$datasource->setConfiguration($configuration);
Expand All @@ -469,7 +469,7 @@ protected function indexRemoveBundle(IndexInterface $index, string $entity_type_

$configuration = $datasource->getConfiguration();
$configuration['bundles']['default'] = FALSE;
if (($key = array_search($entity_bundle, $configuration['bundles']['selected'])) !== FALSE) {
if (($key = array_search($entity_bundle, $configuration['bundles']['selected'], TRUE)) !== FALSE) {
unset($configuration['bundles']['selected'][$key]);
}
$datasource->setConfiguration($configuration);
Expand Down
25 changes: 14 additions & 11 deletions src/Plugin/facets/query_type/LocalGovDirectoriesQueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function execute() {
$query = $this->query;

// Only alter the query when there's an actual query object to alter.
// @phpstan-ignore-next-line.
if (!empty($query)) {
$operator = $this->facet->getQueryOperator();
$field_identifier = $this->facet->getFieldIdentifier();
Expand All @@ -39,22 +40,24 @@ public function execute() {
$active_items = $this->facet->getActiveItems();

if (count($active_items)) {

$bundle = NULL;
$type_storage = \Drupal::entityTypeManager()
->getStorage('localgov_directories_facets');
$chosen_facets = $type_storage->loadMultiple($active_items);
foreach ($chosen_facets as $directory_facet) {
$bundle[$directory_facet->bundle()][] = $directory_facet->id();
}

$filter = NULL;
foreach ($bundle as $bundle_name => $group_items) {
unset($filter);
$filter = $query->createConditionGroup($operator, ['facet:' . $field_identifier . '.' . $bundle_name]);
foreach ($group_items as $value) {
$filter->addCondition($this->facet->getFieldIdentifier(), $value, $exclude ? '<>' : '=');
if ($bundle !== NULL) {
$filter = NULL;
foreach ($bundle as $bundle_name => $group_items) {
unset($filter);
$filter = $query->createConditionGroup($operator, ['facet:' . $field_identifier . '.' . $bundle_name]);
foreach ($group_items as $value) {
$filter->addCondition($this->facet->getFieldIdentifier(), $value, $exclude ? '<>' : '=');
}
$query->addConditionGroup($filter);
}
$query->addConditionGroup($filter);
}
}
}
Expand Down Expand Up @@ -93,7 +96,7 @@ public function build() {
// Remove any duplicate facets, or they show up multiple times.
$group_facets_filtered = array_filter($group_facets, function ($item) use ($results) {
$facet_ids = array_column($results, 'filter');
if (in_array($item['filter'], $facet_ids)) {
if (in_array($item['filter'], $facet_ids, TRUE)) {
return FALSE;
}
return TRUE;
Expand Down Expand Up @@ -157,7 +160,7 @@ protected function getResultingFacetsWithOwnFacetGroup(string $filter_tag): arra
$cids = $condition->getTags();

// @todo Check that we are only removing facet conditions.
if (in_array($filter_tag, $cids)) {
if (in_array($filter_tag, $cids, TRUE)) {

// Store the removed conditions and remove it.
$removed_conditions[$cid] = $conditions[$cid];
Expand Down Expand Up @@ -187,7 +190,7 @@ protected function getResultingFacetsWithOwnFacetGroup(string $filter_tag): arra
->execute();
$found_facets = $facets['localgov_directory_facets_filter'] ?? [];
$found_facets = array_filter($found_facets, function ($item) use ($group_facet_ids) {
if (in_array(intval(trim($item['filter'], '"')), $group_facet_ids)) {
if (in_array(intval(trim($item['filter'], '"')), array_map('intval', $group_facet_ids), TRUE)) {
return TRUE;
}
return FALSE;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Unit/FacetPreprocessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function testFacetTypeSorting() {
*
* @see DirectoryExtraFieldDisplay::__construct()
*/
public function setup(): void {
parent::setup();
public function setUp(): void {
parent::setUp();

// Facet items.
$facet_zero = $this->createMock(LocalgovDirectoriesFacets::class);
Expand Down