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

Add Laravel 9 support #6

Merged
merged 2 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0]
php: [8.1]
dependency-version: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0]
php: [8.1]
dependency-version: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4, 8.0]
php: [7.4, 8.0, 8.1]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This changelog is initialized in release 1.0.0

## [Unreleased]

### Added
* Laravel 9 support

## [v2.1.1] - 2022-01-18

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"homepage": "https://github.com/wimski/laravel-model-repositories",
"require": {
"php": "^7.4 || ^8.0",
"laravel/framework": "^8.0"
"laravel/framework": "^8.0 || ^9.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"nunomaduro/larastan": "^1.0",
"orchestra/testbench": "^6.23",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^1.0 || ^2.0",
"orchestra/testbench": "^6.23 || ^7.0",
"phpstan/phpstan-mockery": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
Expand Down
28 changes: 14 additions & 14 deletions src/Contracts/Repositories/ModelRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,44 @@ public function find($key, string ...$column);
public function findOrFail($key, string ...$column);

/**
* @param int[]|string[]|Arrayable $keys
* @param string ...$column
* @return Collection<T>
* @param int[]|string[]|Arrayable<int|string, mixed> $keys
* @param string ...$column
* @return Collection<int, T>
*/
public function findMany($keys, string ...$column): Collection;

/**
* @param string|mixed[]|Closure|Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return T|null
*/
public function firstWhere($column, $operator = null, $value = null, string $boolean = 'and');

/**
* @param string|mixed[]|Closure|Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return T
* @throws ModelNotFoundException
*/
public function firstWhereOrFail($column, $operator = null, $value = null, string $boolean = 'and');

/**
* @param string|mixed[]|Closure|Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return Collection<T>
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return Collection<int, T>
*/
public function where($column, $operator = null, $value = null, string $boolean = 'and'): Collection;

/**
*
* @param string ...$column
* @return Collection<T>
* @return Collection<int, T>
*/
public function all(string ...$column): Collection;
}
8 changes: 4 additions & 4 deletions src/Repositories/AbstractModelRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function findOrFail($key, string ...$column)

public function findMany($keys, string ...$column): Collection
{
/** @var Collection<T> $models */
/** @var Collection<int, T> $models */
$models = $this->model->findMany($keys, $this->parseColumns(...$column));

return $models;
Expand Down Expand Up @@ -65,15 +65,15 @@ public function firstWhereOrFail($column, $operator = null, $value = null, strin

public function where($column, $operator = null, $value = null, string $boolean = 'and'): Collection
{
/** @var Collection<T> $models */
/** @var Collection<int, T> $models */
$models = $this->model->where($column, $operator, $value, $boolean)->get();

return $models;
}

public function all(string ...$column): Collection
{
/** @var Collection<T> $models */
/** @var Collection<int, T> $models */
$models = $this->model->all($this->parseColumns(...$column));

return $models;
Expand All @@ -94,6 +94,6 @@ protected function parseColumns(string ...$column): array
*/
protected function throwModelNotFoundException(...$key): void
{
throw (new ModelNotFoundException())->setModel(get_class($this->model), $key);
throw (new ModelNotFoundException())->setModel(get_class($this->model), array_values($key));
}
}
10 changes: 5 additions & 5 deletions tests/Integration/Repositories/ModelRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ModelRepositoryTest extends AbstractIntegrationTest
protected ModelWithRepositoryRepository $repository;

/**
* @var Collection<ModelWithRepository>
* @var Collection<int, ModelWithRepository>
*/
protected Collection $models;

Expand Down Expand Up @@ -314,8 +314,8 @@ public function it_returns_a_collection_with_a_specific_columns_for_all(): void
}

/**
* @param Collection<ModelWithRepository> $expected
* @param Collection<ModelWithRepository> $actual
* @param Collection<int, ModelWithRepository> $expected
* @param Collection<int, ModelWithRepository> $actual
*/
protected function assertSameModels(Collection $expected, Collection $actual): void
{
Expand All @@ -330,7 +330,7 @@ protected function assertSameModels(Collection $expected, Collection $actual): v
}

/**
* @param Collection<ModelWithRepository> $models
* @param Collection<int, ModelWithRepository> $models
* @param string $column
*/
protected function assertModelsHaveColumn(Collection $models, string $column): void
Expand All @@ -344,7 +344,7 @@ protected function assertModelsHaveColumn(Collection $models, string $column): v
}

/**
* @param Collection<ModelWithRepository> $models
* @param Collection<int, ModelWithRepository> $models
* @param string $column
*/
protected function assertModelsDoNotHaveColumn(Collection $models, string $column): void
Expand Down
3 changes: 3 additions & 0 deletions tests/Laravel/App/Models/ModelWithRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ModelWithRepository extends Model
{
use HasFactory;

/**
* @return Factory<ModelWithRepository>
*/
protected static function newFactory(): Factory
{
return new ModelWithRepositoryFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Database\Eloquent\Factories\Factory;
use Wimski\ModelRepositories\Tests\Laravel\App\Models\ModelWithRepository;

/**
* @extends Factory<ModelWithRepository>
*/
class ModelWithRepositoryFactory extends Factory
{
protected $model = ModelWithRepository::class;
Expand Down