Skip to content

Commit

Permalink
Try to avoid parameter moves
Browse files Browse the repository at this point in the history
  • Loading branch information
GlazerMann authored Nov 28, 2023
1 parent bc71fe6 commit 7c857d4
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public function prepare() : void {
if ($this->has('CITATION_BOT_PLACEHOLDER_journal')) {
if ($this->has('journal') && $this->get('journal') !== $this->get('CITATION_BOT_PLACEHOLDER_journal') &&
'[[' . $this->get('journal') . ']]' !== $this->get('CITATION_BOT_PLACEHOLDER_journal')) {
$this->forget('CITATION_BOT_PLACEHOLDER_journal');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_journal');
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_journal', 'journal');
}
Expand All @@ -659,7 +659,7 @@ public function prepare() : void {
} elseif ($this->get('title') === $this->get('CITATION_BOT_PLACEHOLDER_title')) {
$this->rename('CITATION_BOT_PLACEHOLDER_title', 'title');
} else {
$this->forget('CITATION_BOT_PLACEHOLDER_title');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_title');
}
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_title', 'title');
Expand All @@ -676,45 +676,45 @@ public function prepare() : void {
} elseif ($this->get('chapter') === $this->get('CITATION_BOT_PLACEHOLDER_chapter')) {
$this->rename('CITATION_BOT_PLACEHOLDER_chapter', 'chapter');
} else {
$this->forget('CITATION_BOT_PLACEHOLDER_chapter');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_chapter');
}
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_chapter', 'chapter');
}
}
if ($this->has('CITATION_BOT_PLACEHOLDER_issue')) {
if ($this->has('issue') && $this->get('issue') !== $this->get('CITATION_BOT_PLACEHOLDER_issue')) {
$this->forget('CITATION_BOT_PLACEHOLDER_issue');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_issue');
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_issue', 'issue');
}
}
if ($this->has('CITATION_BOT_PLACEHOLDER_volume')) {
if ($this->has('volume') && $this->get('volume') !== $this->get('CITATION_BOT_PLACEHOLDER_volume')) {
$this->forget('CITATION_BOT_PLACEHOLDER_volume');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_volume');
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_volume', 'volume');
}
}
if ($this->has('CITATION_BOT_PLACEHOLDER_page')) {
if (($this->has('page') || $this->has('pages')) && ($this->get('page') . $this->get('pages') !== $this->get('CITATION_BOT_PLACEHOLDER_page'))) {
$this->forget('CITATION_BOT_PLACEHOLDER_page');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_page');
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_page', 'page');
}
}
if ($this->has('CITATION_BOT_PLACEHOLDER_pages')) {
if (($this->has('page') || $this->has('pages')) && ($this->get('page') . $this->get('pages') !== $this->get('CITATION_BOT_PLACEHOLDER_pages'))) {
$this->forget('CITATION_BOT_PLACEHOLDER_pages');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_pages');
} else {
$this->rename('CITATION_BOT_PLACEHOLDER_pages', 'pages');
}
}
if ($this->has('CITATION_BOT_PLACEHOLDER_year')) {
if ($this->has('year') && ($this->get('year') !== $this->get('CITATION_BOT_PLACEHOLDER_year'))) {
$this->forget('CITATION_BOT_PLACEHOLDER_year');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_year');
} elseif ($this->has('date') && ($this->get('date') !== $this->get('CITATION_BOT_PLACEHOLDER_year'))) {
$this->forget('CITATION_BOT_PLACEHOLDER_year');
$this->move_and_forget('CITATION_BOT_PLACEHOLDER_year');
} elseif ($this->has('date') && ($this->get('date') === $this->get('CITATION_BOT_PLACEHOLDER_year'))) {
$this->forget('date');
$this->rename('CITATION_BOT_PLACEHOLDER_year', 'year');
Expand Down Expand Up @@ -7403,4 +7403,15 @@ public function block_modifications() : void { // {{void}} should be just like a
unset($this->rawtext); // @phan-suppress-current-line PhanTypeObjectUnsetDeclaredProperty
$this->parse_text($tmp);
}

private function move_and_forget(string $para) : void { // Try to keep parameters in the same order
$para2 = str_replace('CITATION_BOT_PLACEHOLDER_', '', $para);
if ($this->has($para2)) {
$this->set($para, $this->get($para2));
$this->rename($para, $para2);
} else {
$this->forget($para);
bot_debug_log('move_and_forget: ' . $para);
}
}
}

0 comments on commit 7c857d4

Please sign in to comment.