Skip to content

Commit

Permalink
Laravel 9 support (#29)
Browse files Browse the repository at this point in the history
* bump packages version

* update github actions workflow

* raise phpstan level to maximum

* first attempt to fix phpstan errors

* move stubs directory

* fix mixed generic types on HasMany relations

* update factories to new format

* do not load factories to testbench

* apply laravel/pint code styles

* update readme
  • Loading branch information
Dartui authored Jun 25, 2022
1 parent 3b8ffaf commit 55b1811
Show file tree
Hide file tree
Showing 50 changed files with 704 additions and 366 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ jobs:
strategy:
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
operating-system:
- ubuntu-latest
- windows-latest
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ Some meta values are collected into helper classes:

## Compatibility list

| Corcel WooCommerce | Laravel | PHP version |
| ----------------------------------------------------- | -------------- | ------------- |
| [1.x](https://github.com/corcel/woocommerce/tree/1.x) | 6.x, 7.x | >= 7.2 |
| 2.x (master) | 6.x, 7.x, 8.x | >= 7.3 \| 8.0 |
| Corcel WooCommerce | Laravel | PHP version | Supported |
| ----------------------------------------------------- | -------------- | ------------- | ------------------ |
| 3.x (master) | 9.x | >= 8.0.3 | :white_check_mark: |
| [2.x](https://github.com/corcel/woocommerce/tree/2.x) | 6.x, 7.x, 8.x | >= 7.3 \| 8.0 | :white_check_mark: |
| [1.x](https://github.com/corcel/woocommerce/tree/1.x) | 6.x, 7.x | >= 7.2 | :x: |

## Installation

Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
}
],
"require": {
"php": "^7.3|^8.0",
"illuminate/database": "^6.0|^7.0|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0",
"jgrossi/corcel": "^3.0|^4.0|^5.0",
"nesbot/carbon": "^2.0"
"php": "^8.0.3",
"illuminate/database": "^9.0",
"illuminate/support": "^9.0",
"jgrossi/corcel": "^6.0",
"nesbot/carbon": "^2.53.1"
},
"require-dev": {
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpstan/phpstan": "^0.12.46",
"orchestra/testbench": "^7.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.4",
"laravel/legacy-factories": "^1.0",
"nunomaduro/larastan": "^0.7.13"
"nunomaduro/larastan": "^2.0",
"laravel/pint": "^0.2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -31,7 +31,8 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"Tests\\": "tests/",
"Database\\Factories\\": "tests/database/factories/"
}
}
}
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ parameters:
- src
- tests

level: 8
level: max

noUnnecessaryCollectionCall: false

stubFiles:
- tests/stubs/Taxonomy.php.stub
- stubs/Corcel.stub

ignoreErrors:
-
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Builder/OrderBuilder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Corcel\WooCommerce\Model\Builder;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function status($status): PostBuilder
];

if (in_array($status, $builtin)) {
$status = 'wc-' . $status;
$status = 'wc-'.$status;
}

return parent::status($status);
Expand Down
30 changes: 25 additions & 5 deletions src/Model/Customer.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,65 @@
<?php

declare(strict_types=1);

namespace Corcel\WooCommerce\Model;

use Corcel\Model\User;
use Corcel\WooCommerce\Traits\AddressesTrait;
use Corcel\WooCommerce\Traits\HasRelationsThroughMeta;
use Database\Factories\CustomerFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property int $order_count
* @property \Illuminate\Database\Eloquent\Collection $orders
* @property int $order_count
* @property Collection $orders
*/
class Customer extends User
{
use HasFactory;
use AddressesTrait;

/**
* @use HasRelationsThroughMeta<\Illuminate\Database\Eloquent\Model>
*/
use HasRelationsThroughMeta;

/**
* @inheritDoc
*
* @var string[]
* @var array<string>
*/
protected $appends = [
'order_count',
];

/**
* Create a new factory instance for the model.
*
* @return CustomerFactory
*/
protected static function newFactory(): CustomerFactory
{
return CustomerFactory::new();
}

/**
* Get order count attribute.
*
* @return int
*/
protected function getOrderCountAttribute(): int
{
return (int) $this->getMeta('_order_count');
$count = $this->getMeta('_order_count');

return is_numeric($count) ? (int) $count : 0;
}

/**
* Get the related orders.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* @return HasMany<\Illuminate\Database\Eloquent\Model>
*/
public function orders(): HasMany
{
Expand Down
60 changes: 43 additions & 17 deletions src/Model/Item.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Corcel\WooCommerce\Model;
Expand All @@ -7,6 +8,8 @@
use Corcel\Concerns\MetaFields;
use Corcel\Model;
use Corcel\WooCommerce\Model\Meta\ItemMeta;
use Database\Factories\ItemFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

Expand All @@ -31,13 +34,14 @@
*/
class Item extends Model
{
use HasFactory;
use Aliases;
use MetaFields;

/**
* The model aliases.
*
* @var string[][]|string[]
* @var array<string, string>|array<string, array<string, string>>
*/
protected static $aliases = [
'id' => 'order_item_id',
Expand All @@ -50,7 +54,7 @@ class Item extends Model
/**
* @inheritDoc
*
* @var string[]
* @var array<string>
*/
protected $appends = [
'quantity',
Expand Down Expand Up @@ -82,70 +86,92 @@ class Item extends Model
*/
public $timestamps = false;

/**
* Create a new factory instance for the model.
*
* @return ItemFactory
*/
protected static function newFactory(): ItemFactory
{
return ItemFactory::new();
}

/**
* Get the line subtotal attribute.
*
* @return string|null
*/
protected function getLineSubtotalAttribute()
protected function getLineSubtotalAttribute(): ?string
{
return $this->getMeta('_line_subtotal');
$lineSubtotal = $this->getMeta('_line_subtotal');

return is_scalar($lineSubtotal) ? (string) $lineSubtotal : null;
}

/**
* Get the line subtotal tax attribute.
*
* @return string|null
*/
protected function getLineSubtotalTaxAttribute()
protected function getLineSubtotalTaxAttribute(): ?string
{
return $this->getMeta('_line_subtotal_tax');
$lineSubtotalTax = $this->getMeta('_line_subtotal_tax');

return is_scalar($lineSubtotalTax) ? (string) $lineSubtotalTax : null;
}

/**
* Get the line tax attribute.
*
* @return string|null
*/
protected function getLineTaxAttribute()
protected function getLineTaxAttribute(): ?string
{
return $this->getMeta('_line_tax');
$lineTax = $this->getMeta('_line_tax');

return is_scalar($lineTax) ? (string) $lineTax : null;
}

/**
* Get the line total attribute.
*
* @return string|null
*/
protected function getLineTotalAttribute()
protected function getLineTotalAttribute(): ?string
{
return $this->getMeta('_line_total');
$lineTotal = $this->getMeta('_line_total');

return is_scalar($lineTotal) ? (string) $lineTotal : null;
}

/**
* Get the quantity attribute.
*
* @return string|null
*/
protected function getQuantityAttribute()
protected function getQuantityAttribute(): ?string
{
return $this->getMeta('_qty');
$quantity = $this->getMeta('_qty');

return is_scalar($quantity) ? (string) $quantity : null;
}

/**
* Get the tax class attribute.
*
* @return string|null
*/
protected function getTaxClassAttribute()
protected function getTaxClassAttribute(): ?string
{
return $this->getMeta('_tax_class');
$taxClass = $this->getMeta('_tax_class');

return is_scalar($taxClass) ? (string) $taxClass : null;
}

/**
* @inheritDoc
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* @return HasMany<ItemMeta>
*/
public function meta(): HasMany
{
Expand All @@ -155,7 +181,7 @@ public function meta(): HasMany
/**
* Get the related order.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
* @return BelongsTo<Order, Item>
*/
public function order(): BelongsTo
{
Expand All @@ -165,7 +191,7 @@ public function order(): BelongsTo
/**
* Get the related product.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
* @return BelongsTo<Product, Item>
*/
public function product(): BelongsTo
{
Expand Down
1 change: 1 addition & 0 deletions src/Model/Meta/ItemMeta.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Corcel\WooCommerce\Model\Meta;
Expand Down
Loading

0 comments on commit 55b1811

Please sign in to comment.