Skip to content

Commit 72e6d35

Browse files
committed
Change Selector constructor to accept string or list<Component>
1 parent 7325989 commit 72e6d35

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/Property/Selector.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ public static function isValid(string $selector): bool
7474
}
7575

7676
/**
77-
* @param non-empty-string $selector
77+
* @param non-empty-string|list<Component> $selector
78+
* Providing a string is deprecated in version 9.2 and will not work from v10.0
7879
*
7980
* @throws \UnexpectedValueException if the selector is not valid
8081
*/
81-
final public function __construct(string $selector = '')
82+
final public function __construct($selector)
8283
{
83-
// Allow construction of empty object for content to be set via `setComponents()`.
84-
// (`setSelector()` will throw an exception when provided with an empty string.)
85-
if ($selector !== '') {
84+
if (\is_string($selector)) {
8685
$this->setSelector($selector);
86+
} else {
87+
$this->setComponents($selector);
8788
}
8889
}
8990

@@ -147,7 +148,7 @@ public static function parse(ParserState $parserState, array &$comments = []): s
147148
);
148149
}
149150

150-
return (new static())->setComponents($selectorParts);
151+
return new static($selectorParts);
151152
}
152153

153154
/**

tests/Unit/Property/KeyframeSelectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getArrayRepresentationIncludesClassName(): void
3131
*/
3232
public function getArrayRepresentationIncludesComponent(): void
3333
{
34-
$subject = (new KeyframeSelector())->setComponents([new CompoundSelector('50%')]);
34+
$subject = new KeyframeSelector([new CompoundSelector('50%')]);
3535

3636
$result = $subject->getArrayRepresentation();
3737

tests/Unit/Property/SelectorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public static function provideComponentsAndArrayRepresentation(): array
395395
*/
396396
public function setComponentsSetsComponentsProvided(array $components, array $expectedRepresenation): void
397397
{
398-
$subject = new Selector();
398+
$subject = new Selector([]);
399399

400400
$subject->setComponents($components);
401401

@@ -408,7 +408,7 @@ public function setComponentsSetsComponentsProvided(array $components, array $ex
408408
*/
409409
public function getComponentsReturnsEmptyArrayIfNotSet(): void
410410
{
411-
$subject = new Selector();
411+
$subject = new Selector([]);
412412

413413
$result = $subject->getComponents();
414414

@@ -424,7 +424,7 @@ public function getComponentsReturnsEmptyArrayIfNotSet(): void
424424
*/
425425
public function getComponentsReturnsComponentsSet(array $components): void
426426
{
427-
$subject = new Selector();
427+
$subject = new Selector([]);
428428
$subject->setComponents($components);
429429

430430
$result = $subject->getComponents();
@@ -541,7 +541,7 @@ public function doesNotCleanupSpacesWithinAttributeSelector(): void
541541
*/
542542
public function getArrayRepresentationIncludesClassName(): void
543543
{
544-
$subject = new Selector();
544+
$subject = new Selector([]);
545545

546546
$result = $subject->getArrayRepresentation();
547547

@@ -553,7 +553,7 @@ public function getArrayRepresentationIncludesClassName(): void
553553
*/
554554
public function getArrayRepresentationIncludesComponent(): void
555555
{
556-
$subject = (new Selector())->setComponents([new CompoundSelector('p.test')]);
556+
$subject = new Selector([new CompoundSelector('p.test')]);
557557

558558
$result = $subject->getArrayRepresentation();
559559

0 commit comments

Comments
 (0)