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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/.gitattributes export-ignore
/phpunit.xml export-ignore
/tests export-ignore
/wiki export-ignore
/README.md
10 changes: 4 additions & 6 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name: Documentation

on:
pull_request:
types: [ closed ]
push:
branches: [ 'main' ]

jobs:
publish:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

strategy:
matrix:
php-version:
- "7.4"
php-version: [ '8.1' ]

steps:
- name: Checkout source code
Expand All @@ -39,7 +37,7 @@ jobs:
- name: Install Dependencies
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Pusblish documentation to Wiki
- name: Publish documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "wiki/"
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ name: Test

on:
push:
branches:
- main
branches: [ 'main' ]
pull_request:
types: [ opened, synchronize, reopened ]
types: [ 'opened', 'synchronize', 'reopened' ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [ "8.0", "8.1" ]
php-version: [ '8.1' ]

steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
Expand All @@ -36,8 +37,9 @@ jobs:
- name: Validate composer.json and composer.lock
run: composer validate

- name: Install Dependencies
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Execute Static Code analysis
run: composer analyse
Expand Down
23 changes: 16 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"php": "^8.1.0",
"ext-json": "*",
"ramsey/uuid": "^4.1",
"nesbot/carbon": "^2.40",
Expand All @@ -21,20 +21,29 @@
"complex-heart/contracts": "^1.0.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.3",
"fakerphp/faker": "^1.9.1",
"phpstan/phpstan": "^1.6.8",
"pestphp/pest": "^1.4"
"pestphp/pest": "^1.22.3",
"pestphp/pest-plugin-mock": "^1.0.0",
"pestphp/pest-plugin-faker": "^1.0.0",
"phpstan/phpstan": "^1.9.0"
},
"autoload": {
"psr-4": {
"ComplexHeart\\Domain\\Model\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ComplexHeart\\Domain\\Model\\Test\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/pest --configuration=phpunit.xml --coverage-clover=coverage.xml --log-junit=test.xml",
"analyse": "vendor/bin/phpstan analyse src --no-progress --level=5"
"test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage-html=coverage",
"analyse": "vendor/bin/phpstan analyse src --no-progress --level=5",
"check": [
"@analyse",
"@test"
]
},
"config": {
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ImmutableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
class ImmutableException extends RuntimeException
{

}
}
18 changes: 18 additions & 0 deletions src/Exceptions/InstantiationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace ComplexHeart\Domain\Model\Exceptions;

use RuntimeException;

/**
* Class InstantiationException
*
* @author Unay Santisteban <usantisteban@othercode.es>
* @package ComplexHeart\Domain\Model\Exceptions
*/
class InstantiationException extends RuntimeException
{

}
6 changes: 3 additions & 3 deletions src/Traits/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final public static function attributes(): array
{
return array_filter(
array_keys(get_class_vars(static::class)),
fn(string $item): bool => strpos($item, '_') !== 0
fn(string $item): bool => !str_starts_with($item, '_')
);
}

Expand Down Expand Up @@ -63,7 +63,7 @@ final protected function hydrate(iterable $source): void
*
* @return mixed|null
*/
final protected function get(string $attribute)
final protected function get(string $attribute): mixed
{
if (in_array($attribute, static::attributes())) {
$method = $this->getStringKey($attribute, 'get', 'Value');
Expand All @@ -82,7 +82,7 @@ final protected function get(string $attribute)
* @param string $attribute
* @param mixed $value
*/
final protected function set(string $attribute, $value): void
final protected function set(string $attribute, mixed $value): void
{
if (in_array($attribute, $this->attributes())) {
$method = $this->getStringKey($attribute, 'set', 'Value');
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasEquality.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ protected function hash(): string
*
* @return string
*/
abstract function __toString();
abstract function __toString(): string;
}
6 changes: 3 additions & 3 deletions src/Traits/HasInvariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final public static function invariants(): array
{
$invariants = [];
foreach (get_class_methods(static::class) as $invariant) {
if (strpos($invariant, 'invariant') === 0 && $invariant !== 'invariants') {
if (str_starts_with($invariant, 'invariant') && $invariant !== 'invariants') {
$invariants[$invariant] = str_replace(
'invariant ',
'',
Expand Down Expand Up @@ -52,7 +52,7 @@ final public static function invariants(): array
*
* If exception is thrown the error message will be the exception message.
*
* $onFail function must have following signature:
* $onFail function must have the following signature:
* fn(array<string, string>) => void
*
* @param callable|null $onFail
Expand All @@ -74,7 +74,7 @@ private function check(callable $onFail = null): void
}
}

if (count($violations) > 0) {
if (!empty($violations)) {
if (is_null($onFail)) {
$customizedHandler = function (array $violations) use ($handler): void {
call_user_func_array([$this, $handler], [$violations]);
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/HasTypeCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait HasTypeCheck
*
* @return bool
*/
protected function isValueTypeValid($value, string $validType): bool
protected function isValueTypeValid(mixed $value, string $validType): bool
{
if ($validType === 'mixed') {
return true;
Expand All @@ -42,8 +42,8 @@ protected function isValueTypeValid($value, string $validType): bool
*
* @return bool
*/
protected function isValueTypeNotValid($value, string $validType): bool
protected function isValueTypeNotValid(mixed $value, string $validType): bool
{
return !$this->isValueTypeValid($value, $validType);
}
}
}
2 changes: 1 addition & 1 deletion src/Traits/IsAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait IsAggregate
*
* @return static
*/
protected function withOverrides(array $overrides)
protected function withOverrides(array $overrides): static
{
$new = $this->overrideEntity($overrides);

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/IsEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait IsEntity
*
* @return static
*/
protected function withOverrides(array $overrides)
protected function withOverrides(array $overrides): static
{
return $this->overrideAttributes(
filter(fn($value, string $key): bool => $key !== 'id', $overrides)
Expand Down
9 changes: 5 additions & 4 deletions src/Traits/IsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ComplexHeart\Domain\Model\Traits;

use ComplexHeart\Domain\Model\Exceptions\InstantiationException;
use RuntimeException;
use Doctrine\Instantiator\Instantiator;
use Doctrine\Instantiator\Exception\ExceptionInterface;
Expand All @@ -27,7 +28,7 @@ trait IsModel
*
* @return static
*/
protected function initialize(array $source, callable $onFail = null)
protected function initialize(array $source, callable $onFail = null): static
{
$this->hydrate($this->mapSource($source));
$this->check($onFail);
Expand All @@ -42,14 +43,14 @@ protected function initialize(array $source, callable $onFail = null)
*
* @throws RuntimeException
*/
final public static function make()
final public static function make(): static
{
try {
return (new Instantiator())
->instantiate(static::class)
->initialize(func_get_args());
} catch (ExceptionInterface $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
throw new InstantiationException($e->getMessage(), $e->getCode(), $e);
}
}

Expand All @@ -60,7 +61,7 @@ final public static function make()
*
* @return static
*/
protected function withOverrides(array $overrides)
protected function withOverrides(array $overrides): static
{
return self::make(...array_values(array_merge($this->values(), $overrides)));
}
Expand Down
14 changes: 7 additions & 7 deletions src/TypedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(array $items = [])
*
* @throws InvariantViolation
*/
protected function checkKeyType($key): void
protected function checkKeyType(mixed $key): void
{
$supported = ['string', 'integer'];
if (!in_array($this->keyType, $supported)) {
Expand All @@ -73,7 +73,7 @@ protected function checkKeyType($key): void
*
* @throws InvariantViolation
*/
protected function checkValueType($item): void
protected function checkValueType(mixed $item): void
{
if ($this->isValueTypeNotValid($item, $this->valueType)) {
throw new InvariantViolation("All items in the collection must be type of $this->valueType");
Expand Down Expand Up @@ -121,7 +121,7 @@ protected function invariantKeysAndValuesMustMatchTheRequiredType(): bool
* @return static
* @throws InvariantViolation
*/
public function push(...$values)
public function push(...$values): static
{
foreach ($values as $value) {
$this->checkValueType($value);
Expand All @@ -138,7 +138,7 @@ public function push(...$values)
*
* @throws InvariantViolation
*/
public function offsetSet($key, $value): void
public function offsetSet(mixed $key, mixed $value): void
{
if ($this->keyType !== 'mixed') {
$this->checkKeyType($key);
Expand All @@ -158,7 +158,7 @@ public function offsetSet($key, $value): void
* @return static
* @throws InvariantViolation
*/
public function prepend($value, $key = null)
public function prepend($value, $key = null): static
{
if ($this->keyType !== 'mixed') {
$this->checkKeyType($key);
Expand All @@ -177,7 +177,7 @@ public function prepend($value, $key = null)
* @return static
* @throws InvariantViolation
*/
public function add($item)
public function add(mixed $item): static
{
$this->checkValueType($item);

Expand All @@ -192,7 +192,7 @@ public function add($item)
*
* @return Collection
*/
public function pluck($value, $key = null)
public function pluck($value, $key = null): Collection
{
return $this->toBase()->pluck($value, $key);
}
Expand Down
Loading