FeedInterface.php
2 weeks ago
FeedValidatorInterface.php
5 months ago
ProductLoader.php
5 months ago
ProductMapperInterface.php
5 months ago
ProductWalker.php
5 months ago
WalkerProgress.php
5 months ago
WalkerProgress.php
65 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Walker Progress class. |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\Internal\ProductFeed |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Automattic\WooCommerce\Internal\ProductFeed\Feed; |
| 11 | |
| 12 | /** |
| 13 | * Simple class that tracks/indicates the progress of a walker. |
| 14 | * |
| 15 | * @since 10.5.0 |
| 16 | */ |
| 17 | final class WalkerProgress { |
| 18 | /** |
| 19 | * Total number of items to process. |
| 20 | * |
| 21 | * @var int |
| 22 | */ |
| 23 | public int $total_count; |
| 24 | |
| 25 | /** |
| 26 | * Total number of batches to process. |
| 27 | * |
| 28 | * @var int |
| 29 | */ |
| 30 | public int $total_batch_count; |
| 31 | |
| 32 | /** |
| 33 | * Number of items processed so far. |
| 34 | * |
| 35 | * @var int |
| 36 | */ |
| 37 | public int $processed_items = 0; |
| 38 | |
| 39 | /** |
| 40 | * Number of batches processed so far. |
| 41 | * |
| 42 | * @var int |
| 43 | */ |
| 44 | public int $processed_batches = 0; |
| 45 | |
| 46 | /** |
| 47 | * Creates a WalkerProgress instance from a WooCommerce products query result. |
| 48 | * |
| 49 | * @since 10.5.0 |
| 50 | * |
| 51 | * @param \stdClass $result The result object from wc_get_products() with total and max_num_pages properties. |
| 52 | * @return self |
| 53 | */ |
| 54 | public static function from_wc_get_products_result( \stdClass $result ): self { |
| 55 | $progress = new self(); |
| 56 | |
| 57 | $progress->total_count = $result->total; |
| 58 | $progress->total_batch_count = $result->max_num_pages; |
| 59 | $progress->processed_items = 0; |
| 60 | $progress->processed_batches = 0; |
| 61 | |
| 62 | return $progress; |
| 63 | } |
| 64 | } |
| 65 |