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

Conversation

bjendres
Copy link
Member

@bjendres bjendres commented Sep 5, 2023

No description provided.

@bjendres bjendres added this to the CiviBanking 1.0 milestone Sep 5, 2023
@@ -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?

@@ -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']);
$total_tx_count = (float) $params['total_tx_count'] ?? 1.0;
if ($total_tx_count) {
$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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants