Skip to content

Commit

Permalink
[CLEANUP] Correct spelling of “(un)inlinable” (#705)
Browse files Browse the repository at this point in the history
… in method, property and variable names.

Research indicates that whilst “inlineable” may be a permitted alternative
variant, “inlinable” is more correct and mainstream.

Part of #380.
  • Loading branch information
JakeQZ authored and oliverklee committed Sep 12, 2019
1 parent c8df4de commit ee831be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
24 changes: 12 additions & 12 deletions src/Emogrifier.php
Expand Up @@ -478,7 +478,7 @@ protected function process()

$excludedNodes = $this->getNodesToExclude();
$cssRules = $this->parseCssRules($allCss);
foreach ($cssRules['inlineable'] as $cssRule) {
foreach ($cssRules['inlinable'] as $cssRule) {
// There's no real way to test "PHP Warning" output generated by the following XPath query unless PHPUnit
// converts it to an exception. Unfortunately, this would only apply to tests and not work for production
// executions, which can still flood logs/output unnecessarily. Instead, Emogrifier's error handler should
Expand All @@ -498,7 +498,7 @@ protected function process()
if (\in_array($node, $excludedNodes, true)) {
continue;
}
$this->copyInlineableCssToStyleAttribute($node, $cssRule);
$this->copyInlinableCssToStyleAttribute($node, $cssRule);
}
}

Expand All @@ -508,7 +508,7 @@ protected function process()

$this->removeImportantAnnotationFromAllInlineStyles();

$this->copyUninlineableCssToStyleNode($cssRules['uninlineable']);
$this->copyUninlinableCssToStyleNode($cssRules['uninlinable']);

\restore_error_handler();
}
Expand Down Expand Up @@ -575,8 +575,8 @@ private function getAllNodesWithStyleAttribute()
*
* @param string $css a string of raw CSS code
*
* @return string[][][] A 2-entry array with the key "inlineable" containing rules which can be inlined as `style`
* attributes and the key "uninlineable" containing rules which cannot. Each value is an array of string
* @return string[][][] A 2-entry array with the key "inlinable" containing rules which can be inlined as `style`
* attributes and the key "uninlinable" containing rules which cannot. Each value is an array of string
* sub-arrays with the keys
* "media" (the media query string, e.g. "@media screen and (max-width: 480px)",
* or an empty string if not from a `@media` rule),
Expand All @@ -594,8 +594,8 @@ private function parseCssRules($css)
$matches = $this->getCssRuleMatches($css);

$cssRules = [
'inlineable' => [],
'uninlineable' => [],
'inlinable' => [],
'uninlinable' => [],
];
/** @var string[][] $matches */
/** @var string[] $cssRule */
Expand Down Expand Up @@ -624,12 +624,12 @@ private function parseCssRules($css)
// keep track of where it appears in the file, since order is important
'line' => $key,
];
$ruleType = ($cssRule['media'] === '' && !$hasUnmatchablePseudo) ? 'inlineable' : 'uninlineable';
$ruleType = ($cssRule['media'] === '' && !$hasUnmatchablePseudo) ? 'inlinable' : 'uninlinable';
$cssRules[$ruleType][] = $parsedCssRule;
}
}

\usort($cssRules['inlineable'], [$this, 'sortBySelectorPrecedence']);
\usort($cssRules['inlinable'], [$this, 'sortBySelectorPrecedence']);

$this->caches[static::CACHE_KEY_CSS][$cssKey] = $cssRules;
}
Expand Down Expand Up @@ -956,7 +956,7 @@ private function attributeValueIsImportant($attributeValue)
*
* @return void
*/
private function copyInlineableCssToStyleAttribute(\DOMElement $node, array $cssRule)
private function copyInlinableCssToStyleAttribute(\DOMElement $node, array $cssRule)
{
$newStyleDeclarations = $this->parseCssDeclarationsBlock($cssRule['declarationsBlock']);
if ($newStyleDeclarations === []) {
Expand All @@ -979,11 +979,11 @@ private function copyInlineableCssToStyleAttribute(\DOMElement $node, array $css
/**
* Applies $cssRules to $this->domDocument, limited to the rules that actually apply to the document.
*
* @param string[][] $cssRules The "uninlineable" array of CSS rules returned by `parseCssRules`
* @param string[][] $cssRules The "uninlinable" array of CSS rules returned by `parseCssRules`
*
* @return void
*/
private function copyUninlineableCssToStyleNode(array $cssRules)
private function copyUninlinableCssToStyleNode(array $cssRules)
{
$cssRulesRelevantForDocument = \array_filter(
$cssRules,
Expand Down
24 changes: 12 additions & 12 deletions src/Emogrifier/CssInliner.php
Expand Up @@ -185,7 +185,7 @@ public function inlineCss($css = '')
$excludedNodes = $this->getNodesToExclude();
$cssRules = $this->parseCssRules($combinedCss);
$cssSelectorConverter = $this->getCssSelectorConverter();
foreach ($cssRules['inlineable'] as $cssRule) {
foreach ($cssRules['inlinable'] as $cssRule) {
try {
$nodesMatchingCssSelectors = $this->xPath->query($cssSelectorConverter->toXPath($cssRule['selector']));
} catch (SyntaxErrorException $e) {
Expand All @@ -200,7 +200,7 @@ public function inlineCss($css = '')
if (\in_array($node, $excludedNodes, true)) {
continue;
}
$this->copyInlineableCssToStyleAttribute($node, $cssRule);
$this->copyInlinableCssToStyleAttribute($node, $cssRule);
}
}

Expand All @@ -210,7 +210,7 @@ public function inlineCss($css = '')

$this->removeImportantAnnotationFromAllInlineStyles();

$this->copyUninlineableCssToStyleNode($cssRules['uninlineable']);
$this->copyUninlinableCssToStyleNode($cssRules['uninlinable']);

return $this;
}
Expand Down Expand Up @@ -277,8 +277,8 @@ private function getAllNodesWithStyleAttribute()
*
* @param string $css a string of raw CSS code
*
* @return string[][][] A 2-entry array with the key "inlineable" containing rules which can be inlined as `style`
* attributes and the key "uninlineable" containing rules which cannot. Each value is an array of string
* @return string[][][] A 2-entry array with the key "inlinable" containing rules which can be inlined as `style`
* attributes and the key "uninlinable" containing rules which cannot. Each value is an array of string
* sub-arrays with the keys
* "media" (the media query string, e.g. "@media screen and (max-width: 480px)",
* or an empty string if not from a `@media` rule),
Expand All @@ -299,8 +299,8 @@ private function parseCssRules($css)
$matches = $this->getCssRuleMatches($css);

$cssRules = [
'inlineable' => [],
'uninlineable' => [],
'inlinable' => [],
'uninlinable' => [],
];
/** @var string[][] $matches */
/** @var string[] $cssRule */
Expand Down Expand Up @@ -329,12 +329,12 @@ private function parseCssRules($css)
// keep track of where it appears in the file, since order is important
'line' => $key,
];
$ruleType = ($cssRule['media'] === '' && !$hasUnmatchablePseudo) ? 'inlineable' : 'uninlineable';
$ruleType = ($cssRule['media'] === '' && !$hasUnmatchablePseudo) ? 'inlinable' : 'uninlinable';
$cssRules[$ruleType][] = $parsedCssRule;
}
}

\usort($cssRules['inlineable'], [$this, 'sortBySelectorPrecedence']);
\usort($cssRules['inlinable'], [$this, 'sortBySelectorPrecedence']);

$this->caches[static::CACHE_KEY_CSS][$cssKey] = $cssRules;

Expand Down Expand Up @@ -620,11 +620,11 @@ private function attributeValueIsImportant($attributeValue)
/**
* Applies $cssRules to $this->domDocument, limited to the rules that actually apply to the document.
*
* @param string[][] $cssRules The "uninlineable" array of CSS rules returned by `parseCssRules`
* @param string[][] $cssRules The "uninlinable" array of CSS rules returned by `parseCssRules`
*
* @return void
*/
private function copyUninlineableCssToStyleNode(array $cssRules)
private function copyUninlinableCssToStyleNode(array $cssRules)
{
$cssRulesRelevantForDocument = \array_filter(
$cssRules,
Expand Down Expand Up @@ -712,7 +712,7 @@ private function replaceUnmatchableNotComponent(array $matches)
*
* @return void
*/
private function copyInlineableCssToStyleAttribute(\DOMElement $node, array $cssRule)
private function copyInlinableCssToStyleAttribute(\DOMElement $node, array $cssRule)
{
$newStyleDeclarations = $this->parseCssDeclarationsBlock($cssRule['declarationsBlock']);
if ($newStyleDeclarations === []) {
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CssInlinerTest.php
Expand Up @@ -2621,11 +2621,11 @@ public function inlineCssNotInDebugModeKeepsInvalidOrUnrecognizedSelectorsInMedi
/**
* @test
*/
public function copyUninlineableCssToStyleNodeHasNoSideEffects()
public function copyUninlinableCssToStyleNodeHasNoSideEffects()
{
$subject = $this->buildDebugSubject('<html><a>foo</a><p>bar</p></html>');
// CSS: `a:hover { color: green; } p:hover { color: blue; }`
$uninlineableCssRules = [
$uninlinableCssRules = [
[
'media' => '',
'selector' => 'a:hover',
Expand All @@ -2642,18 +2642,18 @@ public function copyUninlineableCssToStyleNodeHasNoSideEffects()
],
];

$copyUninlineableCssToStyleNode = new \ReflectionMethod(CssInliner::class, 'copyUninlineableCssToStyleNode');
$copyUninlineableCssToStyleNode->setAccessible(true);
$copyUninlinableCssToStyleNode = new \ReflectionMethod(CssInliner::class, 'copyUninlinableCssToStyleNode');
$copyUninlinableCssToStyleNode->setAccessible(true);

$domDocument = $subject->getDomDocument();

$copyUninlineableCssToStyleNode->invoke($subject, $uninlineableCssRules);
$copyUninlinableCssToStyleNode->invoke($subject, $uninlinableCssRules);
$expectedHtml = $subject->render();

$styleElement = $domDocument->getElementsByTagName('style')->item(0);
$styleElement->parentNode->removeChild($styleElement);

$copyUninlineableCssToStyleNode->invoke($subject, $uninlineableCssRules);
$copyUninlinableCssToStyleNode->invoke($subject, $uninlinableCssRules);

self::assertSame($expectedHtml, $subject->render());
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/EmogrifierTest.php
Expand Up @@ -3185,11 +3185,11 @@ public function emogrifyNotInDebugModeKeepsInvalidOrUnrecognizedSelectorsInMedia
/**
* @test
*/
public function copyUninlineableCssToStyleNodeHasNoSideEffects()
public function copyUninlinableCssToStyleNodeHasNoSideEffects()
{
$this->subject->setHtml('<html><a>foo</a><p>bar</p></html>');
// CSS: `a:hover { color: green; } p:hover { color: blue; }`
$uninlineableCssRules = [
$uninlinableCssRules = [
[
'media' => '',
'selector' => 'a:hover',
Expand All @@ -3206,18 +3206,18 @@ public function copyUninlineableCssToStyleNodeHasNoSideEffects()
],
];

$copyUninlineableCssToStyleNode = new \ReflectionMethod(Emogrifier::class, 'copyUninlineableCssToStyleNode');
$copyUninlineableCssToStyleNode->setAccessible(true);
$copyUninlinableCssToStyleNode = new \ReflectionMethod(Emogrifier::class, 'copyUninlinableCssToStyleNode');
$copyUninlinableCssToStyleNode->setAccessible(true);

$domDocument = $this->subject->getDomDocument();

$copyUninlineableCssToStyleNode->invoke($this->subject, $uninlineableCssRules);
$copyUninlinableCssToStyleNode->invoke($this->subject, $uninlinableCssRules);
$expectedHtml = $domDocument->saveHTML();

$styleElement = $domDocument->getElementsByTagName('style')->item(0);
$styleElement->parentNode->removeChild($styleElement);

$copyUninlineableCssToStyleNode->invoke($this->subject, $uninlineableCssRules);
$copyUninlinableCssToStyleNode->invoke($this->subject, $uninlinableCssRules);

self::assertSame($expectedHtml, $domDocument->saveHTML());
}
Expand Down

0 comments on commit ee831be

Please sign in to comment.