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

Remove some 'not defined' notices in importer code #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions CRM/Banking/PluginImpl/Importer/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,19 @@ function import_file( $file_path, $params )

// first: set the count
$params['total_tx_count'] = 0;
foreach ($config->payments as $payment_spec) {
$params['total_tx_count'] += $this->xpath->query($payment_spec->path)->length;
if (!empty($config->payments)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As empty() doesn't check for the statement being an array/iterable, I suppose $config->payments is guaranteed to always be an array if it's not empty?

foreach ($config->payments as $payment_spec) {
if (!empty($payment_spec->path)) {
$params['total_tx_count'] += (int) $this->xpath->query($payment_spec->path)->length;
}
}
}
foreach ($config->payment_lines as $payment_spec) {
$params['total_tx_count'] += $this->xpath->query($payment_spec->path)->length;
if (!empty($config->payment_lines)) {
foreach ($config->payment_lines as $payment_spec) {
if (!empty($payment_spec->path)) {
$params['total_tx_count'] += (int) $this->xpath->query($payment_spec->path)->length;
}
}
}

// then: run the importer
Expand All @@ -185,11 +193,15 @@ function import_file( $file_path, $params )
// first: set the count
$params['total_tx_count'] = 0;
foreach ($statements as $statement) {
foreach ($config->payments as $payment_spec) {
$params['total_tx_count'] += $this->xpath->query($payment_spec->path, $statement)->length;
if (!empty($config->payments)) {
foreach ($config->payments as $payment_spec) {
$params['total_tx_count'] += $this->xpath->query($payment_spec->path, $statement)->length;
}
}
foreach ($config->payment_lines as $payment_spec) {
$params['total_tx_count'] += $this->xpath->query($payment_spec->path, $statement)->length;
if (!empty($config->payment_lines)) {
foreach ($config->payment_lines as $payment_spec) {
$params['total_tx_count'] += $this->xpath->query($payment_spec->path, $statement)->length;
}
}
}

Expand Down Expand Up @@ -315,7 +327,12 @@ protected function filterMatches($payment_node, $filter) {
*/
protected function import_payment($payment_spec, $payment_node, $stmt_data, $index, $params) {
$config = $this->_plugin_config;
$progress = ((float)$index / (float) $params['total_tx_count']);
$total_tx_count = (float) $params['total_tx_count'] ?? 1.0;
if ($total_tx_count) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this condition necessary now that there's a null-coalescing default of 1.0 and an implicit default of 0 due to the type cast to float?

Copy link
Collaborator

@jensschuppe jensschuppe Sep 6, 2023

Choose a reason for hiding this comment

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

This might also use some brackets, too. If I get that right, he type cast will always cause a non-NULL value be given to the null-coalescing operator, making it rather useless here. Maybe this helps.

$progress = ((float)$index / ((float) $params['total_tx_count'] ?? 0.0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

And if so, this should read $total_tx_count instead of $params['total_tx_count'], right?

} else {
$progress = 0;
}

$raw_data = $payment_node->ownerDocument->saveXML($payment_node);
$raw_data = preg_replace("/>\s+</", "><", $raw_data); // 'flatten' raw_data
Expand Down