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

Added laravel 11 and php 8.3 support #13

Merged
merged 1 commit into from
Mar 1, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
command: install
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
php_version: 8.1
php_version: 8.3

- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run
Expand All @@ -30,7 +30,7 @@ jobs:
with:
command: install
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
php_version: 8.1
php_version: 8.3

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --extensions=php
61 changes: 44 additions & 17 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,48 @@ jobs:
strategy:
matrix:
include:
# Laravel 10.*
- php: 8.1
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.2
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.1
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'
- php: 8.2
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'
# Laravel 10.*
- php: 8.1
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.2
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.3
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.1
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'
- php: 8.2
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'
- php: 8.3
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'
# Laravel 11.*
- php: 8.2
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-stable'
- php: 8.3
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-stable'
- php: 8.2
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-lowest'
- php: 8.2
laravel: 11.*
testbench: 9.*
composer-flag: '--prefer-lowest'

runs-on: ubuntu-latest

Expand All @@ -48,3 +73,5 @@ jobs:

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"require": {
"php": ">=8.1",
"composer/composer": "^2",
"illuminate/console": "^10",
"illuminate/database": "^10",
"illuminate/support": "^10"
"illuminate/console": "^10|^11",
"illuminate/database": "^10|^11",
"illuminate/support": "^10|^11"
},
"require-dev": {
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^10.0",
"friendsofphp/php-cs-fixer": "^3",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^8|^9",
"phpunit/phpunit": "^10",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
Expand All @@ -37,7 +38,10 @@
"test": "vendor/bin/phpunit",
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-html coverage",
"fix": "./vendor/bin/php-cs-fixer fix",
"lint": "./vendor/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php"
"lint": "./vendor/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php",
"analyse": [
"@php ./vendor/bin/phpstan analyse --memory-limit=2G"
]
},
"extra": {
"laravel": {
Expand All @@ -48,5 +52,7 @@
},
"config": {
"sort-packages": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-cli
FROM php:8.3-cli

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- ./vendor/larastan/larastan/extension.neon

parameters:

paths:
- src
- tests

# Level 9 is the highest level
level: 9
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ php artisan vendor:publish --tag=computed-attributes-config

This package is tested for the following Laravel and PHP versions:

- 10.* (PHP 8.1, 8.2)
- 10.* (PHP 8.1, 8.2, 8.3)
- 11.* (PHP 8.2, 8.3)

## Usage examples

Expand Down
10 changes: 3 additions & 7 deletions src/ComputedAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait ComputedAttributes
* @param string $attributeName
* @return mixed
*/
public function getComputedAttributeValue(string $attributeName)
public function getComputedAttributeValue(string $attributeName): mixed
{
$functionName = 'get' . Str::studly($attributeName) . 'Computed';

Expand Down Expand Up @@ -66,14 +66,10 @@ public function scopeComputedAttributesValidate(Builder $builder, array $attribu
* Return the configuration array for this model.
* If the configuration array does not exist the function will return an empty array.
*
* @return array
* @return array<int, string>
*/
public function getComputedAttributeConfiguration(): array
{
if (isset($this->computed)) {
return $this->computed;
} else {
return [];
}
return $this->computed ?? [];
}
}
3 changes: 1 addition & 2 deletions src/Console/GenerateComputedAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Korridor\LaravelComputedAttributes\Console;

use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Korridor\LaravelComputedAttributes\ComputedAttributes;
Expand Down Expand Up @@ -99,7 +98,7 @@ public function handle(): int
// Calculate
foreach ($modelAttributesEntries as $modelAttributesEntry) {
$model = $modelAttributesEntry->getModel();
/** @var Builder|ComputedAttributes $modelInstance */
/** @var Model|ComputedAttributes $modelInstance */
$modelInstance = new $model();
$attributes = $modelAttributesEntry->getAttributes();

Expand Down
9 changes: 1 addition & 8 deletions src/Parser/ModelAttributeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@

class ModelAttributeParser
{
/**
* ModelAttributeParser constructor.
*/
public function __construct()
{
}

/**
* @return string
*/
Expand Down Expand Up @@ -53,7 +46,7 @@ public function getAllModelClasses(): array
$traits = $reflection->getTraitNames();
foreach ($traits as $trait) {
if ('Korridor\\LaravelComputedAttributes\\ComputedAttributes' === $trait) {
array_push($models, $class);
$models[] = $class;
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/Parser/ModelAttributesEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@

namespace Korridor\LaravelComputedAttributes\Parser;

use Illuminate\Database\Eloquent\Model;
use Korridor\LaravelComputedAttributes\ComputedAttributes;

class ModelAttributesEntry
{
/**
* @var string
* @var class-string<Model>
*/
private $model;
private string $model;

/**
* @var string[]
* @var array<int, string>
*/
private $attributes;
private array $attributes;

/**
* ModelAttributesEntry constructor.
*
* @param string $model
* @param string[] $attributes
* @param class-string<Model> $model
* @param array<int, string> $attributes
*/
public function __construct(string $model, array $attributes)
{
Expand All @@ -29,15 +32,15 @@ public function __construct(string $model, array $attributes)
}

/**
* @return string
* @return class-string<Model|ComputedAttributes>
*/
public function getModel(): string
{
return $this->model;
}

/**
* @return array
* @return array<int, string>
*/
public function getAttributes(): array
{
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/GenerateComputedAttributesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Korridor\LaravelComputedAttributes\Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Korridor\LaravelComputedAttributes\Tests\TestCase;
Expand All @@ -15,8 +14,6 @@

class GenerateComputedAttributesCommandTest extends TestCase
{
use RefreshDatabase;

public function testCommandComputesAttributesForAllModelsWithTraitAndAllThereAttributes(): void
{
// Arrange
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/ValidateComputedAttributesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

namespace Korridor\LaravelComputedAttributes\Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Korridor\LaravelComputedAttributes\Tests\TestCase;
use Korridor\LaravelComputedAttributes\Tests\TestEnvironment\Models\Post;
use Korridor\LaravelComputedAttributes\Tests\TestEnvironment\Models\Vote;

class ValidateComputedAttributesCommandTest extends TestCase
{
use RefreshDatabase;

public function testCommandComputesAttributesForAllModelsWithTraitAndAllThereAttributes(): void
{
// Arrange
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getEnvironmentSetUp($app): void

/**
* @param Application $app
* @return array
* @return array<int, class-string>
*/
protected function getPackageProviders($app): array
{
Expand Down
Loading