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
32 changes: 19 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ permissions:
contents: read

on:
schedule:
- cron: '0 4 * * *' # daily 04:00 UTC canary keepalive
pull_request:
branches:
- "*"
push:
branches:
- 'master'
workflow_dispatch: {}

env:
COLUMNS: 120
Expand All @@ -34,20 +37,20 @@ jobs:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 8.2, 8.3, 8.4 ]
php-version: [ 8.3, 8.4, 8.5 ]
coverage: [ xdebug, none ]
composer_flags: [ "--prefer-lowest", "" ]
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-version }}'
coverage: '${{ matrix.coverage }}'
php-version: ${{ matrix.php-version }}
coverage: ${{ matrix.coverage }}
tools: composer
extensions: ast

Expand All @@ -58,29 +61,30 @@ jobs:
run: make test --no-print-directory

- name: Uploading coverage to coveralls
if: "${{ matrix.coverage == 'xdebug' }}"
if: '${{ matrix.coverage == ''xdebug'' }}'
continue-on-error: true
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make report-coveralls --no-print-directory || true

- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
continue-on-error: true
with:
name: PHPUnit - ${{ matrix.php-version }} - ${{ matrix.coverage }}
path: build/
overwrite: true


linters:
name: Linters
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 8.2, 8.3, 8.4 ]
php-version: [ 8.3, 8.4, 8.5 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v7
with:
fetch-depth: 0

Expand All @@ -99,22 +103,23 @@ jobs:
run: make codestyle --no-print-directory

- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
continue-on-error: true
with:
name: Linters - ${{ matrix.php-version }}
path: build/
overwrite: true


report:
name: Reports
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 8.2, 8.3, 8.4 ]
php-version: [ 8.3, 8.4, 8.5 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v7
with:
fetch-depth: 0

Expand All @@ -133,8 +138,9 @@ jobs:
run: make report-all --no-print-directory

- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
continue-on-error: true
with:
name: Reports - ${{ matrix.php-version }}
path: build/
overwrite: true
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# JBZoo / SimpleTypes

[![CI](https://github.com/JBZoo/SimpleTypes/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/SimpleTypes/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/SimpleTypes/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/SimpleTypes?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/SimpleTypes/coverage.svg)](https://shepherd.dev/github/JBZoo/SimpleTypes) [![Psalm Level](https://shepherd.dev/github/JBZoo/SimpleTypes/level.svg)](https://shepherd.dev/github/JBZoo/SimpleTypes) [![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/simpletypes/badge)](https://www.codefactor.io/repository/github/jbzoo/simpletypes/issues)
[![Stable Version](https://poser.pugx.org/jbzoo/simpletypes/version)](https://packagist.org/packages/jbzoo/simpletypes/) [![Total Downloads](https://poser.pugx.org/jbzoo/simpletypes/downloads)](https://packagist.org/packages/jbzoo/simpletypes/stats) [![Dependents](https://poser.pugx.org/jbzoo/simpletypes/dependents)](https://packagist.org/packages/jbzoo/simpletypes/dependents?order_by=downloads) [![GitHub License](https://img.shields.io/github/license/jbzoo/simpletypes)](https://github.com/JBZoo/SimpleTypes/blob/master/LICENSE)
[![CI](https://github.com/JBZoo/SimpleTypes/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/SimpleTypes/actions/workflows/main.yml?query=branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/JBZoo/SimpleTypes/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/SimpleTypes?branch=master)
[![Psalm Coverage](https://shepherd.dev/github/JBZoo/SimpleTypes/coverage.svg)](https://shepherd.dev/github/JBZoo/SimpleTypes)
[![Psalm Level](https://shepherd.dev/github/JBZoo/SimpleTypes/level.svg)](https://shepherd.dev/github/JBZoo/SimpleTypes)
[![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/simpletypes/badge)](https://www.codefactor.io/repository/github/jbzoo/simpletypes/issues)

[![Stable Version](https://poser.pugx.org/jbzoo/simpletypes/version)](https://packagist.org/packages/jbzoo/simpletypes/)
[![Total Downloads](https://poser.pugx.org/jbzoo/simpletypes/downloads)](https://packagist.org/packages/jbzoo/simpletypes/stats)
[![Dependents](https://poser.pugx.org/jbzoo/simpletypes/dependents)](https://packagist.org/packages/jbzoo/simpletypes/dependents?order_by=downloads)
[![GitHub License](https://img.shields.io/github/license/jbzoo/simpletypes)](https://github.com/JBZoo/SimpleTypes/blob/master/LICENSE)



Expand Down Expand Up @@ -380,8 +388,8 @@ echo $value->rule(); // "eur"

## Requirements

- PHP 8.2 or higher
- jbzoo/utils ^7.3
- PHP 8.3 or higher
- jbzoo/utils ^8.0

## License

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
"prefer-stable" : true,

"require" : {
"php" : "^8.2",
"jbzoo/utils" : "^7.3"
"php" : "^8.3",
"jbzoo/utils" : "^8.0"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^7.2"
"jbzoo/toolbox-dev" : "^8.0"
},

"autoload" : {
Expand All @@ -55,7 +55,7 @@

"extra" : {
"branch-alias" : {
"dev-master" : "7.x-dev"
"dev-master" : "8.x-dev"
}
}
}
34 changes: 22 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@
@copyright Copyright (C) JBZoo.com, All rights reserved.
@see https://github.com/JBZoo/SimpleTypes
-->
<phpunit bootstrap="tests/autoload.php" colors="true">
<phpunit bootstrap="tests/autoload.php"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false">
<coverage>
<report>
<clover outputFile="build/coverage_xml/main.xml"/>
<php outputFile="build/coverage_cov/main.cov"/>
<text outputFile="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/>
</report>
</coverage>

<testsuites>
<testsuite name="All">
<testsuite name="PHPUnit">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/coverage_xml/main.xml"/>
<log type="coverage-php" target="build/coverage_cov/main.cov"/>
<log type="junit" target="build/coverage_junit/main.xml"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/>
<junit outputFile="build/coverage_junit/main.xml"/>
</logging>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
41 changes: 15 additions & 26 deletions src/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,30 @@ public function __toString()
}

/**
* Serialize.
* @return array
* Serialize the object state (modern replacement for __sleep()).
*
* The whole object graph (config, formatter, parser, ids) is rebuilt from the scalar dump
* on wake-up via prepareObject() - exactly as the previous __sleep()/__wakeup() pair did -
* so only that dump has to be stored.
*
* @return array<string, string>
*/
public function __sleep()
public function __serialize(): array
{
$result = [];
$reflect = new \ReflectionClass($this);
$propList = $reflect->getProperties();

foreach ($propList as $prop) {
if ($prop->isStatic()) {
continue;
}
$result[] = $prop->name;
}

$this->log('Serialized');

return $result;
return ['dump' => $this->dump(false)];
}

/**
* Wake up after serialize.
* Wake up after serialize (modern replacement for __wakeup()).
*
* @param array<string, string> $data
*/
public function __wakeup(): void
public function __unserialize(array $data): void
{
$this->log('--> wakeup start');
$this->prepareObject($this->dump(false));
$this->prepareObject($data['dump'] ?? '');
$this->log('<-- Wakeup finish');
}

Expand Down Expand Up @@ -140,7 +136,6 @@ public function __set(string $name, mixed $value): void
/**
* Experimental! Methods aliases.
* @deprecated
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function __call(string $name, array $arguments): mixed
{
Expand Down Expand Up @@ -337,17 +332,11 @@ public function setEmpty(bool $getClone = false): self
return $this->modifier(0.0, 'Set empty', $getClone);
}

/**
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function add(array|float|int|self|string|null $value, bool $getClone = false): self
{
return $this->customAdd($value, $getClone);
}

/**
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function subtract(array|float|int|self|string|null $value, bool $getClone = false): self
{
return $this->customAdd($value, $getClone, true);
Expand Down Expand Up @@ -684,7 +673,7 @@ private function prepareObject(array|float|int|string|null $value = null, ?Abstr

// check that default rule
$rules = $this->formatter->getList(true);
if (!\array_key_exists($this->default, $rules) || \count($rules) === 0) {
if (!\array_key_exists($this->default, $rules)) {
throw new Exception("{$this->type}: Default rule not found!");
}

Expand Down
4 changes: 1 addition & 3 deletions tests/InstancesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public function testCreateTypes(): int
return $count;
}

/**
* @depends testCreateTypes
*/
#[\PHPUnit\Framework\Attributes\Depends('testCreateTypes')]
public function testCreateConfigs(int $typeCount): void
{
$files = \scandir(\realpath(__DIR__ . '/../src/Config'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use JBZoo\SimpleTypes\Config\AbstractConfig;
use JBZoo\SimpleTypes\Type\AbstractType;

abstract class AbstractTypeTest extends PHPUnit
abstract class AbstractTypeTestCase extends PHPUnit
{
protected string $type;

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/AreaTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use function JBZoo\PHPUnit\isSame;

final class AreaTypeTest extends AbstractTypeTest
final class AreaTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Area';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/DegreeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function JBZoo\PHPUnit\is;
use function JBZoo\PHPUnit\isSame;

final class DegreeTypeTest extends AbstractTypeTest
final class DegreeTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Degree';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/InfoTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function JBZoo\PHPUnit\isSame;
use function JBZoo\PHPUnit\isTrue;

final class InfoTypeTest extends AbstractTypeTest
final class InfoTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Info';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/LengthTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use function JBZoo\PHPUnit\isSame;

final class LengthTypeTest extends AbstractTypeTest
final class LengthTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Length';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/TempTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use function JBZoo\PHPUnit\isSame;

final class TempTypeTest extends AbstractTypeTest
final class TempTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Temp';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/TimeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use function JBZoo\PHPUnit\isSame;

final class TimeTypeTest extends AbstractTypeTest
final class TimeTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Time';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/VolumeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use function JBZoo\PHPUnit\isSame;

final class VolumeTypeTest extends AbstractTypeTest
final class VolumeTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Volume';

Expand Down
2 changes: 1 addition & 1 deletion tests/Types/WeightTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use function JBZoo\PHPUnit\isSame;

final class WeightTypeTest extends AbstractTypeTest
final class WeightTypeTest extends AbstractTypeTestCase
{
protected string $type = 'Weight';

Expand Down
Loading