Skip to content
CAI
Software that uses CAICheck a score

tijsverkoyen/CssToInlineStyles

64.4

Adequate · 19 September 2026

688

lines of production code

PHP

primary language

1

measurement over time

CAI band scale
CAI lens gauges

What this system is

This system is a PHP library designed to convert external CSS styles into inline style attributes within HTML documents, primarily for email rendering. It processes CSS from style tags and strings, applying rules based on selector specificity and preserving existing inline styles. The implementation leverages the DOM extension for parsing and includes robust handling of CSS cleanup and error management.

Features

Added Sumo email template example with CSS inlining

The example directory now includes a new 'sumo' email template, consisting of an HTML file (index.htm) and a corresponding stylesheet (style.css). A new index.php script demonstrates how to use the CssToInlineStyles library to inline the CSS into the HTML, providing a working example of the library's usage for email rendering.

example · high confidence

Initial release of CSS-to-inline-styles conversion

The library now provides a \CssToInlineStyles\ class that converts external CSS styles into inline style attributes on HTML elements. It supports merging CSS from \\<style\>\ tags with additional CSS strings, respects CSS specificity by sorting rules, and handles existing inline styles by appending new properties rather than overwriting them. The implementation uses the DOM extension for parsing and manipulation, ensuring UTF-8 encoding is preserved and handling potential DOM parsing errors gracefully.

src · high confidence

New CSS Processor for extracting and cleaning styles

Added a new Processor class in src/Css that handles extracting CSS from HTML style tags and cleaning raw CSS strings. The processor now removes @charset declarations and media queries during cleanup, strips HTML comments before parsing style tags, and uses possessive quantifiers in regular expressions to prevent PCRE limits from being reached.

src/Css · high confidence

Architecture

Repository structure modernized with PSR-4, Composer, and CI configuration

The project has been restructured to follow modern PHP standards, replacing the legacy single-file \css\_to\_inline\_styles.php\ with a proper PSR-4 autoloadable structure. This change introduces Composer support via \composer.json\, standardizes development workflows with \.editorconfig\ and \phpstan.dist.neon\, and migrates continuous integration from Travis CI to GitHub Actions. Additionally, \CHANGELOG.md\ and \README.md\ have been added to document the library's history and usage, while \.gitattributes\ and \.gitignore\ are configured to manage exports and local artifacts.

(repo-wide) · high confidence

Behavioural changes

CSS property parsing now respects selector specificity

The CSS property processor has been refactored to track and preserve the specificity of each CSS property during parsing. The new \Property\ class stores an optional \Specificity\ object from the Symfony CssSelector component, and the \Processor\ now accepts and forwards this specificity when converting CSS strings into property objects. This ensures that the original specificity context is retained, allowing downstream logic to correctly handle CSS cascade rules based on selector weight rather than just property order or presence.

src/Css/Property · high confidence

CSS specificity calculation and rule processing overhaul

The CSS rule processing logic has been rewritten to correctly calculate and apply CSS specificity when determining which styles to inline. The new \Processor\ class computes specificity for each selector using regex patterns for IDs, classes/attributes/pseudo-classes, and type/pseudo-elements, then sorts rules by specificity (and document order for ties) to ensure correct style precedence. This change replaces the previous approach, which did not properly handle specificity, and includes safeguards against regex failures that could previously cause processing errors.

src/Css/Rule · high confidence

Test coverage

Added test coverage for CSS Processor; Added unit tests for CSS Property parsing and representation; Added unit tests for CSS Rule processing and specificity calculation; Initial test suite for CSS-to-inline-styles conversion.

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Baseline

  • First survey — no prior run to compare against. CAI 64.

Lenses

  • Code Health 99
  • Architecture 69
  • Maturity 49
  • Readiness 75
  • Security 100

Changes since last survey

  • 300 commits — 271 feature/other, 29 fixes

By area

  • (root) — 121 commits
  • (repo) — 93 commits
  • src/Css — 26 commits
  • src/CssToInlineStyles.php — 26 commits
  • tests/Css — 11 commits
  • tests/CssToInlineStylesTest.php — 11 commits
  • .github/workflows — 4 commits
  • example/config.php — 1 commit
  • example/examples — 1 commit
  • example/index.php — 1 commit
  • src/Exception.php — 1 commit
  • src/Selector.php — 1 commit
  • tests/CssToOnlineStylesTest.php — 1 commit
  • tests/bootstrap.php — 1 commit
  • tests/examples — 1 commit

Notable commits

  • fix: Added @charset removal to doCleanup() to fix processing stylesheets with @charset
  • fix: Bugfix for specifity array key
  • fix: Composer fixes
  • fix: Fix Travis CI
  • fix: Fix broken link
  • fix: Fix for http://github.com/tijsverkoyen/CssToInlineStyles/issues#issue/1
  • fix: Fix multibyte string conversion
  • fix: Fix properties split on base64 encoded url content
  • fix: Fix the detection of style tags
  • fix: Fix the test expectation
  • fix: Fixed a stupid mistake where I called a method twice
  • fix: Fixed issue with comparing Specificity
  • fix: Fixed some PHPDoc
  • fix: Fixed some PHPDoc
  • fix: Fixed some code-styling issues
  • fix: Fixed some issues detected with SensioLabsInsight
  • fix: Fixed sortOnSpecifity sort order.
  • fix: Fixed stripping of XML-Header
  • fix: Fixed the XPath query for selectors with a class or id descendant
  • fix: Fixed the branch alias for master
  • …and 280 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

tijsverkoyen/CssToInlineStyles was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 19 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit a0aef6022b3d84b8c72855ded8581458d82d5013 — the exact code this score is about.
  • Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-13a154b7f5d1.