PHPackages                             voral/vinc-file-version-regexp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. voral/vinc-file-version-regexp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

voral/vinc-file-version-regexp
==============================

An extension for voral/version-increment to update version strings in custom files using regular expressions.

1.0.0(1y ago)00MITPHPPHP &gt;=8.1CI passing

Since Apr 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Voral/vinc-file-version-regexp)[ Packagist](https://packagist.org/packages/voral/vinc-file-version-regexp)[ Docs](https://github.com/Voral/vinc-file-version-regexp)[ RSS](/packages/voral-vinc-file-version-regexp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

vinc-file-version-regexp
========================

[](#vinc-file-version-regexp)

[RU](README.ru.md)

[![PHP Tests](https://github.com/Voral/vinc-file-version-regexp/actions/workflows/php.yml/badge.svg)](https://github.com/Voral/vinc-file-version-regexp/actions/workflows/php.yml/badge.svg)[![Code Coverage](https://camo.githubusercontent.com/b06fbe88bf587a7cc815722d9a21db516c75e51a93e2c0eec02f17e550534264/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f566f72616c2f76696e632d66696c652d76657273696f6e2d7265676578702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Voral/vinc-file-version-regexp/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c824d97d1de4dd6b0b2110b97da44394524241648a64980446871680ae99e65f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f566f72616c2f76696e632d66696c652d76657273696f6e2d7265676578702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Voral/vinc-file-version-regexp/?branch=master)

An extension for [voral/version-increment](https://github.com/Voral/vs-version-incrementor) to update version strings in custom files using regular expressions.

This tool allows you to automatically update version numbers in arbitrary files (e.g., PHP, JSON, XML) during the versioning process. It integrates seamlessly with the `voral/version-increment` package and listens to the `BEFORE_VERSION_SET` event to perform replacements based on a provided regular expression.

---

Key Features
------------

[](#key-features)

- **Custom File Support**: Update version strings in any file format using flexible regular expressions.
- **Event-Based Integration**: Listens to the `BEFORE_VERSION_SET` event from `voral/version-increment`.
- **Error Handling with Unique Codes**: Prevents conflicts between multiple extensions by supporting error code deltas.
- **Flexible Configuration**: Define custom regular expressions to match version strings in various formats.
- **Extensibility**: Easily integrate into existing workflows with minimal configuration.

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require --dev voral/vinc-file-version-regexp
```

---

Usage
-----

[](#usage)

To use this extension, configure it in your `.vs-version-increment.php` file by adding a listener for the `BEFORE_VERSION_SET` event. Here's an example:

```
use Vasoft\VersionIncrement\Config;
use Vasoft\VersionIncrement\Events\EventType;
use Vasoft\VersionIncrement\Extension\RegexpFileModifier;

$config = (new Config());
$config->getEventBus()->addListener(
        EventType::BEFORE_VERSION_SET,
        new RegexpFileModifier(
            './src/version.php',
            '#(\$version\s*=\s*\'|"v)\d+\.\d+\.\d+(\'|";)#s'
        )
    );

return $config;
```

### Explanation:

[](#explanation)

- **File Path**: Specify the path to the file where the version string should be updated (e.g., `./src/version.php`).
- **Regular Expression**: Provide a regex pattern to locate the version string. The pattern must include:
    - Group 1: The part of the string before the version.
    - Group 2: The part of the string after the version.
- **Error Code Delta**: Optionally, specify a delta value to ensure unique error codes when using multiple extensions.

---

Example Use Cases
-----------------

[](#example-use-cases)

### 1. Updating a PHP File

[](#1-updating-a-php-file)

If your project contains a `version.php` file like this:

```

```

The extension will update it to:

```

```

### 2. Updating a JSON File

[](#2-updating-a-json-file)

For a `config.json` file:

```
{
  "version": "1.0.0"
}
```

The extension can update it to:

```
{
  "version": "2.0.0"
}
```

---

Error Handling
--------------

[](#error-handling)

The extension provides detailed error messages and unique error codes to help diagnose issues:

- **FileNotFoundException**: Thrown if the specified file does not exist.
- **FileNotWritableException**: Thrown if the file is not writable.
- **PatternNotFoundException**: Thrown if the regular expression does not match any part of the file content.

Error codes are offset by a configurable `errorCodeDelta` to avoid conflicts with other extensions.

---

Configuration Options
---------------------

[](#configuration-options)

You can customize the behavior of the extension by adjusting its parameters:

ParameterDescription`filePath`The path to the file where the version will be updated.`regexp`The regular expression used to locate the version string.`errorCodeDelta`Optional delta value to ensure unique error codes across multiple modules.---

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps:

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Submit a pull request with a clear description of your changes.

Ensure that your code adheres to the project's coding standards and includes appropriate tests.

---

Testing
-------

[](#testing)

Run the following commands to test the package:

```
composer test
```

Generate a code coverage report:

```
composer coverage
```

Perform static analysis:

```
composer stan
```

Check coding standards:

```
composer fixer
```

Run all checks at once:

```
composer check
```

---

License
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.

---

Useful Links
------------

[](#useful-links)

- [voral/version-increment](https://github.com/Voral/vs-version-incrementor): The main package this extension integrates with.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance48

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

385d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce4dfd67b12e198becd71253723d0c83044cb4689b735f2fd4eee4ac191c41ec?d=identicon)[Voral](/maintainers/Voral)

---

Top Contributors

[![Voral](https://avatars.githubusercontent.com/u/327165?v=4)](https://github.com/Voral "Voral (18 commits)")

---

Tags

automation-toolchangelogchangelog-generatorcommit-analysiscomposergitphp-toolsemantic-versioningversion-incrementversion-managementcommit analysisPHP Libraryversion controlconventional-commitssemantic versioningversion-managementdev-toolphp toolversion incrementchangelog generatorgit integrationautomated versioningrelease managementchangelog formattingautomation toolversion-updater

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/voral-vinc-file-version-regexp/health.svg)

```
[![Health](https://phpackages.com/badges/voral-vinc-file-version-regexp/health.svg)](https://phpackages.com/packages/voral-vinc-file-version-regexp)
```

###  Alternatives

[lodash-php/lodash-php

A port of Lodash to PHP

527719.0k5](/packages/lodash-php-lodash-php)[liip/rmt

Release Management Tool: a handy tool to help releasing new version of your software

457448.7k74](/packages/liip-rmt)[marcocesarato/php-conventional-changelog

Generate changelogs and release notes from a project's commit messages and metadata and automate versioning with semver.org and conventionalcommits.org

2511.3M109](/packages/marcocesarato-php-conventional-changelog)[ramsey/conventional-commits

A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook action!

1931.2M122](/packages/ramsey-conventional-commits)[tomzx/php-semver-checker

PHP Semantic Versioning Checker

434232.8k2](/packages/tomzx-php-semver-checker)[niiknow/bayes

a machine learning lib

6950.0k](/packages/niiknow-bayes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
