Debian Codegraph @

src/Renderer/RendererStyle/EyeFill.php

raw
1 <?php
2 declare(strict_types = 1);
3
4 namespace BaconQrCode\Renderer\RendererStyle;
5
6 use BaconQrCode\Exception\RuntimeException;
7 use BaconQrCode\Renderer\Color\ColorInterface;
8
9 final class EyeFill
10 {
11 private static ?EyeFill $inherit = null;
12
13 public function __construct(
14 private readonly ?ColorInterface $externalColor,
15 private readonly ?ColorInterface $internalColor
16 ) {
17 }
18
19 public static function uniform(ColorInterface $color) : self
20 {
21 return new self($color, $color);
22 }
23
24 public static function inherit() : self
25 {
26 return self::$inherit ?: self::$inherit = new self(null, null);
27 }
28
29 public function inheritsBothColors() : bool
30 {
31 return null === $this->externalColor && null === $this->internalColor;
32 }
33
34 public function inheritsExternalColor() : bool
35 {
36 return null === $this->externalColor;
37 }
38
39 public function inheritsInternalColor() : bool
40 {
41 return null === $this->internalColor;
42 }
43
44 public function getExternalColor() : ColorInterface
45 {
46 if (null === $this->externalColor) {
47 throw new RuntimeException('External eye color inherits foreground color');
48 }
49
50 return $this->externalColor;
51 }
52
53 public function getInternalColor() : ColorInterface
54 {
55 if (null === $this->internalColor) {
56 throw new RuntimeException('Internal eye color inherits foreground color');
57 }
58
59 return $this->internalColor;
60 }
61 }