Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some (hopefully constructive) criticism of this package #2

Closed
uuf6429 opened this issue Apr 13, 2021 · 3 comments
Closed

Some (hopefully constructive) criticism of this package #2

uuf6429 opened this issue Apr 13, 2021 · 3 comments

Comments

@uuf6429
Copy link

uuf6429 commented Apr 13, 2021

  1. There is an expirable() blueprint method, but no opposite (removeExpirable() or similar):
         public function removeExpirable()
         {
             return function ($columnName = 'expires_at') {
                 return $this->dropColumn($columnName);
             };
         }
  2. The Expirable trait is missing docs for macro/extension/magic methods (as an example, see laravel's SoftDeletes trait):
         /**
          * @mixin ExpirableEloquentQueryBuilder   <- this works because of completely overwriting query builder
          */
  3. The trait has two things that makes it incompatible / risky with other package:
    1. it defines 'boot' method which means models and other traits can't use it, instead it should be bootExpirable (which is a laravel feature) - this is also how SoftDeletes trait does it
    2. Similarly, overwriting the query builder is a bad idea - it will clash with any other attempt by the end users or other 3rd-party traits. Instead, you could do it like SoftDeletingScope by adding macro methods:
      class ExpirationScope implements Scope
      {
          public function apply(Builder $builder, Model $model)
          {
              ...
          }
      
          public function extend(Builder $builder)
          {
              $builder->macro('onlyExpired', function (Builder $builder) {
                  return $builder->withoutGlobalScope(ExpirationScope::class)
                      ->where($this->model->getExpirationAttribute(), '<=', Carbon::now());
              });
              ...
      In this case, use /** @method static static|EloquentBuilder|QueryBuilder onlyExpired() */ for point 2
    3. There should be a lot of caution when adding methods to the trait - each method is yet another compatibility risk*
  4. ..speaking of which, maybe check grammar - $subscriptions->expiredOnly() is more idiomatic/correct, for example
  5. There's some unnecessary/redundant PHPDoc (eg, all PHPDoc in PurgeCommand and other internal classes)
  6. This package clearly depends on some laravel packages (basically all the parent classes), however these dependencies are not required in composer.json

(*) this shows the problem with traits - methods in the same level cannot be overridden and in case of conflicts, you're forced to choose an implementation and you can't later on call the other methods, unlike class inheritance where you can call the parent method

The first 3 points are the most 'painful' and point 4 would be a BC break.
If I get some time later, I might try opening a PR..


On a different point, there's another competing package that solves some of the issues above, but has its own problems: mvdnbrk/laravel-model-expires - maybe you guys could join efforts into one solution that works well with the best of both?

@alajusticia
Copy link
Owner

Hello @uuf6429,

Thanks for your feedback, many interesting points here.

I will try to work on some of them when I get time, or you could open a PR that I will be happy to look at.

@alajusticia
Copy link
Owner

Issues resolved in v1.5

@alajusticia
Copy link
Owner

Except for point 4: the names of the methods withExpired() and onlyExpired() were chosen to follow the pattern of the SoftDeletes trait (withTrashed and onlyTrashed).
Besides it would introduce a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants