You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. <?php
  2. /*
  3. * ImportedTransactions.php
  4. * Copyright (c) 2021 james@firefly-iii.org
  5. *
  6. * This file is part of the Firefly III Data Importer
  7. * (https://github.com/firefly-iii/data-importer).
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. declare(strict_types=1);
  23. namespace App\Events;
  24. use Illuminate\Queue\SerializesModels;
  25. /**
  26. * Class ImportedTransactions
  27. */
  28. class ImportedTransactions
  29. {
  30. use SerializesModels;
  31. public const int TEST = 3;
  32. public array $errors;
  33. public array $messages;
  34. public array $warnings;
  35. public function __construct(array $messages, array $warnings, array $errors)
  36. {
  37. app('log')->debug('Created event ImportedTransactions with filtering (2)');
  38. // filter messages:
  39. $this->messages = $this->filterArray('message(s)', $messages);
  40. $this->warnings = $this->filterArray('warning(s)', $warnings);
  41. $this->errors = $this->filterArray('error(s)', $errors);
  42. }
  43. /**
  44. * @string $title
  45. */
  46. private function filterArray(string $title, array $collection): array
  47. {
  48. $count = 0;
  49. $newCollection = [];
  50. foreach ($collection as $index => $set) {
  51. $newSet = [];
  52. foreach ($set as $line) {
  53. $line = (string)$line;
  54. if ('' !== $line) {
  55. $newSet[] = $line;
  56. ++$count;
  57. }
  58. }
  59. if (count($newSet) > 0) {
  60. $newCollection[$index] = $newSet;
  61. }
  62. }
  63. app('log')->debug(sprintf('Array contains %d %s', $count, $title));
  64. return $newCollection;
  65. }
  66. }