Skip to content

[TASK] Add native type declarations for CSSNamespace #1187

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 2 commits into from
Mar 18, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ 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, #1172, #1174, #1178, #1179, #1181, #1183, #1184, #1186)
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181, #1183, #1184, #1186,
#1187)
- Add visibility to all class/interface constants (#469)

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

-
message: '#^Cannot call method render\(\) on string\.$#'
identifier: method.nonObject
count: 1
path: ../src/Property/CSSNamespace.php

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

-
message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#'
identifier: if.condNotBoolean
Expand Down
29 changes: 12 additions & 17 deletions src/Property/CSSNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Value\CSSString;
use Sabberworm\CSS\Value\URL;

/**
* `CSSNamespace` represents an `@namespace` rule.
*/
class CSSNamespace implements AtRule
{
/**
* @var string
* @var CSSString|URL
*/
private $url;

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

Expand All @@ -35,11 +37,10 @@ class CSSNamespace implements AtRule
protected $comments = [];

/**
* @param string $url
* @param string|null $prefix
* @param CSSString|URL $url
* @param int<0, max> $lineNumber
*/
public function __construct($url, $prefix = null, int $lineNumber = 0)
public function __construct($url, ?string $prefix = null, int $lineNumber = 0)
{
$this->url = $url;
$this->prefix = $prefix;
Expand All @@ -61,33 +62,27 @@ public function render(OutputFormat $outputFormat): string
}

/**
* @return string
* @return CSSString|URL
*/
public function getUrl()
{
return $this->url;
}

/**
* @return string|null
*/
public function getPrefix()
public function getPrefix(): ?string
{
return $this->prefix;
}

/**
* @param string $url
* @param CSSString|URL $url
*/
public function setUrl($url): void
{
$this->url = $url;
}

/**
* @param string $prefix
*/
public function setPrefix($prefix): void
public function setPrefix(string $prefix): void
{
$this->prefix = $prefix;
}
Expand All @@ -101,12 +96,12 @@ public function atRuleName(): string
}

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