| 1 |
<?php |
| 2 |
|
| 3 |
namespace AATXT\App\Admin\BulkActions; |
| 4 |
|
| 5 |
/** |
| 6 |
* Value Object representing the result of a bulk action. |
| 7 |
* |
| 8 |
* Immutable object that holds the counts of total items processed |
| 9 |
* and successfully updated items. |
| 10 |
*/ |
| 11 |
final class BulkActionResult |
| 12 |
{ |
| 13 |
/** |
| 14 |
* Total number of items that were processed |
| 15 |
* |
| 16 |
* @var int |
| 17 |
*/ |
| 18 |
private $total; |
| 19 |
|
| 20 |
/** |
| 21 |
* Number of items successfully updated |
| 22 |
* |
| 23 |
* @var int |
| 24 |
*/ |
| 25 |
private $updated; |
| 26 |
|
| 27 |
/** |
| 28 |
* Constructor |
| 29 |
* |
| 30 |
* @param int $total Total items processed |
| 31 |
* @param int $updated Items successfully updated |
| 32 |
*/ |
| 33 |
public function __construct(int $total, int $updated) |
| 34 |
{ |
| 35 |
$this->total = $total; |
| 36 |
$this->updated = $updated; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Get the total number of items processed. |
| 41 |
* |
| 42 |
* @return int |
| 43 |
*/ |
| 44 |
public function getTotal(): int |
| 45 |
{ |
| 46 |
return $this->total; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get the number of items successfully updated. |
| 51 |
* |
| 52 |
* @return int |
| 53 |
*/ |
| 54 |
public function getUpdated(): int |
| 55 |
{ |
| 56 |
return $this->updated; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Check if all items were successfully updated. |
| 61 |
* |
| 62 |
* @return bool |
| 63 |
*/ |
| 64 |
public function isComplete(): bool |
| 65 |
{ |
| 66 |
return $this->total === $this->updated; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Check if no items were updated. |
| 71 |
* |
| 72 |
* @return bool |
| 73 |
*/ |
| 74 |
public function hasNoUpdates(): bool |
| 75 |
{ |
| 76 |
return $this->updated === 0; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Check if some but not all items were updated. |
| 81 |
* |
| 82 |
* @return bool |
| 83 |
*/ |
| 84 |
public function isPartial(): bool |
| 85 |
{ |
| 86 |
return $this->updated > 0 && $this->updated < $this->total; |
| 87 |
} |
| 88 |
} |
| 89 |
|