Skip to content
This repository was archived by the owner on Mar 7, 2022. It is now read-only.

Commit 0a6d2e2

Browse files
Merge branch 'release/4.0.0'
2 parents d456f6f + b6304a0 commit 0a6d2e2

File tree

13 files changed

+62
-31
lines changed

13 files changed

+62
-31
lines changed

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ env:
1313
matrix:
1414
- LARAVEL_VERSION="5.8.*" COMPOSER_FLAGS="--prefer-lowest"
1515
- LARAVEL_VERSION="5.8.*" COMPOSER_FLAGS="--prefer-stable"
16+
- LARAVEL_VERSION="^6.0" COMPOSER_FLAGS="--prefer-lowest"
17+
- LARAVEL_VERSION="^6.0" COMPOSER_FLAGS="--prefer-stable"
1618
- LARAVEL_VERSION="dev-master" ORCHESTRA_VERSION="dev-master" COMPOSER_FLAGS="--prefer-lowest" MINIMUM_STABILITY="dev"
1719
- LARAVEL_VERSION="dev-master" ORCHESTRA_VERSION="dev-master" COMPOSER_FLAGS="--prefer-stable" MINIMUM_STABILITY="dev"
1820

@@ -34,13 +36,9 @@ install:
3436
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
3537

3638
script:
39+
- vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1
3740
- vendor/bin/phpunit
3841

39-
branches:
40-
only:
41-
- master
42-
- develop
43-
4442
notifications:
4543
email:
4644
on_failure: change

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All Notable changes to `sebastiaanluca/laravel-auto-morph-map` will be documente
44

55
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
66

7-
## Unreleased
7+
## 4.0.0 (2019-09-06)
8+
9+
### Added
10+
11+
- Added support for Laravel 6.0
812

913
## 3.0.0 (2019-03-01)
1014

composer.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
],
2424
"require": {
2525
"php": "^7.2",
26-
"laravel/framework": "5.8.*"
26+
"laravel/framework": "5.8.*|^6.0"
2727
},
2828
"require-dev": {
2929
"kint-php/kint": "^3.0",
30-
"mockery/mockery": "^1.2.2",
31-
"orchestra/testbench": "3.8.*",
32-
"phpunit/phpunit": "^8.2"
30+
"mockery/mockery": "^1.2",
31+
"orchestra/testbench": "3.8.*|^4.0",
32+
"phpunit/phpunit": "^8.3",
33+
"sebastiaanluca/php-codesniffer-ruleset": "^0.4.2"
3334
},
3435
"autoload": {
3536
"psr-4": {
@@ -55,6 +56,9 @@
5556
}
5657
},
5758
"scripts": {
59+
"composer-validate": "@composer validate --no-check-all --strict --ansi",
60+
"codesniffer-check": "vendor/bin/phpcs --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1",
61+
"codesniffer-fix": "vendor/bin/phpcbf --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 || exit 0",
5862
"test": "vendor/bin/phpunit",
5963
"test-lowest": [
6064
"composer update --prefer-lowest --prefer-dist --no-interaction --ansi",
@@ -63,6 +67,13 @@
6367
"test-stable": [
6468
"composer update --prefer-stable --prefer-dist --no-interaction --ansi",
6569
"@test"
70+
],
71+
"check": [
72+
"@composer-validate",
73+
"@codesniffer-check",
74+
"@test"
6675
]
67-
}
76+
},
77+
"minimum-stability": "dev",
78+
"prefer-stable": true
6879
}

config/auto-morph-map.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
* The naming scheme to use when determining the model's morph type
1010
* base value. Defaults to singular table name.
1111
*/
12+
1213
'naming' => NamingSchemes::SINGULAR_TABLE_NAME,
1314

1415
/**
1516
* The case type to use when aliasing a model. Defaults to use snake case.
1617
*/
18+
1719
'case' => CaseTypes::SNAKE_CASE,
1820

1921
/**
2022
* If you wish, you can override the naming and conversion altogether
2123
* using a closure.
2224
*/
23-
// 'conversion' => function (string $model) {
24-
// return snake_case(basename($model));
25-
// },
25+
26+
// 'conversion' => function (string $model) {
27+
// return snake_case(basename($model));
28+
// },
2629

2730
];

phpcs.xml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="."/>
4+
5+
<file>./src</file>
6+
<file>./tests</file>
7+
8+
<rule ref="./vendor/sebastiaanluca/php-codesniffer-ruleset/ruleset.xml"/>
9+
</ruleset>

src/Commands/CacheMorphMap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SebastiaanLuca\AutoMorphMap\Commands;
46

57
use Illuminate\Console\Command;

src/Commands/ClearCachedMorphMap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SebastiaanLuca\AutoMorphMap\Commands;
46

57
use Illuminate\Console\Command;

src/Mapper.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public function getCachePath() : string
4747
public function getModels() : array
4848
{
4949
$config = $this->getComposerConfig();
50-
5150
$paths = $this->getModelPaths($config);
5251

53-
if (empty($paths)) {
52+
if (count($paths) === 0) {
5453
return [];
5554
}
5655

@@ -82,7 +81,7 @@ protected function useCache() : bool
8281
return false;
8382
}
8483

85-
$this->mapModels(require $cache);
84+
$this->mapModels(include $cache);
8685

8786
return true;
8887
}
@@ -129,11 +128,13 @@ protected function scan(array $paths) : array
129128

130129
foreach ($paths as $namespace => $path) {
131130
foreach ((new Finder)->in($path)->files() as $file) {
132-
$model = $namespace . str_replace(
133-
['/', '.php'],
134-
['\\', ''],
135-
Str::after($file->getPathname(), $path . DIRECTORY_SEPARATOR)
136-
);
131+
$name = str_replace(
132+
['/', '.php'],
133+
['\\', ''],
134+
Str::after($file->getPathname(), $path . DIRECTORY_SEPARATOR)
135+
);
136+
137+
$model = $namespace . $name;
137138

138139
if (! class_exists($model)) {
139140
continue;
@@ -154,14 +155,16 @@ protected function scan(array $paths) : array
154155

155156
/**
156157
* @param array $map
158+
*
159+
* @return void
157160
*/
158161
protected function mapModels(array $map) : void
159162
{
160163
$existing = Relation::morphMap() ?: [];
161164

162-
if (! empty($existing)) {
165+
if (count($existing) > 0) {
163166
$map = collect($map)
164-
->reject(function (string $class, string $alias) use ($existing) {
167+
->reject(function (string $class, string $alias) use ($existing) : bool {
165168
return array_key_exists($alias, $existing) || in_array($class, $existing, true);
166169
})
167170
->toArray();

tests/TestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SebastiaanLuca\AutoMorphMap\Tests;
46

57
use Illuminate\Filesystem\Filesystem;

tests/resources/cache.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php return array (
2-
"something_inherited" => 'App\\Models\\SomethingInherited',
3-
"different_package" => 'MyPackage\\Models\\Sub\\Package',
4-
);
1+
<?php return [
2+
'something_inherited' => 'App\\Models\\SomethingInherited',
3+
'different_package' => 'MyPackage\\Models\\Sub\\Package',
4+
];

0 commit comments

Comments
 (0)