Skip to content
CAI
Software that uses CAICheck a score

briannesbitt/Carbon

66.9

Adequate · 25 September 2026

54.7k

lines of production code

PHP

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is the Carbon PHP library, a comprehensive date and time manipulation toolkit that extends native PHP DateTime functionality with a fluent API. It provides robust features for parsing, formatting, arithmetic, and localization, including specific integrations for Laravel and Doctrine. The codebase also includes a command-line interface and static analysis support via PHPStan to aid in development and code quality.

How it got here

2012–2015 — Carbon 3.0 modernization and strict typing

11 changes.

This period focused on upgrading the Carbon library to version 3.0, enforcing strict typing and modern PHP 8 features while dropping support for older PHP versions. The work included significant architectural refactoring, such as introducing enums and immutable defaults, alongside comprehensive expansion of test coverage and localization support for new languages.

2016–2018 — modularization and Laravel integration

12 changes.

The codebase underwent significant architectural refactoring, splitting monolithic traits into single-responsibility modules and restructuring the exception hierarchy for better safety and clarity. Concurrently, a Laravel ServiceProvider was introduced to automatically synchronize Carbon's locale with the application environment. This period was heavily supported by comprehensive test coverage and fixture creation for CarbonPeriod, CarbonImmutable, CarbonTimeZone, and the new factory components.

2019–2020 — CLI tooling and static analysis support

11 changes.

This period focused on expanding the Carbon library's ecosystem by introducing a command-line interface and enhancing static analysis capabilities through a PHPStan extension for macros. The work also included adding comprehensive test coverage for new features, including ISO language/region lists, Jenssegers compatibility, and Doctrine DBAL integrations.

2021–2023 — PHP 8.2 compatibility and lazy loading

5 changes.

This period focused on adapting Carbon to PHP 8.2+ by introducing lazy-loading mechanisms for translation and message formatting to improve performance and compatibility. The work included implementing lazy wrappers for date periods and message formatters, alongside comprehensive unit tests for exception classes and new enums.

Features

Add Carbon CLI installer and bootstrap script

A new \bin/carbon\ executable and its Windows batch wrapper \bin/carbon.bat\ have been added to the project. These files bootstrap the Carbon CLI by locating the \autoload.php\ file and invoking the \Carbon\\Cli\\Invoker\ class, enabling users to run Carbon commands directly from the command line.

bin · high confidence

Add Carbon CLI installer via Invoker

A new Invoker class has been added to the Carbon CLI component to handle the installation of the carbon-cli package. When the main CLI class is not available and the 'install' command is invoked, the system automatically executes a composer require command to install the carbon-cli dependency, allowing users to bootstrap the CLI tool directly.

src/Carbon/Cli · high confidence

Added ISO language and region name lists

The Carbon library now includes dedicated data files for ISO 639-2 language codes and ISO 3166-2 region codes. The new \src/Carbon/List/languages.php\ file provides a mapping of language codes to their ISO names and native names, while \src/Carbon/List/regions.php\ maps region codes to their short ISO names. These additions support more accurate and localized display of language and region information within the library.

src/Carbon/List · high confidence

Added localization support for Afar, Akan, Amharic, Aragonese, and Maithili

Carbon now includes translation files for several new languages and regional variants, enabling users to display dates and relative time strings in Afar (aa, aa\_DJ, aa\_ER, aa\_ET), Akan (ak, ak\_GH), Amharic (am, am\_ET), Aragonese (an, an\_ES), and Maithili (anp, anp\_IN). These additions allow applications to correctly format month names, weekdays, and human-readable time differences (such as 'ago' or 'from now') for speakers of these languages.

src/Carbon/Lang · high confidence

Automatic Carbon locale synchronization with Laravel application locale

The new ServiceProvider in src/Carbon/Laravel automatically keeps Carbon's locale settings in sync with the Laravel application's locale. On boot, it applies the current Laravel locale to Carbon, CarbonImmutable, CarbonPeriod, and CarbonInterval instances, and also updates the Illuminate Carbon class and the Date facade if they are present. It registers an event listener for the 'locale.changed' event (or 'Illuminate\\Foundation\\Events\\LocaleUpdated' in newer Laravel versions) to update Carbon's locale whenever the application locale changes at runtime. The service provider also synchronizes the fallback locale and allows customization of how the app instance and locale are retrieved via configurable getters.

src/Carbon/Laravel · high confidence

Carbon date library initial implementation

The Carbon library is introduced as a new dependency for handling date and time operations in PHP. This change adds the Carbon.php file, which extends the native DateTime class to provide a more fluent and intuitive API for date manipulation, including static helper methods like now(), create(), and instance(), as well as property accessors for common date components (year, month, day, etc.).

Carbon · high confidence

Introduces lazy-loaded MessageFormatterMapper with type-aware loading

A new MessageFormatterMapper class has been added to the Carbon package. It acts as a wrapper around Symfony's MessageFormatter and implements lazy loading logic that dynamically selects between a strong-typed or weak-typed implementation based on the PHP version's support for strict type declarations in the underlying translation interface. This allows the library to maintain compatibility across different PHP versions while optimizing for strict typing where available.

src/Carbon/MessageFormatter · high confidence

PHPStan support for Carbon macros

Added a PHPStan extension that enables static analysis of dynamically registered macros on Carbon classes. The new \MacroExtension\ and \MacroMethodReflection\ classes allow PHPStan to recognize and type-check methods added via \Carbon::macro()\, including their parameters, return types, and deprecation status, improving code quality checks for applications using Carbon's macro feature.

src/Carbon/PHPStan · high confidence

Architecture

Carbon traits refactored into dedicated, single-responsibility modules

The Carbon date/time library has reorganized its internal structure by splitting the monolithic trait implementations into distinct, focused traits. The \src/Carbon/Traits\ directory now contains separate files for specific capabilities: \Boundaries.php\ for start/end of unit methods, \Cast.php\ for type conversion, \Comparison.php\ for equality and ordering checks, \Converter.php\ for formatting and string casting, \Creator.php\ for instance construction and parsing, and \Date.php\ for core date properties and modifiers. This modularization improves code maintainability and allows for more granular usage of Carbon's functionality.

src/Carbon/Traits · high confidence

Behavioural changes

Carbon exceptions are restructured with specific classes and safety guards

The exception hierarchy in src/Carbon/Exceptions has been completely rewritten: generic exceptions are replaced by specific classes (e.g., BadComparisonUnitException, BadFluentConstructorException, ImmutableException, InvalidDateException, OutOfRangeException, ParseErrorException, PeriodFilterSafetyException, UnknownGetterException, UnknownMethodException, UnknownSetterException, UnknownUnitException), each exposing relevant context via getters. Immutable operations now throw ImmutableException with static factory methods (fromClass/fromMethod) and a deprecated constructor. Period unserialization is protected by PeriodFilterSafetyException, which blocks unsafe filters and provides an allow() opt-in. NotACarbonClassException now includes a TogglableDetection trait and an expectCarbonInterface() helper to enforce CarbonInterface implementation. All new exception files use strict\_types and declare the Carbon namespace, improving error clarity and safety for users catching or handling Carbon errors.

src/Carbon/Exceptions · high confidence

Introduction of Carbon 3.0 with strict typing and modern PHP features

This release introduces Carbon 3.0, a major version upgrade that drops support for PHP versions prior to 7.4 and enforces strict typing across the codebase. The library now utilizes modern PHP 8 syntax, including named arguments, union types, and the \match\ expression. Significant architectural changes include the introduction of \CarbonImmutable\ as the default instance type, the addition of \Unit\, \Month\, and \WeekDay\ enums for type-safe operations, and a refactored translation system via \AbstractTranslator\ and \Callback\ classes to improve performance and flexibility. New capabilities include \diffInDaysFiltered\, \diffInWeekdays\, and \diffInWeekendDays\ for granular date difference calculations, as well as enhanced \CarbonPeriod\ features like \quarterly()\ and \monthly()\ generators.

src/Carbon · high confidence

Lazy message formatters now support choice formatting and weak typing

The lazy message formatter implementation has been updated to implement both MessageFormatterInterface and ChoiceMessageFormatterInterface, enabling support for pluralization and choice-based message formatting. Additionally, the formatter now uses weak typing for the message and locale parameters in the format method, allowing for more flexible input handling while still delegating to the underlying Symfony formatter.

lazy/Carbon/MessageFormatter · high confidence

Lazy-loading compatibility layers for PHP 8.2+ and translation

Carbon now uses lazy-loaded wrapper classes to maintain compatibility with PHP 8.2 and improve translation handling. For date periods, it introduces ProtectedDatePeriod and UnprotectedDatePeriod to wrap the native DatePeriod class; the protected version explicitly deprecates direct access to internal properties (start, end, current, interval, recurrences, include\_start\_date) which are no longer synchronized with the actual period state in PHP 8.2+, while the unprotected version provides a minimal extension for environments where property access is not required. For translations, it adds LazyTranslator with both strong-typed (TranslatorStrongType.php) and weak-typed (TranslatorWeakType.php) implementations, allowing the library to lazily load translation logic and access internal message catalogue properties without immediate dependency on full translation infrastructure.

lazy/Carbon · high confidence

Standardized development environment and build tooling

The project now enforces consistent code formatting and editor behavior through the addition of \.editorconfig\ (4-space indentation, LF line endings) and a comprehensive \.php-cs-fixer.dist.php\ configuration (PSR-12, PHP 7.1+ migration). Build and packaging are streamlined by introducing \build.php\ to generate version-specific archives and \extension.neon\ for PHPStan macro support, while legacy documentation generation scripts (\readme.php\, \readme.src.md\) have been removed. IDE assistance is improved via \.phpstorm.meta.php\, and security reporting is formalized with \SECURITY.md\.

(repo-wide) · high confidence

Test coverage

Added Jenssegers compatibility tests; Added Laravel integration tests with mock application components; Added PHPStan integration tests for macro and mixin behavior; Added localization tests for Afar and Afrikaans locales; Added test fixture for custom CarbonTimeZone behavior; Added test fixtures for Carbon mixin, serialization, and formatting edge cases; Added test fixtures for CarbonImmutable behavior validation; Added test fixtures for CarbonInterval mixin functionality; Added test fixtures for CarbonPeriod testing; Added test fixtures for timezone handling, type cases, and dynamic intervals; Added tests for Factory, Callback, and WrapperClock components; Added tests for macro context nesting and detection; Added tests for the CLI Invoker component; Added tests for the Language class and Translator behavior; Added unit tests for Carbon exception classes; Added unit tests for CarbonImmutable; Added unit tests for CarbonTimeZone conversion, creation, and getter methods; Added unit tests for Doctrine DBAL type conversions and SQL declarations; Added unit tests for WeekDay, Month, and Unit enums; Expanded test coverage for CarbonInterval; Expanded test coverage for CarbonPeriod functionality; Expanded unit test coverage for Carbon date manipulation and construction; Removed Carbon test suite; Restructured test infrastructure with new base classes and tooling.

Dependencies

Carbon 3.0: PHP 8.1+ requirement and Symfony 6/7/8 support

This release updates the Carbon library to version 3.0, raising the minimum PHP version to 8.1 and requiring the ext-json extension. It modernizes the codebase by switching to PSR-4 autoloading and adding support for Symfony 6.3.12, 7.0, and 8.0 (specifically symfony/clock and symfony/translation). The package now depends on carbonphp/carbon-doctrine-types and implements the PSR Clock interface, while dev dependencies have been updated to include PHPUnit 10, PHPStan 2, and PHP-CS-Fixer 3.

(dependencies) · high confidence

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

This is the PUBLIC form of this artifact. Findings are listed in full, but the details of SECURITY findings — which rule fired, in which file, on which line, and how to fix it — are deliberately withheld, and any secret-scanner results are excluded entirely. Where detail is absent here it was REMOVED FOR PUBLICATION; it is not missing from the analysis. The complete artifact is available from the repository owner.

Score

  • CAI 49 → 67 (+17.6)
  • Rubric changed (rubric-2026.08.15 → rubric-2026.09.15) — scores are not directly comparable.

Lenses

  • Code Health 94 → 89 (-4.9)
  • Architecture 94 → 100 (+5.8)
  • Maturity 59 → 57 (-2.3)
  • Readiness 34 → 73 (+38.3)
  • Security 50 → 70 (+20.0)

Resolved (44)

  • Coverage not measured — test suite did not build
  • Dimension evaluation failed
  • Duplicated block (16 lines × 4) (src/Carbon/Traits/Creator.php)
  • Duplicated block (31 lines × 26) (src/Carbon/AbstractTranslator.php)
  • Duplicated block (7 lines × 2) (src/Carbon/CarbonInterval.php)
  • Duplicated block (8 lines × 2) (src/Carbon/Traits/Date.php)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • …and 24 more

New (136)

  • CarbonInterval.__construct (cognitive 61) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.__construct (cyclomatic 41) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.doCascade (cognitive 29) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.forHumans (cognitive 81) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.forHumans (cyclomatic 51) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.fromString (cognitive 26) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.fromString (cyclomatic 52) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.getDateIntervalSpec (cognitive 24) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.getDateIntervalSpec (cyclomatic 22) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.getForHumansParameters (cognitive 16) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.set (cyclomatic 20) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.total (cognitive 25) (src/Carbon/CarbonInterval.php)
  • CarbonInterval.total (cyclomatic 20) (src/Carbon/CarbonInterval.php)
  • CarbonPeriod.__call (cognitive 18) (src/Carbon/CarbonPeriod.php)
  • CarbonPeriod.__call (cyclomatic 52) (src/Carbon/CarbonPeriod.php)
  • CarbonPeriod.__construct (cognitive 36) (src/Carbon/CarbonPeriod.php)
  • CarbonPeriod.__construct (cyclomatic 36) (src/Carbon/CarbonPeriod.php)
  • CarbonPeriod.__unserialize (cognitive 39) (src/Carbon/CarbonPeriod.php)
  • CarbonPeriod.__unserialize (cyclomatic 35) (src/Carbon/CarbonPeriod.php)
  • Change coupling: CarbonInterface.php ↔ FactoryImmutable.php (src/Carbon/CarbonInterface.php)
  • …and 116 more

Changes since last survey

  • 41 commits — 29 feature/other, 12 fixes

By area

  • (repo) — 18 commits
  • src/Carbon — 11 commits
  • (root) — 4 commits
  • .github/workflows — 3 commits
  • tests/Carbon — 2 commits
  • tests/Laravel — 2 commits
  • tests/Localization — 1 commit

Notable commits

  • fix: Fix CarbonInterval::spec() when the fraction holds a second or more
  • fix: Fix carbonphp/carbon-doctrine-types in tests
  • fix: Fix test flakiness
  • fix: Merge branch 'master' of github.com:CarbonPHP/carbon into dualfroz/fix-round-numeric-precision-carry
  • fix: Merge pull request #141 from iliaal/fix/quote-match-format-pattern
  • fix: Merge pull request #142 from CarbonPHP/fix/spl-object-id
  • fix: Merge pull request #144 from CarbonPHP/fix/php-8-6-compatibility
  • fix: Merge pull request #145 from CarbonPHP/fix/unserialize-sanitization
  • fix: Merge pull request #3357 from dylanpulver/fix/translated-format-missing-tokens
  • fix: Merge pull request #3359 from dualfroz/dualfroz/fix-round-numeric-precision-carry
  • fix: Merge pull request #3366 from t1gor/fix/interval-spec-microseconds-overflow
  • fix: fix: carry numeric round/floor/ceil precision >= 60s into minute/hour/day
  • change: Add e, p, X and x to the translatedFormat() replacement map
  • change: Add tests
  • change: Apply review feedback on matchFormatPattern chunk loop
  • change: Bump pnpm/action-setup from 6.0.10 to 6.1.0
  • change: Bump pnpm/action-setup from 6.0.9 to 6.0.10
  • change: Carry a numeric rounding precision out of any unit, not just seconds
  • change: Drop mmm_suffix
  • change: Fix Yoruba (yo) locale: correct "second" unit spelling to "aayá"
  • …and 21 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

briannesbitt/Carbon 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 25 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 a82fdca185d02d2d098333d3d7b5ac09e0849e65 — 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-a9cd699f3cd5.