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

Issue #3432191: Fix PHPStan warnings from Drupal upgrade #3825

Merged
merged 3 commits into from May 23, 2024

Conversation

vcsvinicius
Copy link
Contributor

@vcsvinicius vcsvinicius commented Mar 19, 2024

Problem

The last Drupal upgrade start to throw some PHPStan warnings and to continue with the upgrade these warnings was added to be ignored by PHPStan.

The PHPStan ignore added can be check here: https://github.com/goalgorilla/open_social/pull/3806/commits/14894189009...

Solution

Fix these warnings and remove it from PHPStan ignore.

Issue tracker

PROD-28482
#3432191

Theme issue tracker

N/A

How to test

N/A

Definition of done

Before merge

  • Code/peer review is completed
  • All commit messages are clear and clean. If applicable a rebase was performed
  • All automated tests are green
  • Functional/manual tests of the acceptance criteria are approved
  • All acceptance criteria were met
  • New features or changes to existing features are covered by tests, either unit (preferably) or behat
  • Update path is tested. New hook_updates should respect update order, right naming convention and consider hook_post_update code
  • Module can be safely uninstalled. Update/implement hook_uninstall and make sure that removed configuration or dependencies are removed/uninstalled
  • This pull request has all required labels (team/type/priority)
  • This pull request has a milestone
  • This pull request has an assignee (if applicable)
  • Any front end changes are tested on all major browsers
  • New UI elements, or changes on UI elements are approved by the design team
  • New features, or feature changes are approved by the product owner

After merge

  • Code is tested on all branches that it has been cherry-picked
  • Update hook number might need adjustment, make sure they have the correct order
  • The Drupal.org ticket(s) are updated according to this pull request status

Screenshots

N/A

Release notes

Fixed errors ignored from last Drupal upgrade.

Change Record

N/A

Translations

N/A

@vcsvinicius vcsvinicius added status: needs review This pull request is waiting for a requested review prio: high type: repository Improvements to working with the repository (e.g. templates, README files, or workflows) team: guardians labels Mar 19, 2024
@vcsvinicius vcsvinicius added this to the 12.4.0 milestone Mar 19, 2024
@vcsvinicius vcsvinicius requested a review from a team March 19, 2024 17:55
Copy link

mergeable bot commented Mar 19, 2024

Thanks for contributing towards Open Social! A maintainer from the @goalgorilla/maintainers group might not review all changes from all teams/contributors. Please don't be discouraged if it takes a while. In the meantime, we have some automated checks running and it might be that you will see our comments with some tips or requests to speed up the review process. 😊

@vcsvinicius vcsvinicius changed the title Issue #/3432191: Fix PHPStan warnings from Drupal upgrade Issue #3432191: Fix PHPStan warnings from Drupal upgrade Mar 19, 2024
@vcsvinicius vcsvinicius force-pushed the feature/3432191/fix-phpstan-warnings branch from 8c32e2f to 9feada7 Compare March 19, 2024 19:02
@@ -94,7 +94,7 @@ public function enabled() {
$usage_data_settings = $config->get('usage_data');

$plugin_definition = $this->getPluginDefinition();
if (in_array($plugin_definition['setting'], $usage_data_settings)) {
if (in_array($plugin_definition['setting'] ?? [], $usage_data_settings)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit weird, because usually you check if a string is inside an array with the method.
But apart from that, why would you run the method with an empty array because you already know its would not be in the array.

$plugin_icon = $module_path . '/assets/icons/' . $this->pluginDefinition['id'] . '.svg';
$plugin_icon = empty($this->pluginDefinition['id'])
? $default_icon
: $module_path . '/assets/icons/' . $this->pluginDefinition['id'] . '.svg';

return '/' . (file_exists($plugin_icon) ? $plugin_icon : $default_icon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to rewrite this also now, because in your case plugin_icon is never empty anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the function return we are checking if file-exist and it can happen yet, but I can put together with previous if, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in the old situation if the file exist we return $plugin_icon, and otherwise $default_icon.

But in the new one, it will never return $default_icon right? as we put that value in the $plugin_icon, so it will always return this $plugin_icon as it will always exist? Or is that a situation i'm not seeing where the return will return $default_icon still?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the image continue existing at database, but locally the file is missing, then we will use the default-icon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I understand correctly, because you are now putting the default_icon in the plugin_icon it will always exist right? I don't see how the local file can not exist in our scenario.

$plugin_icon = empty($this->pluginDefinition['id'])
? $module_path . '/assets/icons/default-calendar.svg'
: $module_path . '/assets/icons/' . $this->pluginDefinition['id'] . '.svg';

return '/' . $plugin_icon;

@@ -106,17 +108,17 @@ public function getEventDates(NodeInterface $node) {
$date_time = [];

// Set formats for event dates.
$format = $this->pluginDefinition['dateFormat'];
$format = $this->pluginDefinition['dateFormat'] ?? 'Ymd\THis';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it feels a bit weird to be presetting the dates here if it's empty as we are then trying to hide an error/misconfiguration.

I would expect that if the dateFormat is not available at this moment then something is wrong with the platform and we should return an error or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe our code are safe to these data never arrived empty here, because never had an error here, but, I thought in a default value to simplify the solution. I opened a discuss about default values here: https://opensocial.slack.com/archives/G01CXDZ0FCG/p1710789447543369 and I got from here: html/profiles/contrib/social/modules/social_features/social_event/modules/social_event_addtocal/src/Annotation/SocialAddToCalendar.php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looking at the slack conversation, if the default are already set, do we need to retrieve it like this? Because it would mean we need to change it in 2 places if the defaults change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thougth in two options:

  1. Create an excepetion for this module and throw them, because it is a function called by front, so I believe this probably is the best way;
  2. Create a constant to save the default values and it will be saved in one place.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 1 can work yes


// Convert date to correct format.
// Set dates array.
if ($all_day) {
$date_time['start'] = $start_date->format($all_day_format);
$end_date->modify($this->pluginDefinition['endDateModification']);
$end_date->modify($this->pluginDefinition['endDateModification'] ?? '+ 1 day');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also a bit lost about what this exactly does. If an end date is empty we return 1 day?

@vcsvinicius vcsvinicius force-pushed the feature/3432191/fix-phpstan-warnings branch from 9feada7 to 25892ea Compare May 10, 2024 12:42
@robertragas robertragas merged commit ea5daeb into main May 23, 2024
193 of 194 checks passed
@robertragas robertragas deleted the feature/3432191/fix-phpstan-warnings branch May 23, 2024 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio: high status: needs review This pull request is waiting for a requested review team: guardians type: repository Improvements to working with the repository (e.g. templates, README files, or workflows)
3 participants