Skip to content

Commit 1cd6612

Browse files
committed
Added laravel 10 support, strict types, GitHub actions
1 parent 1c9cdc9 commit 1cd6612

19 files changed

+193
-152
lines changed

.gitattributes

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
/phpunit.xml export-ignore
33
/phpunit.xml.old export-ignore
44
/phpcs.xml export-ignore
5-
/phpcs.xml export-ignore
65
/docker export-ignore
7-
/.travis.yml export-ignore
8-
/.styleci.yml export-ignore
9-
/.php_cs export-ignore
10-
/.editorconfig export-ignore
6+
/.php-cs-fixer.php export-ignore
7+
/.editorconfig export-ignore
118
/.gitattributes export-ignore
129
/.gitignore export-ignore
13-
/vendor export-ignore
10+
/.github export-ignore
1411
/coverage export-ignore
12+
/.phpunit.cache export-ignore
13+

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/workflows/lint.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Lint
2+
3+
on: [ push ]
4+
5+
jobs:
6+
lint_with_php_cs_fixer:
7+
name: Lint code with PHP-CS-Fixer
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Install dependencies
13+
uses: php-actions/composer@v6
14+
with:
15+
command: install
16+
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
17+
php_version: 8.1
18+
19+
- name: Run PHP-CS-Fixer
20+
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run
21+
22+
lint_with_phpcs:
23+
name: Lint code with PHP CodeSniffer
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
28+
- name: Install dependencies
29+
uses: php-actions/composer@v6
30+
with:
31+
command: install
32+
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
33+
php_version: 8.1
34+
35+
- name: Run PHP CodeSniffer
36+
run: vendor/bin/phpcs --extensions=php

.github/workflows/unittests.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Unit Test
2+
3+
on: [ push ]
4+
5+
jobs:
6+
PHPUnit:
7+
strategy:
8+
matrix:
9+
include:
10+
# Laravel 10.*
11+
- php: 8.1
12+
laravel: 10.*
13+
composer-flag: '--prefer-stable'
14+
- php: 8.2
15+
laravel: 10.*
16+
composer-flag: '--prefer-stable'
17+
- php: 8.1
18+
laravel: 10.*
19+
composer-flag: '--prefer-lowest'
20+
- php: 8.2
21+
laravel: 10.*
22+
composer-flag: '--prefer-lowest'
23+
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php }}
33+
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
34+
coverage: xdebug
35+
36+
- name: Install dependencies
37+
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
38+
39+
- name: Update dependencies
40+
run: composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction
41+
42+
- name: Run PHPUnit
43+
run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
44+
45+
- name: Upload coverage reports to Codecov
46+
uses: codecov/codecov-action@v3

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
.Trashes
1212
ehthumbs.db
1313
Thumbs.db
14-
vendor
14+
/vendor
1515
coverage
1616
composer.lock
1717
.php-cs-fixer.cache
1818
.phpunit.result.cache
19+
/coverage
20+
.phpunit.cache
21+

.php-cs-fixer.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22

33
return (new PhpCsFixer\Config())
4-
->setRiskyAllowed(false)
4+
->setRiskyAllowed(true)
55
->setRules([
6-
'@PSR2' => true,
6+
'@PSR12' => true,
7+
'declare_strict_types' => true,
8+
'modernize_types_casting' => true,
9+
'void_return' => true,
710
])
811
->setUsingCache(true)
912
->setFinder(
1013
PhpCsFixer\Finder::create()
1114
->in(__DIR__.'/src')
1215
->in(__DIR__.'/tests')
13-
)
14-
;
16+
);

.styleci.yml

-1
This file was deleted.

.travis.yml

-53
This file was deleted.

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
],
1313
"minimum-stability": "stable",
1414
"require": {
15-
"php": "^7.1|^8",
16-
"illuminate/database": "^6|^7|^8|^9"
15+
"php": ">=8.1",
16+
"illuminate/database": "^10"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^7.0|^8.0|^9.0",
20-
"friendsofphp/php-cs-fixer": "^2.16|3.*",
19+
"phpunit/phpunit": "^10",
20+
"friendsofphp/php-cs-fixer": "^3",
2121
"squizlabs/php_codesniffer": "^3.5"
2222
},
2323
"autoload": {

docker/Dockerfile

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
FROM php:7.4-cli
1+
FROM php:8.1-cli
22

3-
RUN apt-get update && apt-get install -y \
4-
zlib1g-dev \
5-
libzip-dev
3+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
64

7-
RUN docker-php-ext-install zip
8-
9-
RUN pecl install xdebug-2.8.1 \
10-
&& docker-php-ext-enable xdebug
5+
RUN chmod +x /usr/local/bin/install-php-extensions && \
6+
install-php-extensions zip xdebug
117

128
# Install composer and add its bin to the PATH.
139
RUN curl -s http://getcomposer.org/installer | php && \

phpcs.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?xml version="1.0"?>
22
<ruleset name="ASH2">
33
<description>The ASH2 coding standard.</description>
4-
<rule ref="PSR2">
4+
<rule ref="PSR12">
5+
<properties>
6+
<property name="lineLimit" value="150"/>
7+
</properties>
58
</rule>
69

710
<file>src/</file>

phpunit.xml

+25-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
bootstrap="vendor/autoload.php"
4-
backupGlobals="false"
5-
backupStaticAttributes="false"
6-
colors="true"
7-
verbose="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-
<coverage>
15-
<include>
16-
<directory suffix=".php">src/</directory>
17-
</include>
18-
</coverage>
19-
<testsuites>
20-
<testsuite name="Feature">
21-
<directory>tests</directory>
22-
</testsuite>
23-
</testsuites>
24-
<php>
25-
<env name="APP_ENV" value="testing"/>
26-
<env name="CACHE_DRIVER" value="array"/>
27-
<env name="SESSION_DRIVER" value="array"/>
28-
<env name="QUEUE_DRIVER" value="sync"/>
29-
<env name="DB_CONNECTION" value="sqlite"/>
30-
<env name="DB_DATABASE" value=":memory:"/>
31-
<server name="APP_ENV" value="testing"/>
32-
<server name="CACHE_DRIVER" value="array"/>
33-
<server name="SESSION_DRIVER" value="array"/>
34-
<server name="QUEUE_DRIVER" value="sync"/>
35-
<server name="DB_CONNECTION" value="sqlite"/>
36-
<server name="DB_DATABASE" value=":memory:"/>
37-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Feature">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
<env name="APP_ENV" value="testing"/>
15+
<env name="CACHE_DRIVER" value="array"/>
16+
<env name="SESSION_DRIVER" value="array"/>
17+
<env name="QUEUE_DRIVER" value="sync"/>
18+
<env name="DB_CONNECTION" value="sqlite"/>
19+
<env name="DB_DATABASE" value=":memory:"/>
20+
<server name="APP_ENV" value="testing"/>
21+
<server name="CACHE_DRIVER" value="array"/>
22+
<server name="SESSION_DRIVER" value="array"/>
23+
<server name="QUEUE_DRIVER" value="sync"/>
24+
<server name="DB_CONNECTION" value="sqlite"/>
25+
<server name="DB_DATABASE" value=":memory:"/>
26+
</php>
3827
</phpunit>

readme.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/korridor/laravel-has-many-merged?style=flat-square)](https://packagist.org/packages/korridor/laravel-has-many-merged)
44
[![License](https://img.shields.io/packagist/l/korridor/laravel-has-many-merged?style=flat-square)](license.md)
5+
[![GitHub Workflow Lint](https://img.shields.io/github/actions/workflow/status/korridor/laravel-has-many-merged/lint.yml?label=lint&style=flat-square)](https://github.com/korridor/laravel-has-many-merged/actions/workflows/lint.yml)
6+
[![GitHub Workflow Tests](https://img.shields.io/github/actions/workflow/status/korridor/laravel-has-many-merged/unittests.yml?label=tests&style=flat-square)](https://github.com/korridor/laravel-has-many-merged/actions/workflows/unittests.yml)
57
[![Codecov](https://img.shields.io/codecov/c/github/korridor/laravel-has-many-merged?style=flat-square)](https://codecov.io/gh/korridor/laravel-has-many-merged)
6-
[![TravisCI](https://img.shields.io/travis/korridor/laravel-has-many-merged?style=flat-square)](https://travis-ci.org/korridor/laravel-has-many-merged)
7-
[![StyleCI](https://styleci.io/repos/339041939/shield)](https://styleci.io/repos/339041939)
88

99
Custom relationship for Eloquent that merges/combines multiple one-to-may (hasMany) relationships.
1010
This relation fully supports lazy and eager loading.
@@ -17,14 +17,17 @@ You can install the package via composer with following command:
1717
composer require korridor/laravel-has-many-merged
1818
```
1919

20+
If you want to use this package with older Laravel/PHP version please install the 0.* version.
21+
22+
```bash
23+
composer require korridor/laravel-has-many-merged "^0"
24+
```
25+
2026
### Requirements
2127

2228
This package is tested for the following Laravel versions:
2329

24-
- 9.* (PHP 8.0, 8.1)
25-
- 8.* (PHP 7.3, 7.4, 8.0, 8.1)
26-
- 7.* (PHP 7.2, 7.3, 7.4)
27-
- 6.* (PHP 7.2, 7.3)
30+
- 10.* (PHP 8.1, 8.2)
2831

2932
## Usage examples
3033

@@ -47,23 +50,23 @@ class User extends Model
4750
/**
4851
* @return HasManyMerged|Message
4952
*/
50-
public function messages()
53+
public function messages(): HasManyMerged
5154
{
5255
return $this->hasManyMerged(Message::class, ['sender_user_id', 'receiver_user_id']);
5356
}
5457

5558
/**
5659
* @return HasMany|Message
5760
*/
58-
public function sentMessages()
61+
public function sentMessages(): HasMany
5962
{
6063
return $this->hasMany(Message::class, 'sender_user_id');
6164
}
6265

6366
/**
6467
* @return HasMany|Message
6568
*/
66-
public function receivedMessages()
69+
public function receivedMessages(): HasMany
6770
{
6871
return $this->hasMany(Message::class, 'receiver_user_id');
6972
}

0 commit comments

Comments
 (0)