Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eisfeuer committed Mar 4, 2020
0 parents commit 1643b82
Show file tree
Hide file tree
Showing 27 changed files with 1,174 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
59 changes: 59 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: run-tests

on: push

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4]
laravel: [6.*]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

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

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: |
composer-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-
composer-laravel-${{ matrix.laravel }}-php-
composer-laravel-
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: phpunit
run: vendor/bin/phpunit

- name: php-cs-test
run: vendor/bin/php-cs-test

- name: php-md-test
run: vendor/bin/php-md-test ./src

- name: php-tlint-test
run: vendor/bin/php-tlint-test ./src

- name: php-insights-test
run: vendor/bin/php-insights-test

- name: php-stan-test
run: vendor/bin/php-stan-test

- name: php-mn-test
run: vendor/bin/php-mn-test ./src
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
composer.lock
docs
vendor
coverage
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":9466:{a:2:{s:7:"defects";a:42:{s:74:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model";i:4;s:102:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_with_a_changes_given_fields";i:4;s:77:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_two_models";i:4;s:76:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_changes_model_data";i:3;s:76:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_changes_two_models";i:3;s:74:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_detaches_a_model";i:3;s:84:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_detaches_one_of_two_models";i:3;s:87:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_set_default_data_after_detach";i:3;s:77:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_detaches_two_models";i:3;s:99:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_detaches_another_one";i:4;s:118:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_detaching_is_false";i:4;s:126:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_using_syncWithoutDetaching";i:4;s:92:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_changes_and_detach_models";i:3;s:89:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_id_from_array_input";i:4;s:122:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_empty_additional_attributes_when_input_is_from_array";i:4;s:96:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_key_from_assoc_array_as_id";i:4;s:117:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_value_from_assoc_array_as_additional_attributes";i:4;s:102:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_inherits_from_laravel_collection";i:4;s:81:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_ids";i:4;s:103:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_keys_of_assoc_array_as_id";i:4;s:119:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_converts_items_to_IdAndAttributeContainer_objects";i:4;s:95:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_inherits_from_laravel_collection";i:4;s:74:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_ids";i:4;s:96:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_keys_of_assoc_array_as_id";i:4;s:112:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_converts_items_to_IdAndAttributeContainer_objects";i:4;s:87:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_id_from_array_input";i:4;s:120:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_empty_additional_attributes_when_input_is_from_array";i:4;s:94:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_key_from_assoc_array_as_id";i:4;s:115:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_value_from_assoc_array_as_additional_attributes";i:4;s:67:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model";i:4;s:95:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_with_a_changes_given_fields";i:4;s:70:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_two_models";i:4;s:69:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_changes_model_data";i:4;s:69:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_changes_two_models";i:4;s:67:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_detaches_a_model";i:4;s:77:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_detaches_one_of_two_models";i:4;s:80:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_set_default_data_after_detach";i:4;s:70:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_detaches_two_models";i:4;s:92:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_detaches_another_one";i:4;s:111:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_detaching_is_false";i:4;s:119:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_using_syncWithoutDetaching";i:4;s:85:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_changes_and_detach_models";i:4;}s:5:"times";a:46:{s:74:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model";d:0.016;s:102:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_with_a_changes_given_fields";d:0.009;s:77:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_two_models";d:0.009;s:76:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_changes_model_data";d:0.009;s:76:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_changes_two_models";d:0.01;s:74:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_detaches_a_model";d:0.008;s:84:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_detaches_one_of_two_models";d:0.009;s:87:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_set_default_data_after_detach";d:0.009;s:77:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_detaches_two_models";d:0.012;s:99:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_detaches_another_one";d:0.009;s:118:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_detaching_is_false";d:0.01;s:126:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_using_syncWithoutDetaching";d:0.009;s:92:"Elbgoods\LaravelSyncOneToMany\Tests\OneToManySyncTest::it_attaches_changes_and_detach_models";d:0.011;s:89:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_id_from_array_input";d:0.007;s:122:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_empty_additional_attributes_when_input_is_from_array";d:0.006;s:96:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_key_from_assoc_array_as_id";d:0.006;s:117:"Elbgoods\LaravelSyncOneToMany\Tests\RelatedRowInputDataTest::it_shows_value_from_assoc_array_as_additional_attributes";d:0.006;s:94:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_id_from_array_input";d:0.006;s:127:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_empty_additional_attributes_when_input_is_from_array";d:0.006;s:101:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_key_from_assoc_array_as_id";d:0.006;s:122:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_value_from_assoc_array_as_additional_attributes";d:0.007;s:102:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_inherits_from_laravel_collection";d:0.084;s:81:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_ids";d:0.007;s:103:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_keys_of_assoc_array_as_id";d:0.007;s:119:"Elbgoods\LaravelSyncOneToMany\Tests\IdAndAttributesCollectionTest::it_converts_items_to_IdAndAttributeContainer_objects";d:0.007;s:95:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_inherits_from_laravel_collection";d:0.086;s:74:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_ids";d:0.006;s:96:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_returns_keys_of_assoc_array_as_id";d:0.006;s:112:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesCollectionTest::it_converts_items_to_IdAndAttributeContainer_objects";d:0.008;s:87:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_id_from_array_input";d:0.006;s:120:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_empty_additional_attributes_when_input_is_from_array";d:0.006;s:94:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_key_from_assoc_array_as_id";d:0.006;s:115:"Elbgoods\SyncOneToMany\Tests\IdAndAttributesContainerTest::it_shows_value_from_assoc_array_as_additional_attributes";d:0.007;s:67:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model";d:0.015;s:95:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_with_a_changes_given_fields";d:0.008;s:70:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_two_models";d:0.011;s:69:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_changes_model_data";d:0.009;s:69:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_changes_two_models";d:0.009;s:67:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_detaches_a_model";d:0.008;s:77:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_detaches_one_of_two_models";d:0.01;s:80:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_set_default_data_after_detach";d:0.009;s:70:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_detaches_two_models";d:0.012;s:92:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_detaches_another_one";d:0.011;s:111:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_detaching_is_false";d:0.009;s:119:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_a_model_and_does_not_detach_when_using_syncWithoutDetaching";d:0.009;s:85:"Elbgoods\SyncOneToMany\Tests\OneToManySyncTest::it_attaches_changes_and_detach_models";d:0.012;}}}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to `laravel-sync-one-to-many` will be documented in this file

## 0.1.0 - 2013-03-04

- initial release
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Coding Guidelines

* This package follows the [coding guidelines](https://github.com/laravel/framework/blob/master/CONTRIBUTING.md#coding-guidelines) used by Laravel.
* Pull requests for the latest major release MUST be sent to the master branch.
* To preserve the quality of the package, only **tested** code changes will by reviewed.

### Testing

Execute tests and code quality tool with following command.
``` bash
composer test
```
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) John Doe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Laravel Sync OneToMany

This package provides the sync function for one to many relations similar to the sync method from BelongsToMany.

## Installation

You can install the package via composer:

```bash
composer require elbgoods/laravel-sync-one-to-many
```

## Usage

Sync using ids
``` php
$user->tasks()->sync([1, 2, 4]);
```

Sync using ids and additional attributes
``` php
$user->tasks()->sync([
1 => ['status' => 'wip', 'priority' => 1],
4 => ['status' => 'finished', 'priority' => 3],
]);
```

Sync without detaching
``` php
$user->tasks()->syncWithoutDetaching([1, 2, 4]);

// or

$user->tasks()->sync([1, 2, 4], ['detaching' => false]);
```
Sync and set additional attributes to detached
``` php
$user->tasks()->sync(
[1, 2, 4],
'set_after_detach' => [
'status' => 'open',
'priority' => 0,
],
);
```

Result is the same as the result of the sync method of `BelongsToMany`, an array with attach, detached and updated rows.

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security

Please see [SECURITY](SECURITY.md) for details.

## Credits

- [Niclas Schirrmeister](https://github.com/eisfeuer)
- [Tom Witkowski](https://github.com/gummibeer)
- [All Contributors](../../contributors)

## License

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

## Treeware

You're free to use this package, but if it makes it to your production environment we would highly appreciate you buying or planting the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees at https://offset.earth/treeware

Read more about Treeware at https://treeware.earth

[![We offset our carbon footprint via Offset Earth](https://toolkit.offset.earth/carbonpositiveworkforce/badge/5e186e68516eb60018c5172b?black=true&landscape=true)](https://offset.earth/treeware)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).
19 changes: 19 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Security Policy

## Supported Versions

This package has no LTS releases - this means that we will only support the latest minor release with feature updates.
We have never had any security vulnerabilities and therefore we don't promise any list of versions.
Instead we will determine this on a case by case basis - depending on factors like:
* vulnerable versions
* age of the versions
* usage of the versions (packagist downloads)
* effort needed to fix it in the versions

We will do our best to fix security issues as and when they become apparent. We will attempt inform all users about possible issues.

## Reporting a Vulnerability

Due to the fact that security vulnerabilities could harm users, we ask that you don't use the public issue tracker to report them.
Please write a mail to [[email protected]](mailto:[email protected]).
We will either create a public issue/security alert, or we will fix the vulnerability and inform users afterwards.
65 changes: 65 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "elbgoods/laravel-sync-one-to-many",
"description": "",
"keywords": [
"elbgoods",
"laravel-sync-one-to-many"
],
"homepage": "https://github.com/elbgoods/laravel-sync-one-to-many",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Niclas Schirrmeister",
"email": "[email protected]",
"role": "Developer"
}, {
"name": "Tom Witkowski",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^7.4",
"illuminate/support": "^6.0"
},
"require-dev": {
"elbgoods/ci-test-tools": "^1.6",
"orchestra/database": "^4.3",
"orchestra/testbench": "^4.0",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"Elbgoods\\SyncOneToMany\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Elbgoods\\SyncOneToMany\\Tests\\": "tests"
}
},
"scripts": {
"test": [
"vendor/bin/phpunit",
"vendor/bin/php-cs-test",
"vendor/bin/php-tlint-test .",
"vendor/bin/php-md-test ./src",
"vendor/bin/php-insights-test",
"vendor/bin/php-mn-test",
"vendor/bin/php-stan-test"
],
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Elbgoods\\SyncOneToMany\\SyncOneToManyServiceProvider"
]
}
}
}
8 changes: 8 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/*
* You can place your custom package configuration in here.
*/
return [

];
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/elbgoods/ci-test-tools/configs/phpstan.neon.dist

parameters:
paths:
- ./src
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit 1643b82

Please sign in to comment.