Skip to content

[TASK] Add native type declarations for Import #1172

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 16, 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 @@ -34,7 +34,7 @@ Please also have a look at our
- Use more native type declarations and strict mode
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
#1162, #1163, #1166)
#1162, #1163, #1166, #1172)
- Add visibility to all class/interface constants (#469)

### Deprecated
Expand Down
6 changes: 0 additions & 6 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ parameters:
count: 1
path: ../src/Property/Charset.php

-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
identifier: if.condNotBoolean
count: 1
path: ../src/Property/Import.php

-
message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#'
identifier: if.condNotBoolean
Expand Down
27 changes: 9 additions & 18 deletions src/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Import implements AtRule
private $location;

/**
* @var string
* @var string|null
*/
private $mediaQuery;

Expand All @@ -38,10 +38,9 @@ class Import implements AtRule
protected $comments = [];

/**
* @param string $mediaQuery
* @param int<0, max> $lineNumber
*/
public function __construct(URL $location, $mediaQuery, int $lineNumber = 0)
public function __construct(URL $location, ?string $mediaQuery, int $lineNumber = 0)
{
$this->location = $location;
$this->mediaQuery = $mediaQuery;
Expand All @@ -56,18 +55,12 @@ public function getLineNo(): int
return $this->lineNumber;
}

/**
* @param URL $location
*/
public function setLocation($location): void
public function setLocation(URL $location): void
{
$this->location = $location;
}

/**
* @return URL
*/
public function getLocation()
public function getLocation(): URL
{
return $this->location;
}
Expand Down Expand Up @@ -95,14 +88,15 @@ public function atRuleName(): string
}

/**
* @return array<int, URL|string>
* @return array{0: URL, 1?: non-empty-string}
*/
public function atRuleArgs(): array
{
$result = [$this->location];
if ($this->mediaQuery) {
\array_push($result, $this->mediaQuery);
if (\is_string($this->mediaQuery) && $this->mediaQuery !== '') {
$result[] = $this->mediaQuery;
}

return $result;
}

Expand Down Expand Up @@ -130,10 +124,7 @@ public function setComments(array $comments): void
$this->comments = $comments;
}

/**
* @return string
*/
public function getMediaQuery()
public function getMediaQuery(): ?string
{
return $this->mediaQuery;
}
Expand Down