Skip to content

Commit

Permalink
cs.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Mar 11, 2021
1 parent 0329c13 commit b13410a
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 119 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ $post->getVersion(3)->revert();

$post->revertToVersion(3);
```
#### Reversion without Save

```php
$newPost = $post->revertWithoutSaving()
```

### Remove versions

Expand Down
8 changes: 0 additions & 8 deletions config/versionable.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

return [
/*
* Keep versions, you can redefine in target model.
Expand Down
8 changes: 0 additions & 8 deletions migrations/2019_05_31_042934_create_versions_table.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand Down
11 changes: 0 additions & 11 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Overtrue\LaravelVersionable;

/**
* Class ServiceProvider.
*/
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot()
Expand Down
24 changes: 8 additions & 16 deletions src/Version.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Overtrue\LaravelVersionable;

use Illuminate\Database\Eloquent\Model;
Expand All @@ -16,8 +8,6 @@
use SebastianBergmann\Diff\Differ;

/**
* Class Version.
*
* @property Model $versionable
* @property array $contents
*/
Expand Down Expand Up @@ -51,7 +41,7 @@ public function user()
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function versionable()
public function versionable(): \Illuminate\Database\Eloquent\Relations\MorphTo
{
return $this->morphTo('versionable');
}
Expand All @@ -62,8 +52,9 @@ public function versionable()
*
* @return \Overtrue\LaravelVersionable\Version
*/
public static function createForModel(Model $model, array $attributes = [])
public static function createForModel(Model $model, array $attributes = []): Version
{
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */
$versionClass = $model->getVersionModel();

$version = new $versionClass();
Expand All @@ -85,22 +76,23 @@ public function revert()
{
return $this->versionable->fill($this->contents)->save();
}

/**
* @return \Illuminate\Database\Eloquent\Model|null $model
*/
public function revertWithoutSaving()
public function revertWithoutSaving(): ?Model
{
return $this->versionable->fill($this->contents);
return $this->versionable->fill($this->contents);
}

/**
* @param \Illuminate\Database\Eloquent\Model|null $model
*
* @return string
*/
public function diff(Model $model = null)
public function diff(Model $model = null): string
{
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */
$model || $model = $this->versionable;

if ($model instanceof Version) {
Expand Down
11 changes: 0 additions & 11 deletions src/VersionStrategy.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Overtrue\LaravelVersionable;

/**
* Class VersionStrategy.
*/
class VersionStrategy
{
public const DIFF = 'diff';
Expand Down
10 changes: 2 additions & 8 deletions src/Versionable.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Overtrue\LaravelVersionable;

use Illuminate\Database\Eloquent\Model;
Expand All @@ -34,6 +26,7 @@ function (Model $model) {

static::deleted(
function (Model $model) {
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */
if ($model->forceDeleting) {
$model->forceRemoveAllVersions();
} else {
Expand All @@ -45,6 +38,7 @@ function (Model $model) {

private static function createVersionForModel(Model $model): void
{
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */
if (static::$versioning && $model->shouldVersioning()) {
Version::createForModel($model);
$model->removeOldVersions($model->getKeepVersionsCount());
Expand Down
11 changes: 0 additions & 11 deletions tests/FeatureTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Tests;

use Overtrue\LaravelVersionable\VersionStrategy;

/**
* Class FeatureTest.
*/
class FeatureTest extends TestCase
{
protected $user;
Expand Down
11 changes: 0 additions & 11 deletions tests/Post.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Tests;

use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelVersionable\Versionable;
use Overtrue\LaravelVersionable\VersionStrategy;

/**
* Class Post.
*/
class Post extends Model
{
use Versionable;
Expand Down
8 changes: 0 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Tests;

use Overtrue\LaravelVersionable\ServiceProvider;
Expand Down
11 changes: 0 additions & 11 deletions tests/User.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Tests;

/**
* Class User.
*/
class User extends \Illuminate\Foundation\Auth\User
{
protected $fillable = ['name'];
Expand Down
8 changes: 0 additions & 8 deletions tests/migrations/2018_12_14_095815_create_posts_table.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

Expand Down
8 changes: 0 additions & 8 deletions tests/migrations/2018_12_14_095815_create_users_table.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

/*
* This file is part of the overtrue/laravel-versionable.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

Expand Down

0 comments on commit b13410a

Please sign in to comment.