Skip to content

[Bug]: When maxProgress is zero, finish() says it is one #25

@fulldecent

Description

@fulldecent

Library version

1.1.3

PHP version

8.2

Bug description

Sometimes there is no work to do! For example, an idempotent synchronization task that has already recently finished working once.

In that case it will finish with:

1/1 [############################] 100%

But I was expecting:

0/0 [############################] 100%

If I see 1/1 instead, that makes the output indistinguishable from when there was one task to do. And in my use case of syncing things it indicates a new record which is an error.

Sample code

// Sync Moodle course completions to CMS expirations (excluding eCards and CE certs) ///////////////////////////////////
$moodleCourseTokenIds = $syncService->getTouchedMoodleCourseTokenIds();
$progressBar = new ProgressBar(progress: 0, maxProgress: count($moodleCourseTokenIds));
foreach ($moodleCourseTokenIds as $moodleCourseTokenId) {
  $syncService->syncMoodleCourseTokenToCMSExpiration($moodleCourseTokenId);
  $progressBar->tick();
}
// $progressBar->finish(); Calling ->finish() with maxProgress: 0 causes it to paint a line "1/1" which is confusing.

Code of Conduct

  • I agree to follow the Code of Conduct

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions