Skip to content

Commit

Permalink
chore: add PHP types to all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Oct 4, 2021
1 parent bbea912 commit 78c3671
Show file tree
Hide file tree
Showing 81 changed files with 1,273 additions and 1,160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/monorepo-split.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
coverage: none
- uses: "ramsey/composer-install@v1"
- id: packages-list
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0, 7.4, 7.3]
laravel: [8.*, 7.*, 6.*]
php: [8.0]
laravel: [8.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
steps:
- uses: actions/checkout@v2
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,12 @@ The simplest option is to create a new model in your app, and let it extend the

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Squire\Models\Country as SquireCountry;

class Country extends SquireCountry
{
public function users()
public function users(): HasMany
{
return $this->hasMany(User::class);
}
Expand All @@ -288,9 +289,10 @@ Another option is the `resolveRelationUsing()` method. This allows you to dynami

```php
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Squire\Models\Country;

Country::resolveRelationUsing('users', function (Country $country) {
Country::resolveRelationUsing('users', function (Country $country): HasMany {
return $country->hasMany(User::class);
});
```
Expand All @@ -305,7 +307,7 @@ Rules can be found in the `Squire\Rules` namespace. To use one, simply construct
use Squire\Rules;

$request->validate([
'country' => ['required', 'string', new Rules\Country('name')],
'country' => ['required', 'string', new Rules\CountryRule('name')],
]);
```

Expand Down Expand Up @@ -334,7 +336,7 @@ use Squire\Model;

class Language extends Model
{
public static $schema = [
public static array $schema = [
'id' => 'string',
'name' => 'string',
];
Expand Down Expand Up @@ -362,9 +364,9 @@ use Squire\Repository;

class ModelServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
Repository::registerSource(Language::class, 'en', __DIR__.'/../../resources/squire-data/languages-en.csv');
Repository::registerSource(Language::class, 'en', __DIR__ . '/../../resources/squire-data/languages-en.csv');
}
}
```
Expand Down Expand Up @@ -395,13 +397,14 @@ Your rule class should contain, at minimum, a `$message` to be served if the val
namespace App\Rules;

use App\Models;
use Illuminate\Database\Eloquent\Builder;
use Squire\Rule;

class Language extends Rule
class LanguageRule extends Rule
{
protected $message = 'validation.language';
protected string $message = 'validation.language';

protected function getQueryBuilder()
protected function getQueryBuilder(): Builder
{
return Models\Language::query();
}
Expand All @@ -419,7 +422,7 @@ use Squire\Rule;

class Language extends Rule
{
protected $column = 'name';
protected string $column = 'name';
}
```

Expand All @@ -443,11 +446,11 @@ As an example, we will install the `Squire\Models\Country` and `Squire\Models\Co
composer require squirephp/countries-en squirephp/continents-en
```

### Breaking Changes Introduced in 2.x
### Breaking Changes Introduced in 3.x

- The original `Squire\Models\Counties\GbCounty` model has now been moved to `Squire\Models\GbCounty`.
- The minimum PHP version has been bumped to v8.0, and the minimum Laravel version to v8.x.

- The [`$map` property](https://github.com/squirephp/legacy#column-customisation) has been deprecated to improve performance of the package with large datasets. Please set up [Eloquent accessors](https://laravel.com/docs/master/eloquent-mutators#defining-an-accessor) if you require a similar feature.
- Types have been introduced to all classes. If you have created [custom models](#creating-a-model) and [custom validation rules](#creating-a-validation-rule), properties and methods now need to use the correct types.

## Need Help?

Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Supported |
| ------- | ------------------ |
| 3.x | :white_check_mark: |
| 2.x | :white_check_mark: |
| 1.x | :white_check_mark: |

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
}
],
"require": {
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0 || ^7.0 || ^8.0",
"php": "^8.0",
"illuminate/contracts": "^8.0",
"illuminate/database": "^6.0 || ^7.0 || ^8.40.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
"illuminate/support": "^8.0",
"akaunting/laravel-money": "^1.2"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 39 additions & 37 deletions packages/airlines-en/composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
{
"name": "squirephp/airlines-en",
"description": "A library containing the English translation of Squire's Airline model.",
"keywords": ["squire"],
"license": "MIT",
"homepage": "https://github.com/squirephp",
"support": {
"issues": "https://github.com/squirephp/squire/issues",
"source": "https://github.com/squirephp/squire"
},
"authors": [
{
"name": "Dan Harrin",
"email": "[email protected]"
}
],
"require": {
"php": "^7.2|^8.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
"squirephp/airlines": "^2.0",
"squirephp/repository": "^2.0"
},
"autoload": {
"psr-4": {
"Squire\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Squire\\AirlinesEnServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
"name": "squirephp/airlines-en",
"description": "A library containing the English translation of Squire's Airline model.",
"keywords": [
"squire"
],
"license": "MIT",
"homepage": "https://github.com/squirephp",
"support": {
"issues": "https://github.com/squirephp/squire/issues",
"source": "https://github.com/squirephp/squire"
},
"authors": [
{
"name": "Dan Harrin",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"illuminate/support": "^8.0",
"squirephp/airlines": "^2.0",
"squirephp/repository": "^2.0"
},
"autoload": {
"psr-4": {
"Squire\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Squire\\AirlinesEnServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}
4 changes: 2 additions & 2 deletions packages/airlines-en/src/AirlinesEnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class AirlinesEnServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
Repository::registerSource(Airline::class, 'en', __DIR__.'/../resources/data.csv');
Repository::registerSource(Airline::class, 'en', __DIR__ . '/../resources/data.csv');
}
}
76 changes: 39 additions & 37 deletions packages/airlines/composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
{
"name": "squirephp/airlines",
"description": "A library containing Squire's Airline model.",
"keywords": ["squire"],
"license": "MIT",
"homepage": "https://github.com/squirephp",
"support": {
"issues": "https://github.com/squirephp/squire/issues",
"source": "https://github.com/squirephp/squire"
},
"authors": [
{
"name": "Dan Harrin",
"email": "[email protected]"
}
],
"require": {
"php": "^7.2|^8.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
"squirephp/model": "^2.0",
"squirephp/rule": "^2.0"
},
"autoload": {
"psr-4": {
"Squire\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Squire\\AirlinesServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
"name": "squirephp/airlines",
"description": "A library containing Squire's Airline model.",
"keywords": [
"squire"
],
"license": "MIT",
"homepage": "https://github.com/squirephp",
"support": {
"issues": "https://github.com/squirephp/squire/issues",
"source": "https://github.com/squirephp/squire"
},
"authors": [
{
"name": "Dan Harrin",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"illuminate/support": "^8.0",
"squirephp/model": "^2.0",
"squirephp/rule": "^2.0"
},
"autoload": {
"psr-4": {
"Squire\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Squire\\AirlinesServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}
6 changes: 3 additions & 3 deletions packages/airlines/src/AirlinesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class AirlinesServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-airlines');
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-airlines');

$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-airlines'),
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-airlines'),
]);
}
}
7 changes: 4 additions & 3 deletions packages/airlines/src/Models/Airline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Squire\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Squire\Model;

class Airline extends Model
{
public static $schema = [
public static array $schema = [
'id' => 'string',
'alias' => 'string',
'call_sign' => 'string',
Expand All @@ -16,12 +17,12 @@ class Airline extends Model
'name' => 'string',
];

public function country()
public function country(): BelongsTo
{
return $this->belongsTo(Country::class);
}

public function continent()
public function continent(): BelongsTo
{
return $this->hasOneThrough(Continent::class, Country::class);
}
Expand Down
16 changes: 0 additions & 16 deletions packages/airlines/src/Rules/Airline.php

This file was deleted.

Loading

0 comments on commit 78c3671

Please sign in to comment.