Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
29978d7
Add missing exception classes: TypeMismatchException, ImmutableExcept…
May 30, 2025
7ef80d4
Implement DataTypeInterface methods in TypeSafeArray and fix setValue…
May 30, 2025
00d3fcb
Fix testIsFieldRequired by providing a default value for required field
May 30, 2025
fa35f67
Add core interfaces and exceptions for type system
May 30, 2025
ab71390
Add ImmutableStruct implementation with validation rules
May 30, 2025
20fc451
Add Vector implementation with abstract base class
May 30, 2025
aceca21
Add TypeSafeArray implementation with type constraints and update sca…
May 30, 2025
c5e02a2
Update .gitignore to exclude build directory
May 30, 2025
f4bd3af
Implement DynamicArray with capacity management, fix FixedSizeArray w…
May 30, 2025
8e4bc6d
feat: implement core features and refactoring
May 30, 2025
e8a910b
feat: update to PHP 8.4 and add CI support
Oct 20, 2025
7abc92d
feat: add static analysis and code quality tools
Oct 20, 2025
648abd1
feat: enhance Dictionary with missing methods
Oct 20, 2025
3aad116
feat: add algebraic data types for better error handling
Oct 20, 2025
2b70fb9
feat: add comprehensive Laravel integration
Oct 20, 2025
f0501c3
feat: add attribute-based validation system
Oct 20, 2025
8d7ad9c
feat: implement PHP 8.4 array functions for better performance
Oct 20, 2025
251faa4
refactor: improve type safety in abstract classes
Oct 20, 2025
afe6b54
feat: add comprehensive benchmark suite
Oct 20, 2025
ca08bc8
docs: update documentation and add comprehensive examples
Oct 20, 2025
9283f1a
chore: update composer.lock with new dependencies
Oct 20, 2025
c3c66e3
docs: update README to showcase PHP 8.4 features
Oct 20, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Align CI matrix with PHP ^8.4 requirement to fix Composer failures.

Current matrix includes 8.2/8.3, but composer.json requires php ^8.4; jobs on 8.2/8.3 fail early.

Recommended diff:

-                php: [8.2, 8.3, 8.4]
+                php: [8.4]

Optional (reduce dependency conflicts on prefer-lowest):

-              run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
+              run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction -W
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
php: [8.2, 8.3, 8.4]
php: [8.4]
🤖 Prompt for AI Agents
.github/workflows/main.yml around line 12: the GitHub Actions PHP matrix
includes versions 8.2 and 8.3 which conflict with composer.json requiring php
^8.4 and cause CI failures; update the matrix to only include PHP 8.4 (or 8.4
and newer supported versions) instead of 8.2/8.3 so jobs run with a compatible
PHP, and optionally add a separate job/matrix entry to run with composer
--prefer-lowest if you want to exercise lowest-dependency compatibility.

stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ yarn-error.log
vendor
vendor/
composer.lock
todo.txt
todo.txt
/build/**
109 changes: 109 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace PHPSTORM_META {

// Helper functions for PHP Datatypes
override(\int8(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8::class,
]));

override(\int16(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16::class,
]));

override(\int32(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int32::class,
]));

override(\int64(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int64::class,
]));

override(\uint8(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8::class,
]));

override(\uint16(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt16::class,
]));

override(\uint32(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt32::class,
]));

override(\uint64(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt64::class,
]));

override(\float32(0.0), map([
'' => \Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32::class,
]));

override(\float64(0.0), map([
'' => \Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64::class,
]));

override(\char(''), map([
'' => \Nejcc\PhpDatatypes\Scalar\Char::class,
]));

override(\byte(0), map([
'' => \Nejcc\PhpDatatypes\Scalar\Byte::class,
]));
Comment on lines +6 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that the uint64() helper function exists.

The override mappings for scalar type helpers follow the correct pattern. However, the uint64() helper referenced at lines 34-36 is not present in the provided code snippets from src/helpers.php, while all other scalar helpers (int8, int16, int32, int64, uint8, uint16, uint32, float32, float64, char, byte) are confirmed to exist.

Run the following script to verify the uint64() helper exists in the codebase:


🏁 Script executed:

#!/bin/bash
# Description: Check for uint64 helper function definition

# Search for uint64 function definition
rg -nP '^\s*function\s+uint64\s*\(' src/helpers.php

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Description: Broader search for uint64 function definition across entire codebase

# Search for uint64 function definition anywhere in the codebase
rg -nP 'function\s+uint64\s*\(' --type=php

# Also check if it's defined as part of namespace or differently
rg -nP '\buint64\s*\(' --type=php -A 2 -B 2 | head -50

Length of output: 233


🏁 Script executed:

#!/bin/bash
# Description: Verify that other scalar helpers exist to confirm uint64 is missing

# Search for int64 and uint32 helper definitions
rg -nP 'function\s+(int64|uint32|char|byte)\s*\(' --type=php -A 3

Length of output: 667


The uint64() helper function is missing from the codebase but is referenced in the meta file.

Verification confirms that other scalar helpers (int64 at line 70, uint32 at line 118, char at line 149, byte at line 156) are properly defined in src/helpers.php. However, uint64() does not exist anywhere in the codebase, yet lines 34-36 of .phpstorm.meta.php contain an override for \uint64(0).

Either remove the uint64 override from .phpstorm.meta.php (lines 34-36) or implement the missing uint64() helper function in src/helpers.php.


override(\some(0), map([
'' => \Nejcc\PhpDatatypes\Composite\Option::class,
]));

override(\none(), map([
'' => \Nejcc\PhpDatatypes\Composite\Option::class,
]));

override(\option(0), map([
'' => \Nejcc\PhpDatatypes\Composite\Option::class,
]));

override(\ok(0), map([
'' => \Nejcc\PhpDatatypes\Composite\Result::class,
]));

override(\err(0), map([
'' => \Nejcc\PhpDatatypes\Composite\Result::class,
]));

override(\result(function(){}), map([
'' => \Nejcc\PhpDatatypes\Composite\Result::class,
]));

override(\stringArray([]), map([
'' => \Nejcc\PhpDatatypes\Composite\Arrays\StringArray::class,
]));

override(\intArray([]), map([
'' => \Nejcc\PhpDatatypes\Composite\Arrays\IntArray::class,
]));

override(\floatArray([]), map([
'' => \Nejcc\PhpDatatypes\Composite\Arrays\FloatArray::class,
]));

override(\byteSlice([]), map([
'' => \Nejcc\PhpDatatypes\Composite\Arrays\ByteSlice::class,
]));

override(\listData([]), map([
'' => \Nejcc\PhpDatatypes\Composite\ListData::class,
]));

override(\dictionary([]), map([
'' => \Nejcc\PhpDatatypes\Composite\Dictionary::class,
]));

override(\struct([]), map([
'' => \Nejcc\PhpDatatypes\Composite\Struct\Struct::class,
]));

override(\union([], []), map([
'' => \Nejcc\PhpDatatypes\Composite\Union\UnionType::class,
]));
}
76 changes: 73 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,77 @@
# Changelog

All notable changes to `php-datatypes` will be documented in this file
All notable changes to `php-datatypes` will be documented in this file.

## 1.0.0 - 201X-XX-XX
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- initial release
## [2.0.0] - 2024-12-19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Verify the release date.

The changelog lists the release date as "2024-12-19", but this PR was created on 2025-05-30. Ensure the date reflects the actual or intended release date for v2.0.0.

🤖 Prompt for AI Agents
In CHANGELOG.md around line 8, the release date for version 2.0.0 is listed as
"2024-12-19" but that is inconsistent with the PR date; update the date to the
correct/intended release date (e.g., the actual release date or the PR merge
date 2025-05-30), or if the release date is unknown, replace the static date
with "TBD" and add a short note or PR reference indicating it should be set at
release time.


### Added
- PHP 8.4 compatibility and CI testing
- PHPStan static analysis configuration (level 9)
- `Dictionary::toArray()`, `isEmpty()`, and `getAll()` methods
- Benchmark suite for performance testing
- `Option<T>` type for nullable values
- `Result<T, E>` type for error handling
- Mutation testing with Infection
- Laravel integration (validation rules, service provider)
- PHPStorm metadata for better IDE support
- Comprehensive example demonstrating all features

### Changed
- **BREAKING:** All concrete datatype classes are now `final` to prevent inheritance issues
- **BREAKING:** All methods now have explicit return types for better type safety
- **BREAKING:** All Laravel validation rules and casts are now `final`
- Updated minimum PHP version requirement to ^8.4
- Enhanced CI workflow to test PHP 8.4
- Improved code quality with static analysis
- Enhanced parameter type declarations throughout the codebase

### Fixed
- Missing serialization methods in Dictionary class
- Missing return types in various methods
- Parameter type declarations for better type safety

### Migration Guide

If you were extending any datatype classes, you'll need to use composition instead:

**Before (v1.x):**
```php
class MyCustomInt8 extends Int8 {
// custom implementation
}
```

**After (v2.0):**
```php
class MyCustomInt8 {
private Int8 $int8;

public function __construct(int $value) {
$this->int8 = new Int8($value);
}

public function getValue(): int {
return $this->int8->getValue();
}

// delegate other methods as needed
}
```

## [1.0.0] - 2024-12-19

### Added
- Initial release with comprehensive type system
- Scalar types: Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128
- Floating point types: Float32, Float64
- Boolean, Char, and Byte types
- Composite types: Arrays, Structs, Unions, Lists, Dictionaries
- String types: AsciiString, Utf8String, EmailString, and 20+ specialized string types
- Vector types: Vec2, Vec3, Vec4
- Serialization support: JSON, XML, Binary
- Comprehensive test suite (592 tests, 1042 assertions)
- Helper functions for all types
- Type-safe operations with overflow/underflow protection
Loading
Loading