Skip to content

[CLEANUP] And some more annotations for non-empty strings #1199

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 19, 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: 3 additions & 0 deletions src/CSSList/AtRuleBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function atRuleArgs(): string
return $this->arguments;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
$formatter = $outputFormat->getFormatter();
Expand Down
3 changes: 3 additions & 0 deletions src/CSSList/KeyFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function getAnimationName(): string
return $this->animationName;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
$formatter = $outputFormat->getFormatter();
Expand Down
3 changes: 3 additions & 0 deletions src/Comment/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function setComment(string $commentText): void
$this->commentText = $commentText;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return '/*' . $this->commentText . '*/';
Expand Down
6 changes: 5 additions & 1 deletion src/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class OutputFormat
/**
* Value format: `"` means double-quote, `'` means single-quote
*
* @var string
* @var non-empty-string
*/
private $stringQuotingType = '"';

Expand Down Expand Up @@ -181,6 +181,8 @@ final class OutputFormat
private $indentationLevel = 0;

/**
* @return non-empty-string
*
* @internal
*/
public function getStringQuotingType(): string
Expand All @@ -189,6 +191,8 @@ public function getStringQuotingType(): string
}

/**
* @param non-empty-string $quotingType
*
* @return $this fluent interface
*/
public function setStringQuotingType(string $quotingType): self
Expand Down
3 changes: 3 additions & 0 deletions src/Property/CSSNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function getLineNo(): int
return $this->lineNumber;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return '@namespace ' . ($this->prefix === null ? '' : $this->prefix . ' ')
Expand Down
3 changes: 3 additions & 0 deletions src/Property/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public function getCharset(): string
return $this->charset->getString();
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return "{$outputFormat->getFormatter()->comments($this)}@charset {$this->charset->render($outputFormat)};";
Expand Down
3 changes: 3 additions & 0 deletions src/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function getLocation(): URL
return $this->location;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return $outputFormat->getFormatter()->comments($this) . '@import ' . $this->location->render($outputFormat)
Expand Down
3 changes: 3 additions & 0 deletions src/RuleSet/AtRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function atRuleArgs(): string
return $this->arguments;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
$formatter = $outputFormat->getFormatter();
Expand Down
2 changes: 2 additions & 0 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public function getSelectors(): array
}

/**
* @return non-empty-string
*
* @throws OutputException
*/
public function render(OutputFormat $outputFormat): string
Expand Down
3 changes: 3 additions & 0 deletions src/Value/CSSFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public function getArguments(): array
return $this->components;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
$arguments = parent::render($outputFormat);
Expand Down
3 changes: 3 additions & 0 deletions src/Value/CSSString.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function getString(): string
return $this->string;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
Comment on lines +86 to 89
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably also add non-empty for OutputFormat::$stringQuotingType and getter/setter.

{
$string = \addslashes($this->string);
Expand Down
3 changes: 3 additions & 0 deletions src/Value/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public function getColorDescription(): string
return $this->getName();
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
if ($this->shouldRenderAsHex($outputFormat)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Value/LineName.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static function parse(ParserState $parserState): LineName
return new LineName($names, $parserState->currentLine());
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return '[' . parent::render(OutputFormat::createCompact()) . ']';
Expand Down
3 changes: 3 additions & 0 deletions src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public function isRelative(): bool
return false;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
$locale = \localeconv();
Expand Down
3 changes: 3 additions & 0 deletions src/Value/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function getURL(): CSSString
return $this->url;
}

/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return "url({$this->url->render($outputFormat)})";
Expand Down