RendererStyle.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. declare(strict_types = 1);
  3. namespace BaconQrCode\Renderer\RendererStyle;
  4. use BaconQrCode\Renderer\Eye\EyeInterface;
  5. use BaconQrCode\Renderer\Eye\ModuleEye;
  6. use BaconQrCode\Renderer\Module\ModuleInterface;
  7. use BaconQrCode\Renderer\Module\SquareModule;
  8. final class RendererStyle
  9. {
  10. /**
  11. * @var int
  12. */
  13. private $size;
  14. /**
  15. * @var int
  16. */
  17. private $margin;
  18. /**
  19. * @var ModuleInterface
  20. */
  21. private $module;
  22. /**
  23. * @var EyeInterface|null
  24. */
  25. private $eye;
  26. /**
  27. * @var Fill
  28. */
  29. private $fill;
  30. public function __construct(
  31. int $size,
  32. int $margin = 4,
  33. ?ModuleInterface $module = null,
  34. ?EyeInterface $eye = null,
  35. ?Fill $fill = null
  36. ) {
  37. $this->margin = $margin;
  38. $this->size = $size;
  39. $this->module = $module ?: SquareModule::instance();
  40. $this->eye = $eye ?: new ModuleEye($this->module);
  41. $this->fill = $fill ?: Fill::default();
  42. }
  43. public function withSize(int $size) : self
  44. {
  45. $style = clone $this;
  46. $style->size = $size;
  47. return $style;
  48. }
  49. public function withMargin(int $margin) : self
  50. {
  51. $style = clone $this;
  52. $style->margin = $margin;
  53. return $style;
  54. }
  55. public function getSize() : int
  56. {
  57. return $this->size;
  58. }
  59. public function getMargin() : int
  60. {
  61. return $this->margin;
  62. }
  63. public function getModule() : ModuleInterface
  64. {
  65. return $this->module;
  66. }
  67. public function getEye() : EyeInterface
  68. {
  69. return $this->eye;
  70. }
  71. public function getFill() : Fill
  72. {
  73. return $this->fill;
  74. }
  75. }