Skip to content

Commit ff1af18

Browse files
authored
[TASK] Add native type declarations for CSSNamespace (#1187)
Part of #811
1 parent f371c22 commit ff1af18

3 files changed

Lines changed: 14 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Please also have a look at our
3434
- Use more native type declarations and strict mode
3535
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
3636
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
37-
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181, #1183, #1184, #1186)
37+
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181, #1183, #1184, #1186,
38+
#1187)
3839
- Add visibility to all class/interface constants (#469)
3940

4041
### Deprecated

config/phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ parameters:
3030
count: 1
3131
path: ../src/CSSList/Document.php
3232

33-
-
34-
message: '#^Cannot call method render\(\) on string\.$#'
35-
identifier: method.nonObject
36-
count: 1
37-
path: ../src/Property/CSSNamespace.php
38-
39-
-
40-
message: '#^Only booleans are allowed in an if condition, string given\.$#'
41-
identifier: if.condNotBoolean
42-
count: 1
43-
path: ../src/Property/CSSNamespace.php
44-
4533
-
4634
message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#'
4735
identifier: if.condNotBoolean

src/Property/CSSNamespace.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66

77
use Sabberworm\CSS\Comment\Comment;
88
use Sabberworm\CSS\OutputFormat;
9+
use Sabberworm\CSS\Value\CSSString;
10+
use Sabberworm\CSS\Value\URL;
911

1012
/**
1113
* `CSSNamespace` represents an `@namespace` rule.
1214
*/
1315
class CSSNamespace implements AtRule
1416
{
1517
/**
16-
* @var string
18+
* @var CSSString|URL
1719
*/
1820
private $url;
1921

2022
/**
21-
* @var string
23+
* @var string|null
2224
*/
2325
private $prefix;
2426

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

3739
/**
38-
* @param string $url
39-
* @param string|null $prefix
40+
* @param CSSString|URL $url
4041
* @param int<0, max> $lineNumber
4142
*/
42-
public function __construct($url, $prefix = null, int $lineNumber = 0)
43+
public function __construct($url, ?string $prefix = null, int $lineNumber = 0)
4344
{
4445
$this->url = $url;
4546
$this->prefix = $prefix;
@@ -61,33 +62,27 @@ public function render(OutputFormat $outputFormat): string
6162
}
6263

6364
/**
64-
* @return string
65+
* @return CSSString|URL
6566
*/
6667
public function getUrl()
6768
{
6869
return $this->url;
6970
}
7071

71-
/**
72-
* @return string|null
73-
*/
74-
public function getPrefix()
72+
public function getPrefix(): ?string
7573
{
7674
return $this->prefix;
7775
}
7876

7977
/**
80-
* @param string $url
78+
* @param CSSString|URL $url
8179
*/
8280
public function setUrl($url): void
8381
{
8482
$this->url = $url;
8583
}
8684

87-
/**
88-
* @param string $prefix
89-
*/
90-
public function setPrefix($prefix): void
85+
public function setPrefix(string $prefix): void
9186
{
9287
$this->prefix = $prefix;
9388
}
@@ -101,12 +96,12 @@ public function atRuleName(): string
10196
}
10297

10398
/**
104-
* @return array<int, string>
99+
* @return array{0: CSSString|URL|non-empty-string, 1?: CSSString|URL}
105100
*/
106101
public function atRuleArgs(): array
107102
{
108103
$result = [$this->url];
109-
if ($this->prefix) {
104+
if (\is_string($this->prefix) && $this->prefix !== '') {
110105
\array_unshift($result, $this->prefix);
111106
}
112107
return $result;

0 commit comments

Comments
 (0)