Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yaml-language-server: $schema=https://docs.coderabbit.ai/schema/schema.v2.json

# CodeRabbit Configuration
# StringManipulation PHP 8.3+ Library
# StringManipulation PHP 8.4+ Library
# Enforces strict quality standards: PHPStan MAX, SOLID principles, PER-CS2.0

# Language and Tone
Expand Down Expand Up @@ -54,8 +54,8 @@ reviews:
Review PHP code for adherence to PER Coding Style 2.0 guidelines.
Ensure proper namespace usage, code organisation, and separation
of concerns. Verify that SOLID principles are followed and
encourage FOOP techniquessuch as immutable data, pure functions,
and functional compositionto improve maintainability,
encourage FOOP techniques (such as immutable data, pure functions,
and functional composition) to improve maintainability,
testability, and performance.

Specific checks:
Expand All @@ -64,7 +64,7 @@ reviews:
- Final classes with static methods where appropriate
- Comprehensive docblocks with @param, @return, and @example tags
- No methods exceeding 100 lines (PHPMD rule)
- PHP 8.3+ features and patterns
- PHP 8.4+ features and patterns
- Proper error handling and null safety

- path: "tests/**/*.php"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
with:
fetch-depth: 0

- name: Set up php 8.3
- name: Set up php 8.4
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
php-version: "8.4"
extensions: mbstring, xml, zip, pdo_mysql, xhprof

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ["8.3", "8.4", "8.5"]
php-versions: ["8.4", "8.5"]

steps:
# This step checks out a copy of your repository.
Expand Down
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## Project Overview

High-performance PHP 8.3+ string manipulation library with zero production dependencies. Single final class (`StringManipulation`) exposing static methods optimised with pre-computed character mappings for O(1) lookups via `strtr()`.
High-performance PHP 8.4+ string manipulation library with zero production dependencies. Single final class (`StringManipulation`) exposing static methods optimised with pre-computed character mappings for O(1) lookups via `strtr()`.

## Build & Test Commands

**Always use Docker** to ensure consistent PHP 8.3 + AST extension environment.
**Always use Docker** to ensure consistent PHP 8.4 + AST extension environment.

| Task | Docker | Local |
|------|--------|-------|
Expand Down Expand Up @@ -82,4 +82,4 @@ Mutation testing target MSI: 88%.

## CI

GitHub Actions runs the test matrix against PHP 8.3, 8.4, and 8.5 with vulnerability scanning (osv-scanner + Enlightn).
GitHub Actions runs the test matrix against PHP 8.4 and 8.5 with vulnerability scanning (osv-scanner + Enlightn).
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Thank you for your interest in contributing to StringManipulation! This document

- Docker and Docker Compose
- Git
- PHP 8.3+ (optional, only for local development without Docker)
- PHP 8.4+ (optional, only for local development without Docker)

### Setting Up Pre-commit Hooks

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.3-cli-alpine
FROM php:8.4-cli-alpine

# Install system dependencies
RUN apk add --no-cache \
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## Introduction

Welcome to the `StringManipulation` library, a high-performance PHP 8.3+ toolkit designed for complex and efficient
Welcome to the `StringManipulation` library, a high-performance PHP 8.4+ toolkit designed for complex and efficient
string handling. Following a recent suite of O(n) optimisations, the library is now **2-5x faster**, making it one of
the most powerful and reliable solutions for developers who require speed and precision in their PHP applications.

Expand Down Expand Up @@ -201,7 +201,7 @@ of tools to ensure stability and correctness.

### Docker-Based Testing (Recommended)

For a consistent and reliable testing environment, we recommend using Docker. Our Docker setup includes PHP 8.3 with all
For a consistent and reliable testing environment, we recommend using Docker. Our Docker setup includes PHP 8.4 with all
required extensions:

```bash
Expand All @@ -217,7 +217,7 @@ docker-compose run --rm test-infection # Mutation testing

### Local Testing

If you have a local PHP 8.3+ environment configured:
If you have a local PHP 8.4+ environment configured:

```bash
# Complete test suite
Expand All @@ -243,7 +243,7 @@ composer tests

## System Requirements

- **PHP 8.3 or later** (strict typing enabled)
- **PHP 8.4 or later** (strict typing enabled)
- **`mbstring` extension** for multi-byte string operations
- **`intl` extension** for internationalisation and advanced Unicode support
- **Enabled `declare(strict_types=1);`** for robust type safety
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marjovanlier/stringmanipulation",
"description": "High-performance PHP 8.3+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements. Provides Unicode-aware operations including searchWords(), nameFix(), utf8Ansi(), removeAccents(), and isValidDate() with comprehensive testing infrastructure.",
"description": "High-performance PHP 8.4+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements. Provides Unicode-aware operations including searchWords(), nameFix(), utf8Ansi(), removeAccents(), and isValidDate() with comprehensive testing infrastructure.",
"keywords": [
"string manipulation",
"performance",
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"minimum-stability": "stable",
"require": {
"php": "^8.3"
"php": "^8.4"
},
"require-dev": {
"enlightn/security-checker": ">=2.0",
Expand Down Expand Up @@ -72,7 +72,7 @@
"test:phpstan": "Perform advanced static analysis with PHPStan for type checking, null safety, and logic validation",
"test:pest": "Run comprehensive Pest test suite with mutation testing, strict type checking and edge case coverage",
"test:psalm": "Execute Psalm static analysis for advanced type inference, purity checking, and security validation",
"test:rector": "Analyse code for modernisation opportunities and PHP 8.3+ feature adoption using Rector rules",
"test:rector": "Analyse code for modernisation opportunities and PHP 8.4+ feature adoption using Rector rules",
"test:vulnerabilities-check": "Scan all dependencies for known CVE vulnerabilities and security advisories using Enlightn Security Checker",
"fix:code-style": "Automatically fix code style issues with Pint",
"fix:rector": "Apply Rector refactorings to improve code quality",
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Site settings
title: StringManipulation
description: High-performance PHP 8.3+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements
description: High-performance PHP 8.4+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements
baseurl: "/StringManipulation"
url: "https://marjovanlier.github.io"

Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We welcome contributions to the StringManipulation library! Whether you're fixin

### Prerequisites

- PHP 8.3 or later
- PHP 8.4 or later
- Docker and Docker Compose (recommended for testing)
- Git
- Composer
Expand Down Expand Up @@ -84,7 +84,7 @@ Use descriptive branch names:
### PHP Standards

- **Strict typing**: All files must include `declare(strict_types=1);`
- **PHP 8.3+**: Use modern PHP features
- **PHP 8.4+**: Use modern PHP features
- **PSR-4 autoloading**: Follow namespace conventions
- **Final classes**: Prefer final classes with static methods
- **Typed parameters**: Always use explicit type declarations
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ composer require marjovanlier/stringmanipulation

### Requirements

- **PHP 8.3+** with strict typing
- **PHP 8.4+** with strict typing
- **mbstring extension** for multi-byte string operations
- **intl extension** for internationalisation support

Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
layout: default
title: Home
nav_order: 1
description: "High-performance PHP 8.3+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements"
description: "High-performance PHP 8.4+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements"
permalink: /
---

# StringManipulation
{: .fs-9 }

High-performance PHP 8.3+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements.
High-performance PHP 8.4+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements.
{: .fs-6 .fw-300 }

[Get Started]({{ site.baseurl }}/getting-started){: .btn .btn-primary .fs-5 .mb-4 .mb-md-0 .mr-2 }
Expand All @@ -19,7 +19,7 @@ High-performance PHP 8.3+ string manipulation library featuring O(n) algorithms

## Overview

The **StringManipulation** library is a toolkit designed for complex and efficient string handling in PHP 8.3+. Following a recent suite of O(n) optimisations, the library delivers **2-5x faster performance**, making it one of the most powerful and reliable solutions for developers who require speed and precision.
The **StringManipulation** library is a toolkit designed for complex and efficient string handling in PHP 8.4+. Following a recent suite of O(n) optimisations, the library delivers **2-5x faster performance**, making it one of the most powerful and reliable solutions for developers who require speed and precision.

### Key Features

Expand Down Expand Up @@ -92,7 +92,7 @@ Methods like `searchWords()` perform all transformations in a single pass, minim

## System Requirements

- PHP 8.3 or later (strict typing enabled)
- PHP 8.4 or later (strict typing enabled)
- `mbstring` extension for multi-byte string operations
- `intl` extension for internationalisation and advanced Unicode support

Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameters:
paths:
- src/
tmpDir: .phpstan
phpVersion: 80300
phpVersion: 80400
treatPhpDocTypesAsCertain: false
tipsOfTheDay: false
reportWrongPhpDocTypeInVarTag: true
Expand Down
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
TypedPropertyFromAssignsRector::class,
AddVoidReturnTypeWhereNoReturnRector::class,
])
->withPhpVersion(PhpVersion::PHP_83)
->withPhpVersion(PhpVersion::PHP_84)
->withSets([
LevelSetList::UP_TO_PHP_83,
LevelSetList::UP_TO_PHP_84,
SetList::CODING_STYLE,
SetList::EARLY_RETURN,
SetList::INSTANCEOF,
Expand Down
2 changes: 1 addition & 1 deletion src/StringManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static function strReplace(array|string $search, array|string $replace, s
}

// Optimize single character replacements using strtr which is faster for this case
if (is_string($search) && is_string($replace) && strlen($search) === 1) {
if (\is_string($search) && \is_string($replace) && \strlen($search) === 1) {
return strtr($subject, [$search => $replace]);
}

Expand Down
13 changes: 10 additions & 3 deletions tests/Benchmark/RemoveAccentsComplexityBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,27 @@ public static function run(): void

$previousTime = null;
$previousLength = null;
$checksum = 0;

foreach (self::LENGTHS as $length) {
$testString = self::makeString($length);
$result = '';

// Warmup
for ($i = 0; $i < self::WARMUP; ++$i) {
StringManipulation::removeAccents($testString);
$result = StringManipulation::removeAccents($testString);
}

$start = microtime(true);
for ($i = 0; $i < self::ITERATIONS; ++$i) {
StringManipulation::removeAccents($testString);
$result = StringManipulation::removeAccents($testString);
}

$duration = microtime(true) - $start;

// Consume the result so the pure calls cannot be optimised away.
$checksum += strlen($result);

$durationMs = $duration * 1000.0;
$opsPerSec = (float) self::ITERATIONS / $duration;
$usPerOp = ($duration * 1_000_000.0) / (float) self::ITERATIONS;
Expand All @@ -80,6 +85,8 @@ public static function run(): void
$previousLength = $length;
}

echo "\nChecksum (prevents dead-code elimination): " . (string) $checksum . "\n";

echo "\nInterpretation:\n";
echo "- If complexity is O(n), time should scale linearly with input size\n";
echo "- Actual ratio should be close to expected ratio\n";
Expand All @@ -92,7 +99,7 @@ public static function run(): void
*/
private static function makeString(int $length): string
{
$string = str_repeat(self::BASE, (int) ceil($length / strlen(self::BASE)));
$string = str_repeat(self::BASE, max(0, (int) ceil($length / strlen(self::BASE))));
return substr($string, 0, $length);
}
}
Expand Down
Loading