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: static analysis check errors #129

Merged
merged 4 commits into from
Aug 27, 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_elections.module
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function localgov_elections_menu_local_tasks_alter(&$data, $route_name) {

// Add the "add area" button to the local tasks if user has permission.
$can_add_areas = Drupal::currentUser()->hasPermission('can fetch boundaries');
if ($can_add_areas && in_array($route_name, $appropriate_fetch_routes)) {
if ($can_add_areas && in_array($route_name, $appropriate_fetch_routes, TRUE)) {
$data['tabs'][0]['boundary_fetch'] = [
'#theme' => 'menu_local_task',
'#weight' => 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
// seen before. It needs to be in the dataset.
$constituencies = $this->cacheBackend->get(CacheKey::CONSTITUENCY_NAMES_KEY)?->data;
foreach ($values as $val) {
if (!in_array($val, $constituencies)) {
if (!in_array($val, $constituencies, TRUE)) {
$form_state->setErrorByName('constituencies', "$val does not seem to be a valid choice.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testConstituencyLookupEndpoint(): void {

$this->assertIsArray($response);

$this->assertTrue(in_array(['label' => 'Edinburgh South West', 'value' => 'Edinburgh South West'], $response));
$this->assertTrue(in_array(['value' => 'Edinburgh South West', 'label' => 'Edinburgh South West'], $response, TRUE));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function fetchBoundaryInformation($lad, $ids): array {
$matched_features = [];
if ($response->getStatusCode() == 200) {
foreach ($json_decoded['features'] as $feature) {
if (in_array($feature['properties']['WD23CD'], $ids)) {
if (in_array($feature['properties']['WD23CD'], $ids, TRUE)) {
$matched_features[] = $feature;
$num_matched++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected function getTokenizedMessage($form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state): void {
$keys = array_keys($form_state->get('original_data')['account']);
$accounts = array_filter($this->userManager->getAccounts('social_post_twitter'), function ($obj) use ($keys) {
return in_array($obj->id(), $keys);
return in_array($obj->id(), $keys, TRUE);
});

$message = $form_state->getValue('preview');
Expand Down
10 changes: 10 additions & 0 deletions src/Annotation/BoundaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@
/**
* Defines boundary_provider annotation object.
*
* @see plugin_api
*
* @Annotation
*/
class BoundaryProvider extends Plugin {

/**
* The plugin ID.
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public readonly string $id;

/**
* The human-readable name of the plugin.
*
* @ingroup plugin_translatable
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public readonly string $title;

/**
* The description of the plugin.
*
* @ingroup plugin_translatable
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public readonly string $description;

Expand All @@ -39,6 +47,8 @@ class BoundaryProvider extends Plugin {
* form at the moment.
*
* @returns array
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public array $form = [];

Expand Down
3 changes: 2 additions & 1 deletion src/Plugin/Block/AnalysisBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function build() {
}

// Display majority if we can.
if ($display_majority && isset($majority)) {
if ($display_majority && !is_null($majority)) {
$markup .= '<div class="results-analysis-grid__label results-analysis-grid__label--majority">Majority</div>';
$markup .= '<div class="results-analysis-grid__value results-analysis-grid__value--majority">' . $majority . '</div>';
}
Expand All @@ -118,6 +118,7 @@ public function build() {
$previous_year = $node->localgov_election_previous_year->value;
$previous_winning_party = $node->localgov_election_prev_winner->entity;
$previous_result = $node->localgov_election_prev_result->referencedEntity;
$previous_winner_abbr = '';
if (isset($previous_winning_party)) {
$previous_winner_abbr = $previous_winning_party->localgov_election_abbreviation->value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/field/ElectionSeatsParty.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function render(ResultRow $values) {

// Find party of Ward/Area/Division winning candidate.
$winning_cand_id = $ward->get('localgov_election_winner')->target_id;
if (isset($winning_cand_id)) {
if (!is_null($winning_cand_id)) {
$winning_cand = Paragraph::load($winning_cand_id);
if (isset($winning_cand)) {
$winning_party = $winning_cand->get('localgov_election_party')->target_id;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Functional/ElectionAliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function setUp(): void {
]);
$file->save();

$this->area_vote = $this->nodeStorage->create([
$this->areaVote = $this->nodeStorage->create([
'title' => "An area",
'status' => TRUE,
'type' => "localgov_area_vote",
Expand All @@ -104,7 +104,7 @@ protected function setUp(): void {
'coordinates' => [1.234567, 2.345678],
]),
]);
$this->area_vote->save();
$this->areaVote->save();

// Map page.
$map_page_url = Url::fromRoute('view.localgov_election_electoral_map.page_1',
Expand Down
Loading