# Technical Documentation: sebastianbergmann/version

> ℹ️ **Provenance:** In-Tree Documentation (13 Chapters) · [CodeWiki Reference](https://codewiki.google/github.com/sebastianbergmann/version) · Recency: Active (< 180 days)

## File: README.md

[](https://packagist.org/packages/sebastian/version)

# sebastian/version

**sebastian/version** is a library that helps with managing the version number of Git-hosted PHP projects.

## Installation

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

```
composer require sebastian/version
```

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:

```
composer require --dev sebastian/version
```
## Usage

The constructor of the `SebastianBergmann\Version` class expects two parameters:

* `$release` is the version number of the latest release (`X.Y.Z`, for instance) or the name of the release series (`X.Y`) when no release has been made from that branch / for that release series yet.
* `$path` is the path to the directory (or a subdirectory thereof) where the sourcecode of the project can be found. Simply passing `__DIR__` here usually suffices.

Apart from the constructor, the `SebastianBergmann\Version` class has a single public method: `asString()`.

Here is a contrived example that shows the basic usage:

```php
<?php declare(strict_types=1);
use SebastianBergmann\Version;

$version = new Version('1.0.0', __DIR__);

var_dump($version->asString());
```
```
string(18) "1.0.0-17-g00f3408"
```

When a new release is prepared, the string that is passed to the constructor as the first argument needs to be updated.

### How SebastianBergmann\Version::asString() works

* If `$path` is not (part of) a Git repository and `$release` is in `X.Y.Z` format then `$release` is returned as-is.
* If `$path` is not (part of) a Git repository and `$release` is in `X.Y` format then `$release` is returned suffixed with `-dev`.
* If `$path` is (part of) a Git repository and `$release` is in `X.Y.Z` format then the output of `git describe --tags --match 'X.Y.*'` is returned as-is. If no tag of the `X.Y` series is reachable, the output of `git describe --tags` is returned as-is.
* If `$path` is (part of) a Git repository and `$release` is in `X.Y` format then a string is returned that begins with `X.Y` and ends with information from `git describe --tags`.

---

## File: ChangeLog.md

# ChangeLog

All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.

## [7.0.1] - 2026-10-04

### Fixed

* The version string is derived from a tag of an older release series when several such tags are merged into the branch after its most recent release

## [7.0.0] - 2026-02-06

### Removed

* This component is no longer supported on PHP 8.3

## [6.0.1] - 2026-10-04

### Fixed

* The version string is derived from a tag of an older release series when several such tags are merged into the branch after its most recent release

## [6.0.0] - 2025-02-07

### Removed

* This component is no longer supported on PHP 8.2

## [5.0.2] - 2024-10-09

### Changed

* [#21](https://github.com/sebastianbergmann/version/pull/21): Avoid spawning a shell for Git

## [5.0.1] - 2024-07-03

### Changed

* This project now uses PHPStan instead of Psalm for static analysis

## [5.0.0] - 2024-02-02

### Removed

* This component is no longer supported on PHP 8.1

## [4.0.1] - 2023-02-07

### Fixed

* [#17](https://github.com/sebastianbergmann/version/pull/17): Release archive contains unnecessary assets

## [4.0.0] - 2023-02-03

### Changed

* `Version::getVersion()` has been renamed to `Version::asString()`

### Removed

* This component is no longer supported on PHP 7.3, PHP 7.4, and PHP 8.0

## [3.0.2] - 2020-09-28

### Changed

* Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3`

## [3.0.1] - 2020-06-26

### Added

* This component is now supported on PHP 8

## [3.0.0] - 2020-01-21

### Removed

* This component is no longer supported on PHP 7.1 and PHP 7.2

[7.0.1]: https://github.com/sebastianbergmann/version/compare/7.0.0...7.0.1
[7.0.0]: https://github.com/sebastianbergmann/version/compare/6.0...7.0.0
[6.0.1]: https://github.com/sebastianbergmann/version/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/sebastianbergmann/version/compare/5.0...6.0.0
[5.0.2]: https://github.com/sebastianbergmann/version/compare/5.0.1...5.0.2
[5.0.1]: https://github.com/sebastianbergmann/version/compare/5.0.0...5.0.1
[5.0.0]: https://github.com/sebastianbergmann/version/compare/4.0...5.0.0
[4.0.1]: https://github.com/sebastianbergmann/version/compare/4.0.0...4.0.1
[4.0.0]: https://github.com/sebastianbergmann/version/compare/3.0.2...4.0.0
[3.0.2]: https://github.com/sebastianbergmann/version/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/version/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/version/compare/2.0.1...3.0.0

---

## File: composer.json

{
    "name": "sebastian/version",
    "description": "Library that helps with managing the version number of Git-hosted PHP projects",
    "homepage": "https://github.com/sebastianbergmann/version",
    "license": "BSD-3-Clause",
    "authors": [
        {
            "name": "Sebastian Bergmann",
            "email": "sebastian@phpunit.de",
            "role": "lead"
        }
    ],
    "support": {
        "issues": "https://github.com/sebastianbergmann/version/issues",
        "security": "https://github.com/sebastianbergmann/version/security/policy"
    },
    "config": {
        "platform": {
            "php": "8.4.1"
        },
        "optimize-autoloader": true,
        "sort-packages": true
    },
    "prefer-stable": true,
    "require": {
        "php": ">=8.4"
    },
    "autoload": {
        "classmap": [
            "src/"
        ]
    },
    "extra": {
        "branch-alias": {
            "dev-main": "7.0-dev"
        }
    }
}

---

## File: renovate.json

{
    "$schema": "https://docs.renovatebot.com/renovate-schema.json",
    "extends": [
        "config:recommended",
        "helpers:pinGitHubActionDigestsToSemver",
        ":configMigration"
    ],
    "timezone": "Europe/Berlin",
    "baseBranchPatterns": [
        "main",
        "/^\\d+\\.\\d+$/"
    ],
    "rebaseWhen": "conflicted",
    "prHourlyLimit": 2,
    "prConcurrentLimit": 10,
    "dependencyDashboard": true,
    "labels": ["type/dependencies"],
    "platformAutomerge": true,
    "osvVulnerabilityAlerts": true,
    "dependencyDashboardOSVVulnerabilitySummary": "all",
    "vulnerabilityAlerts": {
        "enabled": true,
        "labels": ["type/security", "type/dependencies"]
    },
    "packageRules": [
        {
            "description": "Group GitHub Actions updates per branch into one PR, automerge",
            "matchManagers": ["github-actions"],
            "groupName": "github-actions",
            "automerge": true
        },
        {
            "description": "Automerge minor and patch updates after they have settled",
            "matchUpdateTypes": ["minor", "patch", "pin", "digest"],
            "automerge": true
        },
        {
            "description": "Do not update the PHP platform requirement in composer.json",
            "matchManagers": ["composer"],
            "matchDepNames": ["php"],
            "enabled": false
        },
        {
            "description": "Do not suggest major updates for Composer dependencies",
            "matchManagers": ["composer"],
            "matchUpdateTypes": ["major"],
            "enabled": false
        },
        {
            "description": "Bump composer.json ranges when updating dependencies",
            "matchManagers": ["composer"],
            "rangeStrategy": "bump"
        }
    ]
}

---

## File: SECURITY.md

# Security Policy

The library that is developed in this repository is a first-party dependency of [PHPUnit](https://github.com/sebastianbergmann/phpunit).
[PHPUnit's Security Policy](https://github.com/sebastianbergmann/phpunit/security/policy) applies to this library as well.

If you believe you have found a security vulnerability in this library, please report it to me through coordinated disclosure.

Use my [PGP key](https://sebastian-bergmann.de/gpg.asc) for encrypted email, for example when your report includes proof-of-concept exploits against third-party systems.

**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**

---

## File: tools/.phpstan/composer.json

{
    "require-dev": {
        "phpstan/phpstan": "^2.3.1",
        "phpstan/extension-installer": "^1.4.3",
        "phpstan/phpstan-strict-rules": "^2.1.0",
        "ergebnis/phpstan-rules": "^2.14.2"
    },
    "config": {
        "allow-plugins": {
            "phpstan/extension-installer": true
        }
    }
}

---

## File: .github/CODE_OF_CONDUCT.md

# Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic
  addresses, without explicit permission
* Other unethical or unprofessional conduct

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer at sebastian@phpunit.de. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident.

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.3.0, available at [https://contributor-covenant.org/version/1/3/0/][version]

[homepage]: https://contributor-covenant.org
[version]: https://contributor-covenant.org/version/1/3/0/

---

## File: .github/CONTRIBUTING.md

# Contributing to `sebastian/version`

## Welcome!

We look forward to your contributions! Here are some examples how you can contribute:

* [Report a bug](https://github.com/sebastianbergmann/version/issues/new)
* [Send a pull request to fix a bug](https://github.com/sebastianbergmann/version/pulls)


## We have a Code of Conduct

Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.


## Any contributions you make will be under the BSD-3-Clause License

When you submit code changes, your submissions are understood to be under the same [BSD-3-Clause License](https://github.com/sebastianbergmann/version/blob/main/LICENSE) that covers the project. By contributing to this project, you agree that your contributions will be licensed under its BSD-3-Clause License.


### Do Not Violate Copyright

Only submit a pull request with your own original code. Do NOT submit a pull request containing code which you have largely copied from
another project, unless you wrote the respective code yourself.

Open Source does not mean that copyright does not apply. Copyright infringements will not be tolerated and can lead to you being banned from this project and repository.


### Do Not Submit AI-Generated Pull Requests

The same goes for (largely) AI-generated pull requests. These are not welcome as they will be based on copyrighted code from others
without accreditation and without taking the license of the original code into account, let alone getting permission
for the use of the code or for re-licensing.

Aside from that, the experience is that AI-generated pull requests will be incorrect 100% of the time and cost reviewers too much time.
Submitting a (largely) AI-generated pull request will lead to you being banned from this project and repository.


## Write bug reports with detail, background, and sample code

[This is an example](https://github.com/sebastianbergmann/phpunit/issues/4376) of a bug report I wrote, and I think it's not too bad.

In your bug report, please provide the following:

* A quick summary and/or background
* Steps to reproduce
    * Be specific!
    * Give sample code if you can.
* What you expected would happen
* What actually happens
* Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

Please do not report a bug for a version of this library that is no longer supported. Please do not report a bug if you are using a version of PHP that is not supported by the version of this library you are using.

The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit. Support for this library follows the [support for the version of PHPUnit that uses a specific version of this library](https://phpunit.de/supported-versions.html).

Please post code and output as text ([using proper markup](https://guides.github.com/features/mastering-markdown/)). Do not post screenshots of code or output.


## Workflow for Pull Requests

1. Fork the repository.
2. Create your branch from `main` if you plan to implement new functionality or change existing code significantly; create your branch from the oldest branch that is affected by the bug if you plan to fix a bug.
3. Implement your change and add tests for it.
4. Ensure the test suite passes.
5. Ensure the code complies with our coding guidelines (see below).
6. Send that pull request!

Please make sure you have [set up your username and email address](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup) for use with Git. Strings such as `silly nick name <root@localhost>` look really stupid in the commit history of a project.

We encourage you to [sign your Git commits with your GPG key](https://docs.github.com/en/github/authenticating-to-github/signing-commits).

Pull requests for bug fixes must be made for the oldest branch that is supported (see above). Pull requests for new features must be based on the `main` branch.

We are trying to keep backwards compatibility breaks to an absolute minimum. Please take this into account when proposing changes.

Due to time constraints, we are not always able to respond as quickly as we would like. Please do not take delays personal and feel free to remind us if you feel that we forgot to respond.


## Development

This project uses [PHPUnit](https://phpunit.de/) for testing:

```shell
./vendor/bin/phpunit
```

This project uses [PHPStan](https://phpstan.org/) for static analysis:

```shell
./tools/phpstan
```

This project uses [PHP-CS-Fixer](https://cs.symfony.com/) to enforce coding guidelines:

```shell
./tools/php-cs-fixer fix
```

The commands shown above require an autoloader script at `vendor/autoload.php`. This can be generated like so:

```shell
./tools/composer dump-autoload
```

Please understand that we will not accept a pull request when its changes violate this project's coding guidelines or break the test suite.

---

## File: .github/FUNDING.yml

github: sebastianbergmann
liberapay: sebastianbergmann
thanks_dev: u/gh/sebastianbergmann
tidelift: "packagist/sebastian/version"

---

## File: .github/workflows/api-surface-check.yaml

# https://github.com/marketplace/actions/api-surface-check-for-php

on:
  pull_request:
    paths-ignore:
      - ".editorconfig"
      - "LICENSE"
      - "**.md"
      - "**.png"
      - "**.svg"
      - "tests/**"

name: "API Surface Check"

permissions: {}

concurrency:
  group: api-surface-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  signal:
    name: Signal
    runs-on: ubuntu-latest
    steps:
      - run: "true"

---

## File: .github/workflows/api-surface-comment.yaml

# https://github.com/marketplace/actions/api-surface-check-for-php

on:
  # zizmor: ignore[dangerous-triggers] workflow_run is required to comment on
  # PRs from forks; this workflow only runs a pinned action and does not check
  # out PR-controlled code.
  workflow_run:
    workflows: ["API Surface Check"]
    types: [completed]

name: "API Surface Comment"

permissions:
  contents: read

concurrency:
  group: api-surface-comment-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
  cancel-in-progress: true

jobs:
  check-api-surface:
    name: Check API Surface
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write # required to post the API surface diff comment on the PR
    steps:
      - uses: composer/api-surface-check@bba9f1cb940df6e02271b1b6158679ac0b3f39d3 # 1.0.1

---

## File: .github/workflows/ci.yaml

# https://docs.github.com/en/actions

on:
  - pull_request
  - push

name: CI

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  COMPOSER_ROOT_VERSION: 7.0.x-dev
  PHP_VERSION: 8.5

permissions:
  contents: read

jobs:
  coding-guidelines:
    name: Coding Guidelines

    runs-on: ubuntu-latest
    timeout-minutes: 5

    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 1
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          persist-credentials: false

      - name: Use local branch
        shell: bash
        env:
          EVENT_NAME: ${{ github.event_name }}
          HEAD_REF: ${{ github.head_ref }}
          REF_NAME: ${{ github.ref_name }}
        run: |
          if [ "$EVENT_NAME" = "pull_request" ]; then
            BRANCH="$HEAD_REF"
          else
            BRANCH="$REF_NAME"
          fi
          git branch -D "$BRANCH" 2>/dev/null || true
          git branch "$BRANCH" HEAD
          git checkout "$BRANCH"

      - name: Install PHP
        uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
        with:
          php-version: ${{ env.PHP_VERSION }}
          coverage: none
          tools: none

      - name: Run PHP-CS-Fixer
        run: ./tools/php-cs-fixer fix --dry-run --show-progress=dots --using-cache=no --verbose

  static-analysis:
    name: Static Analysis

    runs-on: ubuntu-latest
    timeout-minutes: 5

    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 1
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          persist-credentials: false

      - name: Use local branch
        shell: bash
        env:
          EVENT_NAME: ${{ github.event_name }}
          HEAD_REF: ${{ github.head_ref }}
          REF_NAME: ${{ github.ref_name }}
        run: |
          if [ "$EVENT_NAME" = "pull_request" ]; then
            BRANCH="$HEAD_REF"
          else
            BRANCH="$REF_NAME"
          fi
          git branch -D "$BRANCH" 2>/dev/null || true
          git branch "$BRANCH" HEAD
          git checkout "$BRANCH"

      - name: Install PHP
        uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
        with:
          php-version: ${{ env.PHP_VERSION }}
          coverage: none
          tools: none

      - name: Install dependencies with Composer
        run: ./tools/composer update --no-interaction --no-ansi --no-progress

      - name: Run PHPStan
        run: ./tools/phpstan analyse --no-progress --error-format=github

---

## File: .github/workflows/release.yaml

# https://docs.github.com/en/actions

on:
  push:
    tags:
      - "**"

name: Release

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

permissions:
  contents: read

jobs:
  release:
    name: Release

    runs-on: ubuntu-latest

    permissions:
      contents: write # required to create GitHub releases

    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Install PHP with extensions
        uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
        with:
          php-version: 8.3
          coverage: none
          extensions: none
          tools: none

      - name: Determine tag
        run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"

      - name: Parse ChangeLog
        run: build/scripts/extract-release-notes.php "${RELEASE_TAG}" > release-notes.md

      - name: Create release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: gh release create "${RELEASE_TAG}" --title "sebastian/version ${RELEASE_TAG}" --notes-file release-notes.md

--- METRICS ---
- Files Extracted: 13
- Estimated Token Budget: ~5528 tokens
- Recency Window: Active (< 180 days)
- Canonical Reference: https://codewiki.google/github.com/sebastianbergmann/version
