Skip to content

Commit

Permalink
Merge pull request #6 from square-bit/issue/php_warnings
Browse files Browse the repository at this point in the history
Fixed multiple php warnings and deprecations.
  • Loading branch information
saidatom committed Feb 25, 2024
2 parents 4459ba8 + 626fa44 commit 552b9a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 14 additions & 9 deletions src/Plugin/views/style/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
public function render() {
$rows = $this->getResultRows();

/** @var \Drupal\views_oai_pmh\Plugin\MetadataPrefixInterface $currentPrefixPlugin */
$currentPrefixPlugin = $this->prefixManager->createInstance(
$this->displayHandler->getCurrentMetadataPrefix()
);
try {
/** @var \Drupal\views_oai_pmh\Plugin\MetadataPrefixInterface $currentPrefixPlugin */
$currentPrefixPlugin = $this->prefixManager->createInstance(
$this->displayHandler->getCurrentMetadataPrefix()
);
} catch(\Exception $e) {
return;
}

$records = [];
foreach ($rows as $row_id => $row) {
Expand All @@ -190,7 +194,7 @@ public function render() {
$elements = $this->rowToXml->transform($row);

$element_or_null = [
array_keys($elements)[0] => reset($elements)
array_keys($elements)[0] ?? NULL => reset($elements)
];
// Insure we're adding (union) arrays, not null.
$element = $element_or_null ? $element_or_null : array();
Expand All @@ -202,7 +206,7 @@ public function render() {
$data = $root_elements + $elements;

// path id for datacite, dcc or dc
$path_id = (!empty($data['identifier']))? $data['identifier']['#'] : $data['dc:identifier']['#'];
$path_id = (!empty($data['identifier'])) ? $data['identifier']['#'] : (!empty($data['dc:identifier']) ? $data['dc:identifier']['#'] : '');

$xmlDoc = new \DOMDocument();
$xmlDoc->loadXML($this->serializer->encode($data, 'xml', [
Expand Down Expand Up @@ -427,11 +431,11 @@ protected function populateRow($row_id, ResultRow $row): array {
try {
$value = $this->view->style_plugin->getField($row_id, $id);

if ($field->option['hide_empty'] && empty($value)) {
if ($field->options['hide_empty'] && empty($value)) {
continue;
}

if(isset($field->option['type']) && $field->options['type'] == "datetime_default") {
if(isset($field->options['type']) && $field->options['type'] == "datetime_default") {
$value = \Drupal::service('date.formatter')->format(
strtotime($value), $field->options['settings']['format_type']
);
Expand Down Expand Up @@ -467,7 +471,8 @@ protected function populateRow($row_id, ResultRow $row): array {
* @return array|null
*/
protected function getFieldKeyAlias($id) {
$fields = $this->options['field_mappings'][$this->displayHandler->getCurrentMetadataPrefix()];
$prefix = $this->displayHandler->getCurrentMetadataPrefix();
$fields = $this->options['field_mappings'][$prefix] ?? NULL;

if (isset($fields) && isset($fields[$id]) && $fields[$id] !== 'none') {
return $fields[$id];
Expand Down
6 changes: 4 additions & 2 deletions src/Service/FormatRowToXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public function transform(array $row): array {
$this->depth($alias, $current_value)
);
}
$output = array_map(array($this, "trimmingKeys"), $output);

$output = array_map(fn (array $item): array => $this->trimmingKeys($item), $output);

return $output;
}
Expand All @@ -147,7 +148,8 @@ public function trimmingKeys(&$array) {
unset($array[$key]);
}
}
return array_map(array($this, "trimmingKeys"), $array);

return array_map(fn (mixed $item): mixed => $this->trimmingKeys($item), $array);
}
else {
return $array;
Expand Down
2 changes: 2 additions & 0 deletions src/Service/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Repository implements RepositoryInterface {

protected $totalRecords = 0;

protected array $formats = [];

/**
*
*/
Expand Down

0 comments on commit 552b9a0

Please sign in to comment.