Skip to content

Commit 6a73373

Browse files
authored
Merge pull request #2 from tiny-blocks/release/1.0.0
Release/1.0.0
2 parents 170d189 + 1f76bcc commit 6a73373

23 files changed

+850
-2
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: gustavofreze

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
auto-review:
12+
name: Auto review
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Install dependencies
20+
run: composer update --no-progress --optimize-autoloader
21+
22+
- name: Run phpcs
23+
run: composer phpcs
24+
25+
- name: Run phpmd
26+
run: composer phpmd
27+
28+
tests:
29+
name: Tests
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
36+
- name: Install dependencies
37+
run: composer update --no-progress --optimize-autoloader
38+
39+
- name: Run unit tests
40+
env:
41+
XDEBUG_MODE: coverage
42+
run: composer test
43+
44+
- name: Run mutation tests
45+
run: composer test-mutation

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
vendor
3+
report
4+
composer.lock
5+
.phpunit.result.cache

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Tiny Blocks
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.1.7
2+
3+
.PHONY: configure test test-no-coverage review show-reports clean
4+
5+
configure:
6+
@${DOCKER_RUN} composer update --optimize-autoloader
7+
8+
test: review
9+
@${DOCKER_RUN} composer tests
10+
11+
test-no-coverage: review
12+
@${DOCKER_RUN} composer tests-no-coverage
13+
14+
review:
15+
@${DOCKER_RUN} composer review
16+
17+
show-reports:
18+
@sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html
19+
20+
clean:
21+
@sudo chown -R ${USER}:${USER} ${PWD}
22+
@rm -rf report vendor

README.md

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,82 @@
1-
# value-object
2-
Delimits default behaviors for Value Objects.
1+
# Value Object
2+
3+
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
4+
5+
* [Overview](#overview)
6+
* [Installation](#installation)
7+
* [How to use](#how-to-use)
8+
* [License](#license)
9+
* [Contributing](#contributing)
10+
11+
<div id='overview'></div>
12+
13+
## Overview
14+
15+
A **V**alue **O**bject (**VO**) is an immutable type that is only distinguishable by the state of its properties, that
16+
is, unlike an entity, which has a unique identifier and remains distinct even if its properties are identical, VOs with
17+
the same properties can be considered the same.
18+
19+
Because they are immutable, VOs cannot be changed once created. Modifying one is conceptually the same as discard the
20+
old one and create a new one.
21+
22+
More details about [VOs](https://martinfowler.com/bliki/ValueObject.html).
23+
24+
<div id='installation'></div>
25+
26+
## Installation
27+
28+
```bash
29+
composer require tiny-blocks/value-object
30+
```
31+
32+
<div id='how-to-use'></div>
33+
34+
## How to use
35+
36+
The library exposes available behaviors through the `ValueObject` interface, and the implementation of these behaviors
37+
through the `ValueObjectAdapter` trait.
38+
39+
### Concrete implementation
40+
41+
With the implementation of the `ValueObject` interface, and the `ValueObjectAdapter` trait, the use of
42+
`__get`, `__set` and `__unset` methods is suppressed, making the object immutable.
43+
44+
```php
45+
<?php
46+
47+
namespace Example;
48+
49+
use TinyBlocks\Vo\ValueObject;
50+
use TinyBlocks\Vo\ValueObjectAdapter;
51+
52+
final class TransactionId implements ValueObject
53+
{
54+
use ValueObjectAdapter;
55+
56+
public function __construct(private readonly string $value)
57+
{
58+
}
59+
}
60+
```
61+
62+
### Using the equals method
63+
64+
The `equals` method compares the value of two VOs, and checks if they are equal.
65+
66+
```php
67+
$transactionId = new TransactionId(value: 'e6e2442f-3bd8-421f-9ac2-f9e26ac4abd2');
68+
$otherTransactionId = new TransactionId(value: 'e6e2442f-3bd8-421f-9ac2-f9e26ac4abd2');
69+
70+
echo $transactionId->equals(other: $otherTransactionId); # 1 (true)
71+
```
72+
73+
## License
74+
75+
Math is licensed under [MIT](/LICENSE).
76+
77+
<div id='contributing'></div>
78+
79+
## Contributing
80+
81+
Please follow the [contributing guidelines](https://github.com/tiny-blocks/tiny-blocks/blob/main/CONTRIBUTING.md) to
82+
contribute to the project.

composer.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "tiny-blocks/value-object",
3+
"type": "library",
4+
"license": "MIT",
5+
"homepage": "https://github.com/tiny-blocks/value-object",
6+
"description": "Delimits default behaviors for Value Objects.",
7+
"prefer-stable": true,
8+
"minimum-stability": "stable",
9+
"keywords": [
10+
"vo",
11+
"psr",
12+
"psr-4",
13+
"psr-12",
14+
"tiny-blocks",
15+
"value-object"
16+
],
17+
"authors": [
18+
{
19+
"name": "Gustavo Freze de Araujo Santos",
20+
"homepage": "https://github.com/gustavofreze"
21+
}
22+
],
23+
"config": {
24+
"sort-packages": true,
25+
"allow-plugins": {
26+
"infection/extension-installer": true
27+
}
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"TinyBlocks\\Vo\\": "src/"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"TinyBlocks\\Vo\\": "tests/"
37+
}
38+
},
39+
"require": {
40+
"php": "^8.1"
41+
},
42+
"require-dev": {
43+
"infection/infection": "^0.26",
44+
"phpmd/phpmd": "^2.12",
45+
"phpunit/phpunit": "^9.5",
46+
"squizlabs/php_codesniffer": "^3.7"
47+
},
48+
"scripts": {
49+
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
50+
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit",
51+
"test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests",
52+
"test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4",
53+
"test-no-coverage": "phpunit --no-coverage",
54+
"test-mutation-no-coverage": "infection --only-covered --min-msi=100 --threads=4",
55+
"review": [
56+
"@phpcs",
57+
"@phpmd"
58+
],
59+
"tests": [
60+
"@test",
61+
"@test-mutation"
62+
],
63+
"tests-no-coverage": [
64+
"@test-no-coverage",
65+
"@test-mutation-no-coverage"
66+
]
67+
}
68+
}

infection.json.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"timeout": 10,
3+
"testFramework": "phpunit",
4+
"tmpDir": "report/",
5+
"source": {
6+
"directories": [
7+
"src"
8+
]
9+
},
10+
"logs": {
11+
"text": "report/logs/infection-text.log",
12+
"summary": "report/logs/infection-summary.log"
13+
},
14+
"mutators": {
15+
"@default": true,
16+
"PublicVisibility": false,
17+
"ProtectedVisibility": false
18+
},
19+
"phpUnit": {
20+
"configDir": "",
21+
"customPath": "./vendor/bin/phpunit"
22+
}
23+
}

phpmd.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD Custom rules"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>PHPMD Custom rules</description>
8+
9+
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
10+
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
11+
12+
<rule ref="rulesets/codesize.xml/TooManyFields"/>
13+
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
14+
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
15+
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
16+
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
17+
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
18+
<rule ref="rulesets/codesize.xml/TooManyPublicMethods"/>
19+
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
20+
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
21+
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>
22+
23+
<rule ref="rulesets/controversial.xml/Superglobals"/>
24+
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
25+
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
26+
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
27+
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
28+
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>
29+
30+
<rule ref="rulesets/design.xml/GotoStatement"/>
31+
<rule ref="rulesets/design.xml/ExitExpression"/>
32+
<rule ref="rulesets/design.xml/EvalExpression"/>
33+
<rule ref="rulesets/design.xml/NumberOfChildren"/>
34+
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
35+
<rule ref="rulesets/design.xml/CouplingBetweenObjects"/>
36+
<rule ref="rulesets/design.xml/DevelopmentCodeFragment"/>
37+
38+
<rule ref="rulesets/naming.xml/LongVariable"/>
39+
<rule ref="rulesets/naming.xml/ShortVariable">
40+
<properties>
41+
<property name="minimum" value="2"/>
42+
</properties>
43+
</rule>
44+
<rule ref="rulesets/naming.xml/ShortMethodName">
45+
<properties>
46+
<property name="minimum" value="2"/>
47+
</properties>
48+
</rule>
49+
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
50+
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
51+
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
52+
53+
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
54+
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
55+
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
56+
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
57+
</ruleset>

phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
4+
cacheResultFile="report/.phpunit.result.cache"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
colors="true"
8+
convertErrorsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
processIsolation="false"
12+
stopOnFailure="false"
13+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
14+
<testsuites>
15+
<testsuite name="default">
16+
<directory suffix="Test.php">tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<coverage>
21+
<include>
22+
<directory suffix=".php">src</directory>
23+
</include>
24+
</coverage>
25+
</phpunit>

0 commit comments

Comments
 (0)