Skip to content

Commit

Permalink
Merge pull request #2 from HRADigital/feature/v2
Browse files Browse the repository at this point in the history
Version 2.0
  • Loading branch information
HRADigital authored Mar 22, 2022
2 parents 2943cc6 + 2c362b6 commit 32fc264
Show file tree
Hide file tree
Showing 183 changed files with 10,903 additions and 7,139 deletions.
66 changes: 66 additions & 0 deletions .circleci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# CircleCI Continuous Integration

PHP-Datatypes uses CircleCI for code testing and coverage.

The project currently supports version `7.4`, `8.0` & `8.1` of PHP.

## Installation

In order to validate CircleCI configuration, you'll need to install locally `circleci` cli utility:

```bash
sudo snap install circleci
```

After installation of `circleci` utility, you can assess Coding Standards and Testing in multiple supported PHP versions.

In order to test CircleCI configiuration file, you can run `circleci config validate`.

## Quick links

- [CodeDov](https://app.codecov.io/gh/HRADigital/php-datatypes)
- [Codacy](https://app.codacy.com/gh/HRADigital/php-datatypes/dashboard)
- [CircleCI](https://app.circleci.com/pipelines/github/HRADigital/php-datatypes?filter=all)

## Coding Standards

Run `circleci local execute --job php-cs` from the root of the project in order to test Coding Standards.

Coding standards' job will also give you information about the environment and project it's running on:

### PHP Version

```bash
PHP 7.4.26 (cli) (built: Nov 23 2021 21:06:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
```

### Project's Statistics

```bash
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
PHP 108 1129 4016 4139
Markdown 27 171 0 431
YAML 1 6 0 83
JSON 1 0 0 47
-------------------------------------------------------------------------------
SUM: 137 1306 4016 4700
-------------------------------------------------------------------------------
```

In order to access Code Coverage reports, please go to [CodeDov](https://app.codecov.io/gh/HRADigital/php-datatypes).

In order to access Code Quality reports, please go to [Codacy](https://app.codacy.com/gh/HRADigital/php-datatypes/dashboard).

## Testing

Run `circleci local execute --job php-74` to test `v7.4`, or replace `74` with `80` or `81`, for versions `v8.0` & `v8.1`:

- `circleci local execute --job php-74`
- `circleci local execute --job php-80`
- `circleci local execute --job php-81`

In order to access CI reports, please got to [CircleCI](https://app.circleci.com/pipelines/github/HRADigital/php-datatypes?filter=all).
102 changes: 84 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,107 @@
version: 2.1

orbs:
codecov: codecov/[email protected]

jobs:
build:
php-cs:
docker:
- image: circleci/php:7.2
- image: cimg/php:7.4
working_directory: ~/php-datatypes
steps:
# GIT
- checkout
# SYSTEM
- run:
name: Install System Packages
name: Update System
command: sudo apt-get update
- run:
name: Install CLOC
command: sudo apt-get -y install cloc
# COMPOSER
- run:
name: Install Composer Dependencies
command: composer install
# STATISTICS
name: PHP Version
command: php -v
- run:
name: Project's Statistics
command: git ls-files | xargs cloc
# TESTS
- run:
name: Run Tests
command: phpdbg -qrr vendor/bin/phpunit --coverage-clover ~/build/coverage-report
name: Composer Install
command: composer install
- run:
name: Check Coding Standards for PHPv7.4
command: |
vendor/bin/phpcs --standard=PSR2 --exclude=Squiz.WhiteSpace.ControlStructureSpacing src
vendor/bin/phpcs --standard=PSR2 --exclude=Squiz.WhiteSpace.ControlStructureSpacing tests
php-74:
docker:
- image: cimg/php:7.4
working_directory: ~/php-datatypes
steps:
- checkout
- run:
name: Composer Update
command: composer update
- run:
name: Run Tests for PHPv7.4
command: phpdbg -qrr vendor/bin/phpunit

php-80:
docker:
- image: cimg/php:8.0
working_directory: ~/php-datatypes
steps:
- checkout
- run:
name: Check coding standards in /src
command: vendor/bin/phpcs --standard=PSR2 --exclude=Squiz.WhiteSpace.ControlStructureSpacing src
name: Composer Update
command: composer update
- run:
name: Check coding standards in /tests
command: vendor/bin/phpcs --standard=PSR2 --exclude=Squiz.WhiteSpace.ControlStructureSpacing tests
name: Run Tests for PHPv8.0
command: phpdbg -qrr vendor/bin/phpunit

php-81:
docker:
- image: cimg/php:8.1
working_directory: ~/php-datatypes
steps:
- checkout
- run:
name: Composer Update
command: composer update
- run:
name: Run Tests for PHPv8.1
command: phpdbg -qrr vendor/bin/phpunit

php-coverage:
docker:
- image: cimg/php:7.4
working_directory: ~/php-datatypes
steps:
- checkout
- run:
name: Composer Install
command: composer install
- run:
name: Run Tests for PHPv7.4
command: phpdbg -qrr vendor/bin/phpunit --coverage-clover ~/build/coverage-report
- store_artifacts:
path: ~/build/coverage-report
path: ~/build/coverage-report
- codecov/upload:
file: ~/build/coverage-report


workflows:
ci-flow:
jobs:
- php-cs
- php-74:
requires:
- php-cs
- php-80:
requires:
- php-cs
- php-81:
requires:
- php-cs
- php-coverage:
requires:
- php-74
- php-80
- php-81
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ci/
vendor/
notyetdeveloped/
.buildpath
.project
composer.lock
phpunit.xml
.phpunit.result.cache
50 changes: 35 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
# PHP Datatypes

## Master branch build status

[![Build](https://img.shields.io/circleci/build/github/HRADigital/php-datatypes.svg)](https://github.com/HRADigital/php-datatypes)
[![Coverage](https://img.shields.io/codecov/c/github/HRADigital/php-datatypes.svg)](https://github.com/HRADigital/php-datatypes)
[![Quality](https://api.codacy.com/project/badge/Grade/3be6c231eea84329878a59a66af49e2f)](https://github.com/HRADigital/php-datatypes)
[![Quality](https://app.codacy.com/project/badge/Grade/de03155208c64196899848458c2ced8a)](https://www.codacy.com/gh/HRADigital/php-datatypes/dashboard?utm_source=github.com&utm_medium=referral&utm_content=HRADigital/php-datatypes&utm_campaign=Badge_Grade)
[![Downloads](https://img.shields.io/github/downloads/HRADigital/php-datatypes/total.svg)](https://github.com/HRADigital/php-datatypes)
[![Licence](https://img.shields.io/github/license/HRADigital/php-datatypes.svg)](https://github.com/HRADigital/php-datatypes)
[![Version](https://img.shields.io/github/release/HRADigital/php-datatypes.svg)](https://github.com/HRADigital/php-datatypes)
[![PHP](https://img.shields.io/packagist/php-v/hradigital/php-datatypes.svg)](https://github.com/HRADigital/php-datatypes)

## About

**PHP Datatypes** is a project is based and inspired on many other projects around, and is mainly meant to bring support
for **Scalar objects** and other common **Complex datatypes** into PHP, while native support isn't around.
**PHP Datatypes** is meant to provide an easy way to create your Value Objects/Entities/Aggregates, in a fast and platform agnostic way,
that promotes:

- Code reusability
- Data normalization
- Type hint enforcement
- Full data serializing
- No 3rd party dependency apart from PHP. Clean/Self reliant project.

An Aggregate/Entity/ValueObject that extends [AbstractValueObject](/HRADigital/php-datatypes/blob/master/src/ValueObjects/AbstractValueObject.php)
will be built using predefined/tested [Traits](/HRADigital/php-datatypes/tree/master/src/Traits/Entities) for each of the class attributes,
leaving your class definition cleaned/free for your business logic implementation.

This will also allow you to reuse/load your objects with data that can come from a Database, Webservice, Event payload, etc...

Getters/Accessors for class attributes will return ValueObjects instead of primitive types, as much as possible. All these datatypes will
also be included in the package, as it doesn't have any dependencies apart from, PHP itself.

To learn how to use this package, please go to [AbstractValueObject](/HRADigital/php-datatypes/blob/master/src/ValueObjects/) documentation.

Some of the projects that inspired this one, are mainly [Nikita Popov's Scalar Objects](https://github.com/nikic/scalar_objects),
but also [Martin Helmich's Scalar Classes](https://github.com/martin-helmich/php-scalarclasses/) and
[Michael Hall's Datatypes](https://github.com/themichaelhall/datatypes/).
### Inspiration

### Scalar objects
Some of the projects that inspired this one, are mainly [Nikita Popov's Scalar Objects](/nikic/scalar_objects),
but also [Martin Helmich's Scalar Classes](/martin-helmich/php-scalarclasses/) and
[Michael Hall's Datatypes](/themichaelhall/datatypes/).

**PHP Datatypes** will initially wrap common functionality to PHP's native datatypes, such as `string`, `integer`, `float`
and `boolean`.
Due to the "_No 3rd party dependency_" rule, this package will use some simplified versions of more popular datatypes. Some examples are:

### Complex datatypes
- [synfony/string](/symfony/string), for String related manipulations.
- [nesbot/carbon](/briannesbitt/Carbon), for DateTime manipulations.
- ...

There will also be wrapping classes around **Complex Datatypes** such as `Datetime`, `Email`, `Color`, `UrlAddress`, ...,
and both _Linear_ and _Associative_ **Collections** such as `Queues`, `Stacks` and `Sets`/`Stores`.
## Requirements & Installation

## Installation
- PHP >= 7.4||8.*

In order to install this package, just add it to your **composer**, by executing `composer require hradigital/php-datatypes`.
```bash
composer require hradigital/php-datatypes
```

## Usage

For more information about how to to use these Datatypes, please see the project's **usage notes** and some implementation examples
in [here](https://github.com/HRADigital/php-datatypes/tree/master/src/).
in [here](src/).

## Contributing

Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@
"mutable objects"
],
"require": {
"php": "^7.2"
"php": "^7.4||^8.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.0@dev"
},
"autoload": {
"psr-4": {
"Hradigital\\Datatypes\\": "src/"
"HraDigital\\Datatypes\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Hradigital\\Tests\\Datatypes\\": "tests/"
"HraDigital\\Tests\\Datatypes\\": "tests/"
}
},
"scripts": {
"test-code" : "./vendor/bin/phpunit --coverage-clover ci/coverage-report.xml --coverage-html ci/coverage-report --log-junit ci/tests-results.xml",
"test-cs" : "./vendor/bin/phpcs -p --colors --no-cache --report=full --standard=PSR2 --exclude=Squiz.WhiteSpace.ControlStructureSpacing src/",
"test-all" : "composer run test-code && composer run test-cs"
}
}
43 changes: 23 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<phpunit bootstrap="tests/bootstrap.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
</testsuites>

</phpunit>
39 changes: 39 additions & 0 deletions src/Attributes/General/HasActiveTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace HraDigital\Datatypes\Attributes\General;

/**
* Gives Activation information capabilities to an Entity/Value Object.
*
* @package HraDigital\Datatypes
* @copyright HraDigital\Datatypes
* @license MIT
*/
trait HasActiveTrait
{
/** @var bool $active - If the record is marked as ACTIVE in the system. */
protected bool $active = false;

/**
* Sets the active value of an Entity.
*
* @param bool $active - New active value.
* @return void
*/
protected function castActive(bool $active): void
{
$this->active = $active;
}

/**
* Returns TRUE if the record is marked as ACTIVE in the system.
*
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
}
Loading

0 comments on commit 32fc264

Please sign in to comment.