Skip to content

Version 2.7: Generic classes (& more). PHP 8.4-tested

Latest
Compare
Choose a tag to compare
@FireMidge FireMidge released this 24 Dec 12:53

Breaking changes

  1. next() and previous() on IsCollectionType no longer return a value.
    • This is because of \Iterator requiring next to return void, and it makes sense for next and previous to function in the same way.
  2. ConversionError now extends from \ValueError (previously \RuntimeException)

Features

  1. Added default classes to be able to use some of the traits instantly without having to create an empty new class each time. The classes added are:

    • \FireMidge\ValueObject\Generic\AnyCollection
    • \FireMidge\ValueObject\Generic\AnyFloat
    • \FireMidge\ValueObject\Generic\AnyInteger
    • \FireMidge\ValueObject\Generic\AnyString
    • All of the above classes implement \JsonSerializable, and AnyCollection also implements the \Iterator interface.
  2. Added default Percentage and Email classes

    • \FireMidge\ValueObject\Generic\Percentage
    • \FireMidge\ValueObject\Generic\Email
  3. New methods on IsCollectionType:

    • merge
    • withMerged
    • pop
    • popMultiple
    • split
    • shuffle
    • withReversedOrder
  4. jsonSerialize has been implemented for all types, to aid easy serialisation.

    • In order for automatic serialisation to happen when json_encode is called, the class using these traits has to implement the JsonSerializable interface.
    • The new generic classes all implement it already.

Improvements

  1. Added Psalm annotations in the collection type.
    • This allows for better IDE-internal type hints for methods like toArray(), first(), last() etc.
    • Usage is showcased in README.md
  2. More specific error messages for adding or subtracting a value from a float or integer type beyond allowed min/max values.
  3. Option to return $reasons from a ConversionError
  4. InvalidValue renders different types better, e.g. non-strings are no longer wrapped in double quotes
  5. Library is tested against PHP 8.4. Worked without changes to the code.
  6. Upgraded from PhpUnit 9 to 11.5 and upgraded Infection to 29.0.
    • Changed all docblock annotations to attributes
    • Infection's output is vastly improved, removing the vast majority of false positives. MSI has changed from 97% to 99%, Mutation Code Coverage from 98% to 99% and Covered Code MSI from 98% to 100%.