Skip to content

Commit

Permalink
Rename method to renderNonConditionalAtRules
Browse files Browse the repository at this point in the history
This clarifies that not all at-rules are rendered.  Also rename the associated
property, and add note in the DocBlock for the method that `@charset` rules are
discarded.
  • Loading branch information
JakeQZ committed Apr 17, 2021
1 parent 37bb360 commit 16b1744
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/CssInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ private function removeUnsupportedOfTypePseudoClasses(string $selectorPart): str
*/
private function copyUninlinableCssToStyleNode(CssDocument $cssDocument): void
{
$css = $cssDocument->renderAtRules();
$css = $cssDocument->renderNonConditionalAtRules();

// avoid including unneeded class dependency if there are no rules
if ($this->getMatchingUninlinableCssRules() !== []) {
Expand Down
11 changes: 6 additions & 5 deletions src/Utilities/CssDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CssDocument
*
* @var string
*/
private $atRules;
private $nonConditionalAtRules;

/**
* @param string $css
Expand All @@ -53,7 +53,7 @@ public function __construct(string $css)
= $this->extractImportAndCharsetRules($cssWithoutComments);
[$this->styleRules, $cssAtRules]
= $this->extractNonConditionalAtRules($cssWithoutCommentsCharsetOrImport);
$this->atRules = $cssImportRules . $cssAtRules;
$this->nonConditionalAtRules = $cssImportRules . $cssAtRules;
}

/**
Expand Down Expand Up @@ -93,13 +93,14 @@ public function getStyleRulesData(array $allowedMediaTypes): array

/**
* Renders at-rules from the parsed CSS that are valid and not conditional group rules (i.e. not rules such as
* `@media` which contain style rules whose data is returned by {@see getStyleRulesData}).
* `@media` which contain style rules whose data is returned by {@see getStyleRulesData}). Also does not render
* `@charset` rules; these are discarded (only UTF-8 is supported).
*
* @return string
*/
public function renderAtRules(): string
public function renderNonConditionalAtRules(): string
{
return $this->atRules;
return $this->nonConditionalAtRules;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Utilities/CssDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function rendersValidNonConditionalAtRule(string $atRuleCss, string $cssB
{
$subject = new CssDocument($cssBefore . $atRuleCss);

$result = $subject->renderAtRules();
$result = $subject->renderNonConditionalAtRules();

self::assertStringContainsString(\trim($atRuleCss), $result);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public function rendersMultipleNonConditionalAtRules(string $cssBetween): void
{
$subject = new CssDocument('@import "foo.css";' . $cssBetween . self::VALID_AT_FONT_FACE_RULE);

$result = $subject->renderAtRules();
$result = $subject->renderNonConditionalAtRules();

// The content of the rendered rules is covered by other tests. Here just check the number of rendered rules.
self::assertSame(2, \substr_count($result, '@'));
Expand Down Expand Up @@ -338,7 +338,7 @@ public function discardsAtCharsetRule(): void
{
$subject = new CssDocument('@charset "UTF-8";');

$result = $subject->renderAtRules();
$result = $subject->renderNonConditionalAtRules();

self::assertSame('', $result);
}
Expand All @@ -355,7 +355,7 @@ public function notRendersInvalidNonConditionalAtRule(string $atRuleCss, string
{
$subject = new CssDocument($cssBefore . $atRuleCss);

$result = $subject->renderAtRules();
$result = $subject->renderNonConditionalAtRules();

self::assertThat(
\trim($result),
Expand Down Expand Up @@ -396,7 +396,7 @@ public function notRendersAtMediaRule(): void
{
$subject = new CssDocument('@media screen { p { color: red; } }');

$result = $subject->renderAtRules();
$result = $subject->renderNonConditionalAtRules();

self::assertSame('', $result);
}
Expand Down

0 comments on commit 16b1744

Please sign in to comment.