Skip to content

[TASK] Add more native type declarations for Selector #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Please also have a look at our
- Make all non-private properties `@internal` (#886)
- Use more native type declarations and strict mode
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
#964, #967, #1000)
#964, #967, #1000, #1044)
- Add visibility to all class/interface constants (#469)

### Deprecated
Expand Down
21 changes: 6 additions & 15 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,41 +75,32 @@ class Selector
private $specificity;

/**
* @param string $selector
*
* @return bool
*
* @internal since V8.8.0
*/
public static function isValid($selector)
public static function isValid(string $selector)
{
return \preg_match(static::SELECTOR_VALIDATION_RX, $selector);
}

/**
* @param string $selector
* @param bool $calculateSpecificity @deprecated since V8.8.0, will be removed in V9.0.0
*/
public function __construct($selector, $calculateSpecificity = false)
public function __construct(string $selector, bool $calculateSpecificity = false)
{
$this->setSelector($selector);
if ($calculateSpecificity) {
$this->getSpecificity();
}
}

/**
* @return string
*/
public function getSelector()
public function getSelector(): string
{
return $this->selector;
}

/**
* @param string $selector
*/
public function setSelector($selector): void
public function setSelector(string $selector): void
{
$this->selector = \trim($selector);
$this->specificity = null;
Expand All @@ -124,9 +115,9 @@ public function __toString(): string
}

/**
* @return int
* @return int<0, max>
*/
public function getSpecificity()
public function getSpecificity(): int
{
if ($this->specificity === null) {
$a = 0;
Expand Down