Diff.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/diff.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Diff;
  11. use ArrayIterator;
  12. use IteratorAggregate;
  13. use Traversable;
  14. /**
  15. * @template-implements IteratorAggregate<int, Chunk>
  16. */
  17. final class Diff implements IteratorAggregate
  18. {
  19. /**
  20. * @var non-empty-string
  21. */
  22. private string $from;
  23. /**
  24. * @var non-empty-string
  25. */
  26. private string $to;
  27. /**
  28. * @var list<Chunk>
  29. */
  30. private array $chunks;
  31. /**
  32. * @param non-empty-string $from
  33. * @param non-empty-string $to
  34. * @param list<Chunk> $chunks
  35. */
  36. public function __construct(string $from, string $to, array $chunks = [])
  37. {
  38. $this->from = $from;
  39. $this->to = $to;
  40. $this->chunks = $chunks;
  41. }
  42. /**
  43. * @return non-empty-string
  44. */
  45. public function from(): string
  46. {
  47. return $this->from;
  48. }
  49. /**
  50. * @return non-empty-string
  51. */
  52. public function to(): string
  53. {
  54. return $this->to;
  55. }
  56. /**
  57. * @return list<Chunk>
  58. */
  59. public function chunks(): array
  60. {
  61. return $this->chunks;
  62. }
  63. /**
  64. * @param list<Chunk> $chunks
  65. */
  66. public function setChunks(array $chunks): void
  67. {
  68. $this->chunks = $chunks;
  69. }
  70. public function getIterator(): Traversable
  71. {
  72. return new ArrayIterator($this->chunks);
  73. }
  74. }