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

Assignment in if condition is not allowed. #4588

Merged
merged 2 commits into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 34 additions & 21 deletions Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,8 @@
* [0] => PMID of first matching result
* [1] => total number of results
*/
if ($doi = $this->get_without_comments_and_placeholders('doi')) {
$doi = $this->get_without_comments_and_placeholders('doi');
if ($doi) {
if (doi_works($doi)) {
$results = $this->do_pumbed_query(["doi"]);
if ($results[1] !== 0) {
Expand Down Expand Up @@ -2926,7 +2927,8 @@
foreach ($terms as $term) {
$term = mb_strtolower($term);
if ($term === "title") {
if ($data = $this->get_without_comments_and_placeholders('title')) {
$data = $this->get_without_comments_and_placeholders('title');
if ($data) {
$key = 'Title';
$data = straighten_quotes($data, true);
$data = str_replace([';', ',', ':', '.', '?', '!', '&', '/', '(', ')', '[', ']', '{', '}', '"', "'", '|', '\\'], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], $data);
Expand All @@ -2940,29 +2942,34 @@
}
}
} elseif ($term === "page") {
if ($pages = $this->page_range()) {
$pages = $this->page_range();
if ($pages) {
$val = $pages[1];
$key = 'Pagination';
$query .= " AND (" . str_replace("%E2%80%93", "-", urlencode($val)) . "[$key])";
}
} elseif ($term === "surname") {
if ($val = $this->first_surname()) {
$val = $this->first_surname();
if ($val) {
$key = 'Author';
$query .= " AND (" . str_replace("%E2%80%93", "-", urlencode($val)) . "[$key])";
}
} elseif ($term === "year") {
$key = 'Publication Date';
if ($val = $this->year()) {
$val = $this->year();
if ($val) {
$query .= " AND (" . str_replace("%E2%80%93", "-", urlencode($val)) . "[$key])";
}
} elseif ($term === "doi") {
$key = 'AID';
if ($val = $this->get_without_comments_and_placeholders($term)) {
$val = $this->get_without_comments_and_placeholders($term);
if ($val) {
$query .= " AND (" . "\"" . str_replace(["%E2%80%93", ';'], ["-", '%3B'], $val) . "\"" . "[$key])"; // PubMed does not like escaped /s in DOIs, but other characters seem problematic.
}
} else {
$key = $key_index[$term]; // Will crash if bad data is passed
if ($val = $this->get_without_comments_and_placeholders($term)) {
$val = $this->get_without_comments_and_placeholders($term);
if ($val) {
if (preg_match(REGEXP_PLAIN_WIKILINK, $val, $matches)) {
$val = $matches[1]; // @codeCoverageIgnore
} elseif (preg_match(REGEXP_PIPED_WIKILINK, $val, $matches)) {
Expand Down Expand Up @@ -3459,12 +3466,14 @@
return;
}
$this->this_array = [$this];
if ($pm = $this->get('pmid')) {
report_action('Checking ' . pubmed_link('pmid', $pm) . ' for more details');
query_pmid_api([$pm], $this->this_array);
} elseif ($pm = $this->get('pmc')) {
report_action('Checking ' . pubmed_link('pmc', $pm) . ' for more details');
query_pmc_api([$pm], $this->this_array);
$pmid = $this->get('pmid');
$pmc = $this->get('pmc');
if ($pmid) {
report_action('Checking ' . pubmed_link('pmid', $pmid) . ' for more details');
query_pmid_api([$pmid], $this->this_array);
} elseif ($pmc) {
report_action('Checking ' . pubmed_link('pmc', $pmc) . ' for more details');
query_pmc_api([$pmc], $this->this_array);
}
$this->this_array = [];
}
Expand Down Expand Up @@ -8255,7 +8264,8 @@
*/
private function display_authors(): int
{
if (($da = $this->get('display-authors')) === '') {
$da = $this->get('display-authors');
if ($da === '') {
$da = $this->get('displayauthors');
}
return ctype_digit($da) ? (int) $da : 0;
Expand Down Expand Up @@ -8527,7 +8537,8 @@
if ($this->get($par) !== $this->get3($par)) {
return false;
}
if (($pos = $this->get_param_key($par)) !== null) {
$pos = $this->get_param_key($par);
if ($pos !== null) {
$this->param[$pos]->val = $val;
return true;
}
Expand All @@ -8539,7 +8550,8 @@
$insert_after = prior_parameters($par);
$prior_pos_best = -1;
foreach (array_reverse($insert_after) as $after) {
if (($after_key = $this->get_param_key($after)) !== null) {
$after_key = $this->get_param_key($after);
if ($after_key !== null) {
$keys = array_keys($this->param);
$keys_count = count($keys);
for ($prior_pos = 0; $prior_pos < $keys_count; $prior_pos++) {
Expand Down Expand Up @@ -8819,14 +8831,14 @@
return $isbn13;
}

/** @return ?array<string> */
private function inline_doi_information(): ?array
/** @return array<string> */
private function inline_doi_information(): array
{
if ($this->name !== "doi-inline") {
return null;
return [];
}
if (count($this->param) !== 2) {
return null;
return [];

Check warning on line 8841 in Template.php

View check run for this annotation

Codecov / codecov/patch

Template.php#L8841

Added line #L8841 was not covered by tests
}
$vals = [];
$vals[0] = $this->param[0]->parsed_text();
Expand All @@ -8837,7 +8849,8 @@
private function get_inline_doi_from_title(): void
{
if (preg_match("~(?:\s)*(?:# # # CITATION_BOT_PLACEHOLDER_TEMPLATE )(\d+)(?: # # #)(?:\s)*~i", $this->get('title'), $match)) {
if ($inline_doi = self::$all_templates[$match[1]]->inline_doi_information()) {
$inline_doi = self::$all_templates[$match[1]]->inline_doi_information();
if ($inline_doi) {
if ($this->add_if_new('doi', trim($inline_doi[0]))) {
// Add doi
$this->set('title', trim($inline_doi[1]));
Expand Down