Skip to content

Commit 582e3ab

Browse files
committed
Add last color to SystemColor
1 parent 5b2f9b2 commit 582e3ab

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/PhpWord/Style/Colors/SystemColor.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,27 @@ final class SystemColor extends AbstractColor implements NamedColorInterface
4444
'menuBar' => true,
4545
);
4646

47-
private $color;
47+
private $name;
48+
private $lastColor;
4849

49-
public function __construct(string $color)
50+
public function __construct(string $name, StaticColorInterface $lastColor)
5051
{
51-
if (!static::isValid($color)) {
52-
throw new Exception(sprintf("Provided system color must be a valid system color. '%s' provided. Allowed: %s", $color, implode(', ', array_keys(self::$allowedColors))));
52+
if (!static::isValid($name)) {
53+
throw new Exception(sprintf("Provided system color must be a valid system color. '%s' provided. Allowed: %s", $name, implode(', ', array_keys(self::$allowedColors))));
5354
}
5455

55-
$this->color = $color;
56+
$this->name = $name;
57+
$this->lastColor = clone $lastColor;
5658
}
5759

5860
public function getName(): string
5961
{
60-
return $this->color;
62+
return $this->name;
63+
}
64+
65+
public function getLastColor(): StaticColorInterface
66+
{
67+
return clone $this->lastColor;
6168
}
6269

6370
public static function isValid(string $color): bool

tests/PhpWord/Style/Colors/ColorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testConversions()
3535
array(null, AbstractColor::class, null),
3636
array(new Hex('fff'), Hex::class, 'FFFFFF'),
3737
array(new Rgb(0, 102, 255), Rgb::class, '0066FF'),
38-
array(new SystemColor('window'), SystemColor::class, 'window'),
38+
array(new SystemColor('window', new Hex('fff')), SystemColor::class, 'window'),
3939
array(new HighlightColor('green'), HighlightColor::class, 'green'),
4040
);
4141
// Conduct test

tests/PhpWord/Style/Colors/SystemColorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testConversions()
6767
// Conduct test
6868
foreach ($values as $value) {
6969
$message = $value . ' should be a valid color';
70-
$result = new SystemColor($value);
70+
$result = new SystemColor($value, new Hex('000'));
7171
$this->assertEquals($value, $result->getName(), $message);
7272
$this->assertEquals($value, $result->toHexOrName(), $message);
7373
}

0 commit comments

Comments
 (0)