API page: https://api.drupal.org/api/drupal/core%21modules%21update%21update.modul...
The function uses the following code.
$last_email_notice = \Drupal::state()->get('update.last_email_notification') ? : 0;
This is not necessary, since \Drupal::state()->get() accepts a default value as second parameter. With the current code, the returned value is checked twice to see if it is NULL: first from \Drupal::state()->get(), and then from update_cron().
It is enough using the following code.
$last_email_notice = \Drupal::state()->get('update.last_email_notification', 0);
If the value has not been already set, \Drupal::state()->get() will return the value passed as second parameter.
public function get($key, $default = NULL) {
$values = $this->getMultiple(array($key));
return isset($values[$key]) ? $values[$key] : $default;
}
Comments
Comment #2
avpadernoComment #3
avpadernoComment #7
avpadernoComment #8
avpadernoComment #11
avpadernoThere are other files where this is done. This patch fixes those files too (always for the Update module).
Comment #12
isholgueras commentedI've review it and tested. The patch applies fine and works great.
Comment #13
alexpottThis is the kind of thing that should be done consistently for the entirety of core as the per module issue scope is not the best. You can use a regex like
[:>]state(\(\))?->get\(.*\?to find more. Note not all should be converted. For example,\Drupal::state()->get(static::class) ?: parent::getAll()should not be convert because you don't always want to callparent::getAll()Comment #14
elamanI've created a patch based on @alexpott suggestions. Please review.
Comment #16
elamanNew patch, which accounts for
CssCollectionRendererUnitTest.phpexpecting NULL.Comment #17
alexpott@Elaman CssCollectionRendererUnitTest is failing because it is not mocking correctly. We can fix it here.
Also there were a few left over in core that can be converted.
Comment #18
elaman@alexplott I thought fixing
CssCollectionRendererUnitTestmight be a scope-creep.Comment #20
alexpott@Elaman I don't think so - the mock is incorrect and needs adjusting to work how the function actually works.
Comment #21
alexpottI can't reproduce the test fail locally. Retesting.
Comment #22
avpadernoIt seems there is a deprecation notice repeated twice.
Comment #23
alexpott@kiamlaluno yeah but I didn't get that when running the test locally and now DrupalCI is not reporting it either. It's an unrelated random.
Comment #25
dawehnerThat's much nicer!
Comment #26
dawehnerForget to RTBC it.
Comment #29
avpadernoNow there are two deprecation notices about
EntityManagerInterface::loadEntityByUuid(). It doesn't seem they are caused by the changes introduced in this patch.Comment #30
vadim.hirbu commentedHi @kiamlaluno.
I found that your patch added changes to method
loadEntityByUuid()I've just updated the latest patch to not apply changes to this part
\Drupal::service('entity.repository')->loadEntityByUuid().Added interdiff file.
Comment #32
tvb commentedPatch from #30 could not be applied to 8.9.x-dev.
Comment #33
ravi.shankar commentedWorking on this.
Comment #34
ravi.shankar commentedHere I have added reroll of patch #30.
Comment #36
tvb commentedThere were 6 conflicts in the patch from #30.
Four of these were resolved easily. One concerned a deleted module (path_test).
The changes in CssCollectionRendererUnitTest (6th conflict) were rejected because they are not related to \Drupal::state()->get().
It seems the issue mentioned in #16 to #20 is fixed:
New patch and diff file attached.
Comment #37
alexpott@tvb I like this. But given it's a task the most likely branch for this to land in is 9.1.x - and the so let's roll the next patch against that branch.
Comment #38
jungleRerolled patch from #36
Comment #39
quietone commentedI reviewed the patch and all changes look correct to me, and of course tests are passing. Applied the patch and used the regex from $13, which found 4 occurrences, none of which should be changed.
Comment #40
jungle@quietone, Thanks for reviewing!
rerolled a patch for 8.8.x in case it's needed.
Comment #41
alexpottCommitted 6b54e95 and pushed to 9.1.x. Thanks!
As a task this is only eligible for 9.1.x