Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Apr 28, 2020
2 parents 14690ec + 69be6ac commit e9eac84
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 93 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patreon: spatie
29 changes: 29 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check & fix styling

on: [push]

jobs:
style:
runs-on: ubuntu-latest

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

- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --allow-risky=yes

- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: Commit changes
uses: stefanzweifel/[email protected]
with:
commit_message: Fix styling
branch: ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on: [push]

jobs:
test:

runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [ 7.4 ]
dependency-version: [prefer-lowest, prefer-stable]

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

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

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
extensions: mbstring, sqlite, pdo_sqlite, iconv
coverage: none

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
40 changes: 40 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
$finder = Symfony\Component\Finder\Finder::create()
->notPath('docs/*')
->notPath('vendor')
->in([
__DIR__.'/src',
__DIR__.'/tests',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'logical_operators' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
])
->setFinder($finder);
5 changes: 0 additions & 5 deletions .styleci.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `data-transfer-object` will be documented in this file

## 2.0.0 - 2020-04-28

- Add `FlexibleDataTransferObject` which allows for unknown properties to be ignored
- Bump minimum required PHP version to 7.4
- Support for nested immutable DTOs (#86)

## 1.13.3 - 2020-01-29

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Data transfer objects with batteries included

[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/data-transfer-object.svg?style=flat-square)](https://packagist.org/packages/spatie/data-transfer-object)
[![Build Status](https://img.shields.io/travis/spatie/data-transfer-object/master.svg?style=flat-square)](https://travis-ci.org/spatie/data-transfer-object)
[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/data-transfer-object.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/data-transfer-object)
[![StyleCI](https://github.styleci.io/repos/153632216/shield?branch=master)](https://github.styleci.io/repos/153632216)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/data-transfer-object.svg?style=flat-square)](https://packagist.org/packages/spatie/data-transfer-object)

## Installation
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"larapack/dd": "^1.0",
"phpunit/phpunit": "^7.0"
},
Expand All @@ -34,8 +35,8 @@
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"config": {
"sort-packages": true
Expand Down
3 changes: 1 addition & 2 deletions src/DTOCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class DTOCache
{
/** @var array */
private static $cache = [];
private static array $cache = [];

public static function resolve(string $class, Closure $closure): array
{
Expand Down
21 changes: 9 additions & 12 deletions src/DataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@

abstract class DataTransferObject
{
/** @var bool */
protected $ignoreMissing = false;
protected bool $ignoreMissing = false;

/** @var array */
protected $exceptKeys = [];
protected array $exceptKeys = [];

/** @var array */
protected $onlyKeys = [];
protected array $onlyKeys = [];

/**
* @param array $parameters
Expand Down Expand Up @@ -111,11 +108,11 @@ public function all(): array
*/
public function only(string ...$keys): DataTransferObject
{
$valueObject = clone $this;
$dataTransferObject = clone $this;

$valueObject->onlyKeys = array_merge($this->onlyKeys, $keys);
$dataTransferObject->onlyKeys = [...$this->onlyKeys, ...$keys];

return $valueObject;
return $dataTransferObject;
}

/**
Expand All @@ -125,11 +122,11 @@ public function only(string ...$keys): DataTransferObject
*/
public function except(string ...$keys): DataTransferObject
{
$valueObject = clone $this;
$dataTransferObject = clone $this;

$valueObject->exceptKeys = array_merge($this->exceptKeys, $keys);
$dataTransferObject->exceptKeys = [...$this->exceptKeys, ...$keys];

return $valueObject;
return $dataTransferObject;
}

public function toArray(): array
Expand Down
6 changes: 2 additions & 4 deletions src/DataTransferObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ abstract class DataTransferObjectCollection implements
Iterator,
Countable
{
/** @var array */
protected $collection;
protected array $collection;

/** @var int */
protected $position = 0;
protected int $position = 0;

public function __construct(array $collection = [])
{
Expand Down
29 changes: 9 additions & 20 deletions src/FieldValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@

class FieldValidator
{
/** @var array */
private static $typeMapping = [
private static array $typeMapping = [
'int' => 'integer',
'bool' => 'boolean',
'float' => 'double',
];

/** @var bool */
private $hasTypeDeclaration = false;
private bool $hasTypeDeclaration = false;

/** @var bool */
public $isNullable = false;
public bool $isNullable = false;

/** @var bool */
public $isMixed = false;
public bool $isMixed = false;

/** @var bool */
public $isMixedArray = false;
public bool $isMixedArray = false;

/** @var bool */
public $hasDefaultValue = false;
public bool $hasDefaultValue = false;

/** @var array */
public $allowedTypes = [];

/** @var array */
public $allowedArrayTypes = [];
public array $allowedTypes = [];

public array $allowedArrayTypes = [];

public static function fromReflection(ReflectionProperty $property): FieldValidator
{
Expand Down Expand Up @@ -180,9 +171,7 @@ function (string $type) {
private function normaliseTypes(?string ...$types): array
{
return array_filter(array_map(
function (?string $type) {
return self::$typeMapping[$type] ?? $type;
},
fn (?string $type) => self::$typeMapping[$type] ?? $type,
$types
));
}
Expand Down
3 changes: 1 addition & 2 deletions src/FlexibleDataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

abstract class FlexibleDataTransferObject extends DataTransferObject
{
/** @var bool */
protected $ignoreMissing = true;
protected bool $ignoreMissing = true;
}
8 changes: 6 additions & 2 deletions src/ImmutableDataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

class ImmutableDataTransferObject
{
/** @var \Spatie\DataTransferObject\DataTransferObject */
protected $dataTransferObject;
protected DataTransferObject $dataTransferObject;

public function __construct(DataTransferObject $dataTransferObject)
{
foreach (get_object_vars($dataTransferObject) as $k => $v) {
if (is_subclass_of($v, DataTransferObject::class)) {
$dataTransferObject->{$k} = new self($v);
};
}
$this->dataTransferObject = $dataTransferObject;
}

Expand Down
Loading

0 comments on commit e9eac84

Please sign in to comment.