Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed May 18, 2021
2 parents 7d31e77 + 9191c11 commit cce88f0
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 121 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Ignore all test and documentation with "export-ignore".
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
Expand Down
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: https://paypal.me/AndreaMarcoSartori
85 changes: 85 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: build

on:
push:
pull_request:

jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
php: [7.1, 7.2, 7.3, 7.4, 8.0]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest, windows-latest]
exclude:
- os: windows-latest
php: 8.0

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit --verbose

coverage:
runs-on: ubuntu-latest

name: Coverage

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: xdebug

- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

- name: Upload coverage
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
style:
runs-on: ubuntu-latest

name: Coding style

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: phpcs
coverage: none

- name: Execute check
run: phpcs --standard=psr12 src/
1 change: 0 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to `dto` will be documented in this file.
Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) principles.


## 2.2.0 - 2021-05-18

### Added
- DTO properties inheritance

### Changed
- Replaced Travis with GitHub actions

### Removed
- Exception thrown when DTOs do not provide doc-comments (removed as properties may be inherited)


## 2.1.0 - 2020-12-13

### Added
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# DTO

[![Required PHP Version][ico-php]][link-packagist]
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis]
[![Author][ico-author]][link-author]
[![PHP Version][ico-php]][link-php]
[![Build Status][ico-actions]][link-actions]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Latest Version][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![PSR-12][ico-psr12]][link-psr12]
[![Total Downloads][ico-downloads]][link-downloads]

This package was inspired by [Lachlan Krautz][link-lachlan]' excellent [data-transfer-object][link-repo].
Expand Down Expand Up @@ -526,20 +528,24 @@ If you discover any security related issues, please email andrea.marco.sartori@g

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-php]: https://img.shields.io/packagist/php-v/cerbero/dto?color=%238892BF&style=flat-square&logo=php
[ico-version]: https://img.shields.io/packagist/v/cerbero/dto.svg?style=flat-square
[ico-author]: https://img.shields.io/static/v1?label=author&message=cerbero90&color=50ABF1&logo=twitter&style=flat-square
[ico-php]: https://img.shields.io/packagist/php-v/cerbero/dto?color=%234F5B93&logo=php&style=flat-square
[ico-version]: https://img.shields.io/packagist/v/cerbero/dto.svg?label=version&style=flat-square
[ico-actions]: https://img.shields.io/github/workflow/status/cerbero90/dto/build?style=flat-square&logo=github
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/cerbero90/dto/master.svg?style=flat-square&logo=travis
[ico-psr12]: https://img.shields.io/static/v1?label=compliance&message=PSR-12&color=blue&style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/cerbero90/dto.svg?style=flat-square&logo=scrutinizer
[ico-code-quality]: https://img.shields.io/scrutinizer/g/cerbero90/dto.svg?style=flat-square&logo=scrutinizer
[ico-downloads]: https://img.shields.io/packagist/dt/cerbero/dto.svg?style=flat-square

[link-author]: https://twitter.com/cerbero90
[link-php]: https://www.php.net
[link-packagist]: https://packagist.org/packages/cerbero/dto
[link-travis]: https://travis-ci.org/cerbero90/dto
[link-actions]: https://github.com/cerbero90/dto/actions?query=workflow%3Abuild
[link-psr12]: https://www.php-fig.org/psr/psr-12/
[link-scrutinizer]: https://scrutinizer-ci.com/g/cerbero90/dto/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/cerbero90/dto
[link-downloads]: https://packagist.org/packages/cerbero/dto
[link-author]: https://github.com/cerbero90
[link-lachlan]: https://github.com/lachlankrautz
[link-repo]: https://github.com/rexlabsio/data-transfer-object
[link-contributors]: ../../contributors
59 changes: 33 additions & 26 deletions src/DtoPropertiesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Cerbero\Dto;

use Cerbero\Dto\Exceptions\DtoNotFoundException;
use Cerbero\Dto\Exceptions\InvalidDocCommentException;
use Cerbero\Dto\Exceptions\MissingValueException;
use Cerbero\Dto\Exceptions\UnknownDtoPropertyException;
use Cerbero\Dto\Manipulators\ArrayConverter;
Expand Down Expand Up @@ -78,7 +77,7 @@ class DtoPropertiesMapper
/**
* Instantiate the class.
*
* @param string $dtoClass
* @param string $dtoClass
* @throws DtoNotFoundException
*/
protected function __construct(string $dtoClass)
Expand All @@ -105,7 +104,7 @@ protected function reflectDto(): ReflectionClass
/**
* Retrieve the mapper instance for the given DTO class
*
* @param string $dtoClass
* @param string $dtoClass
* @return DtoPropertiesMapper
* @throws DtoNotFoundException
*/
Expand All @@ -118,7 +117,6 @@ public static function for(string $dtoClass): DtoPropertiesMapper
* Retrieve the mapped property names
*
* @return array
* @throws InvalidDocCommentException
*/
public function getNames(): array
{
Expand All @@ -131,37 +129,46 @@ public function getNames(): array
* Retrieve and cache the raw properties to map
*
* @return array
* @throws InvalidDocCommentException
*/
protected function cacheRawProperties(): array
{
if (isset($this->rawProperties)) {
return $this->rawProperties;
if (!isset($this->rawProperties)) {
$this->cacheRawPropertiesOfReflection($this->reflection);
}

if (false === $docComment = $this->reflection->getDocComment()) {
throw new InvalidDocCommentException($this->dtoClass);
}
return $this->rawProperties;
}

if (preg_match_all(static::RE_PROPERTY, $docComment, $matches, PREG_SET_ORDER) === 0) {
return $this->rawProperties = [];
}
/**
* Cache the raw properties of the given reflection
*
* @param ReflectionClass $reflection
* @return void
*/
protected function cacheRawPropertiesOfReflection(ReflectionClass $reflection): void
{
$this->rawProperties = $this->rawProperties ?? [];

foreach ($matches as $match) {
[, $rawTypes, $name] = $match;
$this->rawProperties[$name] = $rawTypes;
if (preg_match_all(static::RE_PROPERTY, $reflection->getDocComment(), $matches, PREG_SET_ORDER) !== 0) {
foreach ($matches as $match) {
[, $rawTypes, $name] = $match;
$this->rawProperties[$name] = $rawTypes;
}
}

return $this->rawProperties;
$parentDto = $reflection->getParentClass();

if ($parentDto !== false && $parentDto != Dto::class) {
$this->cacheRawPropertiesOfReflection($parentDto);
}
}

/**
* Retrieve the mapped DTO properties
*
* @param array $data
* @param int $flags
* @param array $data
* @param int $flags
* @return array
* @throws InvalidDocCommentException
* @throws MissingValueException
* @throws UnexpectedValueException
* @throws UnknownDtoPropertyException
Expand Down Expand Up @@ -231,8 +238,8 @@ protected function cacheUseStatements(): array
/**
* Parse the given raw property types
*
* @param string $rawTypes
* @param array $useStatements
* @param string $rawTypes
* @param array $useStatements
* @return DtoPropertyTypes
*/
protected function parseTypes(string $rawTypes, array $useStatements): DtoPropertyTypes
Expand Down Expand Up @@ -262,8 +269,8 @@ protected function parseTypes(string $rawTypes, array $useStatements): DtoProper
/**
* Retrieve the key for the given property in the provided data
*
* @param string $property
* @param array $data
* @param string $property
* @param array $data
* @return string
*/
protected function getPropertyKeyFromData(string $property, array $data): string
Expand All @@ -278,8 +285,8 @@ protected function getPropertyKeyFromData(string $property, array $data): string
/**
* Check whether the given data contains unknown properties
*
* @param array $data
* @param int $flags
* @param array $data
* @param int $flags
* @return void
* @throws UnknownDtoPropertyException
*/
Expand Down
22 changes: 0 additions & 22 deletions src/Exceptions/InvalidDocCommentException.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Traits/HasProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ protected function setPropertyValueOrMap(string $property, $value): void
* @param array $data
* @return array
* @throws \Cerbero\Dto\Exceptions\DtoNotFoundException
* @throws \Cerbero\Dto\Exceptions\InvalidDocCommentException
* @throws \Cerbero\Dto\Exceptions\MissingValueException
* @throws \Cerbero\Dto\Exceptions\UnexpectedValueException
* @throws UnknownDtoPropertyException
Expand Down
Loading

0 comments on commit cce88f0

Please sign in to comment.