diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..49194d1 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,41 @@ +name: tests + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + php: [7.4, 7.3, 7.2] + os: [ubuntu-latest, windows-latest] + + name: PHP${{ matrix.php }} on ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ~/.composer/cache/files + key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlite3, pdo_sqlite, pdo_mysql, bcmath, intl, gd, exif, iconv, imagick + coverage: none + + - name: Install dependencies + run: | + composer update --prefer-stable --prefer-dist --no-interaction --no-suggest + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.php_cs b/.php_cs index 04546f1..8be8ca0 100644 --- a/.php_cs +++ b/.php_cs @@ -15,7 +15,6 @@ return PhpCsFixer\Config::create() 'no_extra_consecutive_blank_lines' => false, 'no_unneeded_control_parentheses' => false, 'not_operator_with_successor_space' => true, - 'no_superfluous_phpdoc_tags' => false, 'ordered_imports' => ['sortAlgorithm' => 'alpha'], 'phpdoc_align' => false, 'phpdoc_no_empty_return' => false, diff --git a/CHANGELOG-3.x.md b/CHANGELOG-3.x.md deleted file mode 100644 index f0c83b7..0000000 --- a/CHANGELOG-3.x.md +++ /dev/null @@ -1,140 +0,0 @@ -# Changelog for 3.x - -This changelog references the relevant changes (bug and security fixes) done to `orchestra/model`. - -## 3.8.4 - -Released: 2019-09-11 - -### Added - -* Added `Orchestra\Model\HS`. -* Added `Orchestra\Model\Concerns\Swappable`. - -### Changes - -* Improves tests. - -## 3.8.3 - -Released: 2019-09-02 - -### Added - -* Added `Orchestra\Model\Eloquent::usesTransaction()`. - -### Deprecated - -* Deprecate `Orchestra\Model\Eloquent::transaction()`. - -## 3.8.2 - -Released: 2019-08-04 - -### Changes - -* Use `static function` rather than `function` whenever possible, the PHP engine does not need to instantiate and later GC a `$this` variable for said closure. - -## 3.8.1 - -Released: 2019-04-16 - -### Changes - -* Allow to pass optional parameters to `Orchestra\Model\Concerns\Faker::faker()`. - -## 3.8.0 - -Released: 2019-03-18 - -### Changes - -* Update support to Laravel Framework 5.8. - -## 3.7.2 - -Released: 2019-02-21 - -### Changes - -* Improve performance by prefixing all global functions calls with `\` to skip the look up and resolve process and go straight to the global function. - -## 3.7.1 - -Released: 2018-12-04 - -### Added - -* Add `Orchestra\Model\Concerns\Metable::forgetMetaData()` method helper. - -## 3.7.0 - -Released: 2018-11-19 - -### Changes - -* Update support to Laravel Framework 5.7. -* `Orchestra\Model\Concerns\Metable::mutateMetableAttribute()` should accept `$key` as first parameter to allow multiple JSON fields. - -### Removed - -* Remove deprecated `Orchestra\Model\Traits` namespace. - -## 3.6.4 - -Released: 2018-12-04 - -### Added - -* Add `Orchestra\Model\Concerns\Metable::forgetMetaData()` method helper. - -## 3.6.3 - -Released: 2018-08-16 - -### Changes - -* Avoid re-casting `meta` to instance of `Orchestra\Model\Value\Meta` when it already is. - -## 3.6.2 - -Released: 2018-06-05 - -### Changes - -* Improves `Orchestra\Model\Concerns\AdvancedSearchable` by parsing keyword using regular expression. - -## 3.6.1 - -Released: 2018-05-08 - -### Added - -* Added `Orchestra\Model\Concerns\AdvancedSearchable`. - -### Changes - -* Include `Orchestra\Model\Concerns\Searchable::scopeSearch()` by default. - -## 3.6.0 - -Released: 2018-05-02 - -### Added - -* Added `Orchestra\Model\Eloquent::column()`. -* Added `Orchestra\Model\Listeners\UserAccess`. - -### Changes - -* Update support to Laravel Framework 5.6. -* Rename the following classes: - - `Orchestra\Model\Memory\UserMetaProvider` to `Orchestra\Model\Memory\UserProvider`. - - `Orchestra\Model\Memory\UserMetaRepository` to `Orchestra\Model\Memory\UserRepository`. -* Rename the following traits: - - `Orchestra\Model\Traits\CheckRoles` to `Orchestra\Model\Concerns\CheckRoles`. - - `Orchestra\Model\Traits\Faker` to `Orchestra\Model\Concerns\Faker`. - - `Orchestra\Model\Traits\Metable` to `Orchestra\Model\Concerns\Metable`. - - `Orchestra\Model\Traits\OwnedBy` to `Orchestra\Model\Concerns\OwnedBy`. - - `Orchestra\Model\Traits\Owns` to `Orchestra\Model\Concerns\Owns`. - - `Orchestra\Model\Traits\Searchable` to `Orchestra\Model\Concerns\Searchable`. diff --git a/CHANGELOG-4.x.md b/CHANGELOG-4.x.md index f67d2d4..db5d6e8 100644 --- a/CHANGELOG-4.x.md +++ b/CHANGELOG-4.x.md @@ -39,7 +39,7 @@ Released: 2019-09-11 ### Changes -* Update support to Laravel Framework 6.0. +* Update support to Laravel Framework v6. ### Removed diff --git a/CHANGELOG-5.x.md b/CHANGELOG-5.x.md new file mode 100644 index 0000000..29fe15b --- /dev/null +++ b/CHANGELOG-5.x.md @@ -0,0 +1,18 @@ +# Changelog for 5.x + +This changelog references the relevant changes (bug and security fixes) done to `orchestra/model`. + +## 5.0.0 + +Released: 2020-03-09 + +### Changes + +* Update support to Laravel Framework v7. + +### Removed + +* Remove `Orchestra\Model\HS`, use `Laravie\Dhosa\HotSwap`. +* Remove `Orchestra\Model\Concerns\Swappable`, use `Laravie\Dhosa\Concerns\Swappable`. +* Remove deprecated `Orchestra\Model\Concerns\AdvancedSearch`, use `Orchestra\Model\Concerns\Searchable`. +* Remove deprecated `getSearchableRules()`, use `getSearchableTerms()`. diff --git a/composer.json b/composer.json index 8c74dd4..9c385e8 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ }, "require": { "php": ">=7.3", + "laravie/dhosa": "dev-master", "orchestra/contracts": "^6.0", "orchestra/database": "^6.0", "orchestra/support": "^6.0" diff --git a/src/Concerns/CheckRoles.php b/src/Concerns/CheckRoles.php index 7204cd8..883948d 100644 --- a/src/Concerns/CheckRoles.php +++ b/src/Concerns/CheckRoles.php @@ -2,6 +2,7 @@ namespace Orchestra\Model\Concerns; +use Illuminate\Support\Collection; use Orchestra\Model\Role; trait CheckRoles @@ -10,8 +11,6 @@ trait CheckRoles * Determine if current user has the given role. * * @param \Illuminate\Contracts\Support\Arrayable|array|string $roles - * - * @return bool */ public function hasRoles($roles): bool { @@ -32,8 +31,6 @@ public function hasRoles($roles): bool * Determine if current user has any of the given role. * * @param \Illuminate\Contracts\Support\Arrayable|array|string $roles - * - * @return bool */ public function hasAnyRoles($roles): bool { @@ -92,8 +89,6 @@ public function detachRoles($roles) /** * Get roles name as an array. - * - * @return \Illuminate\Support\Collection */ abstract public function getRoles(): Collection; } diff --git a/src/Concerns/Faker.php b/src/Concerns/Faker.php index af3c973..7af5d84 100644 --- a/src/Concerns/Faker.php +++ b/src/Concerns/Faker.php @@ -8,8 +8,6 @@ trait Faker { /** * Initiate faker factory. - * - * @return \Illuminate\Database\Eloquent\FactoryBuilder */ public static function faker(): FactoryBuilder { diff --git a/src/Concerns/Metable.php b/src/Concerns/Metable.php index b2d5541..42c4006 100644 --- a/src/Concerns/Metable.php +++ b/src/Concerns/Metable.php @@ -11,8 +11,6 @@ trait Metable * `meta` field accessor. * * @param mixed $value - * - * @return \Orchestra\Model\Value\Meta */ public function getMetaAttribute($value): Meta { @@ -23,8 +21,6 @@ public function getMetaAttribute($value): Meta * `meta` field mutator. * * @param mixed $value - * - * @return void */ public function setMetaAttribute($value = null): void { @@ -34,7 +30,6 @@ public function setMetaAttribute($value = null): void /** * Get original meta data. * - * @param string $key * @param mixed $default * * @return mixed @@ -49,7 +44,6 @@ public function getOriginalMetaData(string $key, $default = null) /** * Get meta data. * - * @param string $key * @param mixed $default * * @return mixed @@ -66,8 +60,6 @@ public function getMetaData(string $key, $default = null) * * @param string|array $key * @param mixed $value - * - * @return void */ public function putMetaData($key, $value = null): void { @@ -88,8 +80,6 @@ public function putMetaData($key, $value = null): void * Forget meta data. * * @param string|array $key - * - * @return void */ public function forgetMetaData($key): void { @@ -110,8 +100,6 @@ public function forgetMetaData($key): void * Access meta attribute. * * @param mixed $value - * - * @return \Orchestra\Model\Value\Meta */ protected function accessMetableAttribute($value): Meta { @@ -129,10 +117,7 @@ protected function accessMetableAttribute($value): Meta /** * Get value from mixed content. * - * @param string $key * @param mixed $value - * - * @return string|null */ protected function mutateMetableAttribute(string $key, $value): ?string { diff --git a/src/Concerns/OwnedBy.php b/src/Concerns/OwnedBy.php index 5160333..46d2b62 100644 --- a/src/Concerns/OwnedBy.php +++ b/src/Concerns/OwnedBy.php @@ -9,12 +9,6 @@ trait OwnedBy { /** * Scope query to get model which are owned by the specified model. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Model $related - * @param string|null $key - * - * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOwnedBy(Builder $query, Model $related, ?string $key = null): Builder { @@ -27,11 +21,6 @@ public function scopeOwnedBy(Builder $query, Model $related, ?string $key = null /** * Check if related model actually owns the relationship. - * - * @param \Illuminate\Database\Eloquent\Model|null $related - * @param string|null $key - * - * @return bool */ public function ownedBy(Model $related = null, ?string $key = null): bool { diff --git a/src/Concerns/Owns.php b/src/Concerns/Owns.php index 07b7a98..47c5e2a 100644 --- a/src/Concerns/Owns.php +++ b/src/Concerns/Owns.php @@ -9,12 +9,6 @@ trait Owns { /** * Scope query to get model which related model actually owns the relationship. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Model $related - * @param string|null $foreignKey - * - * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOwns(Builder $query, Model $related, ?string $foreignKey = null): Builder { @@ -29,11 +23,6 @@ public function scopeOwns(Builder $query, Model $related, ?string $foreignKey = /** * Check if related model actually owns the relationship. - * - * @param \Illuminate\Database\Eloquent\Model|null $related - * @param string|null $foreignKey - * - * @return bool */ public function owns(Model $related = null, ?string $foreignKey = null): bool { diff --git a/src/Concerns/Searchable.php b/src/Concerns/Searchable.php index ab20e4e..aa1dd80 100644 --- a/src/Concerns/Searchable.php +++ b/src/Concerns/Searchable.php @@ -10,10 +10,6 @@ trait Searchable /** * Advanced search from query builder. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param string|null $searchTerm - * @param array|null $columns - * * @return \Illuminate\Database\Query\Builder */ public function scopeSearch(Builder $query, ?string $searchTerm, ?array $columns = null): Builder @@ -25,8 +21,6 @@ public function scopeSearch(Builder $query, ?string $searchTerm, ?array $columns /** * Get searchable rules. - * - * @return array */ public function getSearchableTerms(): array { @@ -35,8 +29,6 @@ public function getSearchableTerms(): array /** * Get searchable attributes. - * - * @return array */ public function getSearchableColumns(): array { diff --git a/src/Concerns/Swappable.php b/src/Concerns/Swappable.php deleted file mode 100644 index 6f6205a..0000000 --- a/src/Concerns/Swappable.php +++ /dev/null @@ -1,92 +0,0 @@ -newQuery(); - } - - /** - * Make Hot-swappable faker model. - * - * @param array $attributes - * - * @return \Illuminate\Database\Eloquent\FactoryBuilder - */ - public static function hsFaker(): FactoryBuilder - { - $arguments = \func_get_args(); - - \array_unshift($arguments, static::hsFinder()); - - return \factory(...$arguments); - } - - /** - * Make Hot-swappable model on write connection. - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public static function hsOnWriteConnection(): Builder - { - return static::hs()->query()->onWritePdo(); - } - - /** - * Make Hot-swappable model on specific connection. - * - * @param string|null $connection - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public static function hsOn(?string $connection = null): Builder - { - return \tap(static::hs(), static function ($instance) use ($connection) { - $instance->setConnection($connection); - })->newQuery(); - } - - /** - * Find Hot-swappable full namespace model. - * - * @return string - */ - public static function hsFinder(): string - { - return HS::eloquent(static::hsAliasName()); - } - - /** - * Get Hot-swappable alias name. - * - * @return string - */ - abstract public static function hsAliasName(): string; -} diff --git a/src/Eloquent.php b/src/Eloquent.php index ac5e699..c1a79eb 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -14,10 +14,6 @@ abstract class Eloquent extends Model implements Transformable /** * Get qualified column name. - * - * @param string $column - * - * @return string */ public static function column(string $column): string { @@ -28,8 +24,6 @@ public static function column(string $column): string /** * Determine if the model instance uses soft deletes. - * - * @return bool */ public function isSoftDeleting(): bool { @@ -38,10 +32,6 @@ public function isSoftDeleting(): bool /** * Save the model to the database if exists. - * - * @param array $options - * - * @return bool */ public function saveIfExists(array $options = []): bool { @@ -54,10 +44,6 @@ public function saveIfExists(array $options = []): bool /** * Save the model to the database using transaction if exists. - * - * @param array $options - * - * @return bool */ public function saveIfExistsOrFail(array $options = []): bool { @@ -71,8 +57,6 @@ public function saveIfExistsOrFail(array $options = []): bool /** * Execute a Closure within a transaction. * - * @param \Closure $callback - * * @throws \Throwable * * @return mixed @@ -85,8 +69,6 @@ public function usesTransaction(Closure $callback) /** * Transform each attribute in the model using a callback. * - * @param callable $callback - * * @return \Orchestra\Support\Fluent */ public function transform(callable $callback) diff --git a/src/HS.php b/src/HS.php index 5b31074..ecfe2be 100644 --- a/src/HS.php +++ b/src/HS.php @@ -20,11 +20,7 @@ final class HS /** * Register swappable model. * - * @param string $class - * * @throws \InvalidArgumentException - * - * @return void */ public static function register(string $class): void { @@ -37,12 +33,7 @@ public static function register(string $class): void /** * Override swappable model. * - * @param string $alias - * @param string $class - * * @throws \InvalidArgumentException - * - * @return void */ public static function override(string $alias, string $class): void { @@ -53,10 +44,6 @@ public static function override(string $alias, string $class): void /** * Resolve model class name. - * - * @param string $alias - * - * @return string */ public static function eloquent(string $alias): string { @@ -66,12 +53,7 @@ public static function eloquent(string $alias): string /** * Make a model instance. * - * @param string $alias - * @param array $attributes - * * @throws \InvalidArgumentException - * - * @return \Illuminate\Database\Eloquent\Model */ public static function make(string $alias, array $attributes = []): Model { @@ -84,8 +66,6 @@ public static function make(string $alias, array $attributes = []): Model /** * Flush hot-swap mapping. - * - * @return void */ public static function flush(): void { @@ -98,11 +78,7 @@ public static function flush(): void /** * Validate class is an eloquent model. * - * @param string $class - * * @throws \InvalidArgumentException - * - * @return void */ private static function validateClassIsEloquentModel(string $class): void { @@ -114,11 +90,7 @@ private static function validateClassIsEloquentModel(string $class): void /** * Validate class is an eloquent model. * - * @param string $class - * * @throws \InvalidArgumentException - * - * @return void */ private static function validateClassIsSwappable(string $class): void { diff --git a/src/Listeners/UserAccess.php b/src/Listeners/UserAccess.php index bed30ee..bb41117 100644 --- a/src/Listeners/UserAccess.php +++ b/src/Listeners/UserAccess.php @@ -9,10 +9,6 @@ class UserAccess { /** * Match current user to roles. - * - * @param \Orchestra\Model\User|null $user - * - * @return \Illuminate\Support\Collection|null */ public function handle(?User $user): ?Collection { diff --git a/src/Memory/UserProvider.php b/src/Memory/UserProvider.php index e073a46..26aaafa 100644 --- a/src/Memory/UserProvider.php +++ b/src/Memory/UserProvider.php @@ -11,7 +11,7 @@ class UserProvider extends Provider * Get value of a key. * * @param string $key - * @param mixed $default + * @param mixed $default * * @return mixed */ @@ -44,8 +44,7 @@ public function get(string $key = null, $default = null) /** * Set a value from a key. * - * @param string $key - * @param mixed $value + * @param mixed $value * * @return mixed */ @@ -62,9 +61,7 @@ public function put(string $key, $value = '') /** * Delete value of a key. * - * @param string $key - * - * @return bool + * @param string $key */ public function forget(string $key = null): bool { diff --git a/src/Memory/UserRepository.php b/src/Memory/UserRepository.php index b5afd2b..ed83350 100644 --- a/src/Memory/UserRepository.php +++ b/src/Memory/UserRepository.php @@ -26,10 +26,6 @@ class UserRepository extends Handler implements HandlerContract /** * Setup a new memory handler. - * - * @param string $name - * @param array $config - * @param \Illuminate\Contracts\Container\Container $container */ public function __construct(string $name, array $config, Container $container) { @@ -40,8 +36,6 @@ public function __construct(string $name, array $config, Container $container) /** * Initiate the instance. - * - * @return array */ public function initiate(): array { @@ -51,8 +45,6 @@ public function initiate(): array /** * Get value from database. * - * @param string $key - * * @return mixed */ public function retrieve(string $key) @@ -70,10 +62,6 @@ public function retrieve(string $key) /** * Add a finish event. - * - * @param array $items - * - * @return bool */ public function finish(array $items = []): bool { @@ -89,8 +77,6 @@ public function finish(array $items = []): bool * * @param string|int $userId * @param \Illuminate\Support\Collection|array $data - * - * @return array */ protected function processRetrievedData($userId, $data = []): array { @@ -117,10 +103,7 @@ protected function processRetrievedData($userId, $data = []): array /** * Save user meta to memory. * - * @param string $key * @param mixed $value - * - * @return void */ protected function save(string $key, $value): void { @@ -140,12 +123,8 @@ protected function save(string $key, $value): void /** * Process saving the value to memory. * - * @param string $name * @param mixed $userId * @param mixed $value - * @param bool $isNew - * - * @return void */ protected function saving(string $name, $userId, $value = null, bool $isNew = true): void { diff --git a/src/Observer/Role.php b/src/Observer/Role.php index 536e09f..26d5c1a 100644 --- a/src/Observer/Role.php +++ b/src/Observer/Role.php @@ -18,8 +18,6 @@ class Role /** * Construct a new role observer. - * - * @param \Orchestra\Contracts\Authorization\Factory $acl */ public function __construct(Factory $acl) { @@ -28,10 +26,6 @@ public function __construct(Factory $acl) /** * On creating observer. - * - * @param \Orchestra\Model\Role $model - * - * @return void */ public function creating(Eloquent $model): void { @@ -40,10 +34,6 @@ public function creating(Eloquent $model): void /** * On saving observer. - * - * @param \Orchestra\Model\Role $model - * - * @return void */ public function saving(Eloquent $model): void { @@ -56,10 +46,6 @@ public function saving(Eloquent $model): void /** * On deleting observer. - * - * @param \Orchestra\Model\Role $model - * - * @return void */ public function deleting(Eloquent $model): void { @@ -68,10 +54,6 @@ public function deleting(Eloquent $model): void /** * On updating/restoring observer. - * - * @param \Orchestra\Model\Role $model - * - * @return void */ public function updating(Eloquent $model): void { @@ -87,10 +69,6 @@ public function updating(Eloquent $model): void /** * Is restoring model. - * - * @param \Orchestra\Model\Role $model - * - * @return bool */ protected function isRestoringModel(Eloquent $model): bool { diff --git a/src/Plugins/RefreshOnCreate.php b/src/Plugins/RefreshOnCreate.php index 03bead3..00853dc 100644 --- a/src/Plugins/RefreshOnCreate.php +++ b/src/Plugins/RefreshOnCreate.php @@ -8,8 +8,6 @@ trait RefreshOnCreate { /** * Boot the refresh on create trait for a model. - * - * @return void */ public static function bootRefreshOnCreate(): void { diff --git a/src/Role.php b/src/Role.php index 8fd3825..08921b4 100644 --- a/src/Role.php +++ b/src/Role.php @@ -4,11 +4,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Laravie\Dhosa\Concerns\Swappable; class Role extends Eloquent { use SoftDeletes, - Concerns\Swappable; + Swappable; /** * The database table used by the model. @@ -43,10 +44,6 @@ class Role extends Eloquent /** * Set default roles. - * - * @param array $roles - * - * @return void */ public static function setDefaultRoles(array $roles): void { @@ -55,8 +52,6 @@ public static function setDefaultRoles(array $roles): void /** * Has many and belongs to relationship with User. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function users(): BelongsToMany { @@ -85,8 +80,6 @@ public static function member() /** * Get Hot-swappable alias name. - * - * @return string */ final public static function hsAliasName(): string { diff --git a/src/Scopes/UserWithRoleScope.php b/src/Scopes/UserWithRoleScope.php index 8939d16..7b04613 100644 --- a/src/Scopes/UserWithRoleScope.php +++ b/src/Scopes/UserWithRoleScope.php @@ -27,11 +27,6 @@ public function __construct($roles) /** * Apply the scope to a given Eloquent query builder. - * - * @param \Illuminate\Database\Eloquent\Builder $builder - * @param \Illuminate\Database\Eloquent\Model $model - * - * @return void */ public function apply(Builder $builder, Model $model): void { diff --git a/src/User.php b/src/User.php index 42450be..575ea3c 100644 --- a/src/User.php +++ b/src/User.php @@ -5,9 +5,11 @@ use Illuminate\Auth\Authenticatable; use Illuminate\Contracts\Auth\Authenticatable as UserContract; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Hash; +use Laravie\Dhosa\Concerns\Swappable; use Orchestra\Contracts\Authorization\Authorizable; class User extends Eloquent implements Authorizable, UserContract @@ -15,7 +17,7 @@ class User extends Eloquent implements Authorizable, UserContract use Authenticatable, Concerns\CheckRoles, Concerns\Searchable, - Concerns\Swappable, + Swappable, SoftDeletes; /** @@ -55,8 +57,6 @@ class User extends Eloquent implements Authorizable, UserContract /** * Get searchable rules. - * - * @return array */ public function getSearchableTerms(): array { @@ -69,11 +69,6 @@ public function getSearchableTerms(): array /** * Search user based on keyword as roles. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $roles - * - * @return \Illuminate\Database\Eloquent\Builder */ public function scopeHasRoles(Builder $query, array $roles = []): Builder { @@ -90,11 +85,6 @@ public function scopeHasRoles(Builder $query, array $roles = []): Builder /** * Search user based on keyword as roles id. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $rolesId - * - * @return \Illuminate\Database\Eloquent\Builder */ public function scopeHasRolesId(Builder $query, array $rolesId = []): Builder { @@ -111,20 +101,14 @@ public function scopeHasRolesId(Builder $query, array $rolesId = []): Builder /** * Has many and belongs to relationship with Role. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function roles() + public function roles(): BelongsToMany { return $this->belongsToMany(Role::hsFinder(), 'user_role', 'user_id', 'role_id')->withTimestamps(); } /** * Set `password` mutator. - * - * @param string $value - * - * @return void */ public function setPasswordAttribute(string $value): void { @@ -174,8 +158,6 @@ public function suspend() /** * Determine if the current user account activated or not. - * - * @return bool */ public function isActivated(): bool { @@ -184,8 +166,6 @@ public function isActivated(): bool /** * Determine if the current user account suspended or not. - * - * @return bool */ public function isSuspended(): bool { @@ -218,8 +198,6 @@ public function detachRole($roles) /** * Get roles name as an array. - * - * @return \Illuminate\Support\Collection */ public function getRoles(): Collection { @@ -234,8 +212,6 @@ public function getRoles(): Collection /** * Get Hot-swappable alias name. - * - * @return string */ final public static function hsAliasName(): string { diff --git a/src/Value/Meta.php b/src/Value/Meta.php index 6bda1d7..8708b72 100644 --- a/src/Value/Meta.php +++ b/src/Value/Meta.php @@ -38,8 +38,6 @@ public function put(string $key, $value = '') /** * Forget a key. * - * @param string $key - * * @return $this */ public function forget(string $key) diff --git a/tests/Feature/Concerns/SwappableTest.php b/tests/Feature/Concerns/SwappableTest.php deleted file mode 100644 index 0f8ccc0..0000000 --- a/tests/Feature/Concerns/SwappableTest.php +++ /dev/null @@ -1,64 +0,0 @@ - 'Staff']); - - $this->assertInstanceOf(Role::class, $role); - $this->assertSame('Staff', $role->name); - $this->assertFalse($role->exists); - } - - /** @test */ - public function it_can_create_an_instance_of_eloquent_query_builder() - { - $query = static::hsQuery(); - - $this->assertInstanceOf(Builder::class, $query); - $this->assertInstanceOf(Role::class, $query->getModel()); - } - - /** @test */ - public function it_can_create_an_instance_of_eloquent_faker_builder() - { - $builder = static::hsFaker(); - - $this->assertInstanceOf(FactoryBuilder::class, $builder); - - $role = $builder->create(['name' => 'Moderator']); - - $this->assertTrue($role->exists); - $this->assertSame('Moderator', $role->name); - $this->assertInstanceOf(Role::class, $role); - } - - /** @test */ - public function it_can_find_the_hs_model_name() - { - $this->assertSame(Role::class, static::hsFinder()); - } - - /** - * Get Hot-swappable alias name. - * - * @return string - */ - public static function hsAliasName(): string - { - return 'Role'; - } -} diff --git a/tests/Feature/RoleTest.php b/tests/Feature/RoleTest.php index dc7fba7..c894128 100644 --- a/tests/Feature/RoleTest.php +++ b/tests/Feature/RoleTest.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Foundation\Testing\RefreshDatabase; -use Orchestra\Model\HS; +use Laravie\Dhosa\HotSwap; use Orchestra\Model\Role; use Orchestra\Model\User; @@ -19,7 +19,7 @@ protected function tearDown(): void { parent::tearDown(); - HS::flush(); + HotSwap::flush(); } /** @test */ @@ -32,7 +32,7 @@ public function it_implements_hot_swap() $this->assertNotInstanceOf(RoleStub::class, $user); $this->assertInstanceOf(Role::class, $user); - HS::override('Role', RoleStub::class); + HotSwap::override('Role', RoleStub::class); $user = Role::hs(); diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 62a25e4..09e96f3 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -37,8 +37,6 @@ protected function getPackageProviders($app) * Override application aliases. * * @param \Illuminate\Foundation\Application $app - * - * @return array */ protected function overrideApplicationProviders($app): array { diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index b2120c4..e001088 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -5,8 +5,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Hash; +use Laravie\Dhosa\HotSwap; use Mockery as m; -use Orchestra\Model\HS; use Orchestra\Model\Role; use Orchestra\Model\User; @@ -21,7 +21,7 @@ protected function tearDown(): void { parent::tearDown(); - HS::flush(); + HotSwap::flush(); } /** @test */ @@ -34,7 +34,7 @@ public function it_implements_hot_swap() $this->assertNotInstanceOf(UserStub::class, $user); $this->assertInstanceOf(User::class, $user); - HS::override('User', UserStub::class); + HotSwap::override('User', UserStub::class); $user = User::hs(); diff --git a/tests/Unit/HotSwapTest.php b/tests/Unit/HotSwapTest.php deleted file mode 100644 index e362709..0000000 --- a/tests/Unit/HotSwapTest.php +++ /dev/null @@ -1,68 +0,0 @@ -assertSame(SwappableModel::class, Hs::eloquent('Model')); - $this->assertInstanceOf(SwappableModel::class, Hs::make('Model')); - } - - /** @test */ - public function it_cant_register_none_swappable_class() - { - $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessage('Given [Orchestra\Model\Tests\Unit\NotSwappableModel] doesn\'t use [Orchestra\Model\Concerns\Swappable] trait.'); - - HS::register(NotSwappableModel::class); - } - - /** @test */ - public function it_cant_register_none_eloquent_class() - { - $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessage('Given [Orchestra\Model\Tests\Unit\NotModel] is not a subclass of [Illuminate\Database\Eloquent\Model].'); - - HS::register(NotModel::class); - } -} - -class SwappableModel extends Model -{ - use Swappable; - - public static function hsAliasName(): string - { - return 'Model'; - } -} - -class NotSwappableModel extends Model -{ - // -} - -class NotModel -{ - // -}