Skip to content

feat: Laravel 12, pint and rector #33

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

Merged
merged 5 commits into from
Feb 26, 2025
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
9 changes: 6 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: "Continuous Integration"

on:
push:
branches:
- master
- 11.x
pull_request:
schedule:
- cron: '0 0 * * *'
Expand All @@ -14,14 +17,14 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -39,7 +42,7 @@ jobs:
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit
12 changes: 10 additions & 2 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ on:
jobs:
phplint:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: "laravel-pint"
uses: aglipanci/laravel-pint-action@2.0.0
uses: aglipanci/laravel-pint-action@latest
with:
preset: laravel
verboseMode: true

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "fix: pint"

27 changes: 15 additions & 12 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,33 @@ on:

jobs:
static-analysis-phpstan:

name: "Static Analysis with PHPStan"
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
stability: [prefer-stable]

steps:
- name: "Checkout code"
uses: "actions/checkout@v4"
- name: Checkout code
uses: actions/checkout@v4

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: "cs2pr"
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute type checking
run: vendor/bin/phpstan --configuration="phpstan.neon.dist"
- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan --error-format=table"
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

21 changes: 4 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@

## Changelog

### v11.0.0 - 2024-03-14
### v12.0.0 - 2025-02-26

- Add support for Laravel 11

### v10.0.0 - 2023-02-07

- Add support for Laravel 10

### v9.1.0 - 2022-06-20

- Update league/fractal to latest version #30

### v9.0.0 - 2022-05-07

- Add support for Laravel 9
- Fix https://github.com/yajra/laravel-datatables-fractal/issues/27
- Add phpstan static analysis
- Bump major version to match with the framework
- Add support for Laravel 12
- Add Laravel Pint
- Add Rector
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Laravel DataTables Fractal Plugin

[![Laravel 11.x](https://img.shields.io/badge/Laravel-11.x-orange.svg)](http://laravel.com)
[![Laravel 12.x](https://img.shields.io/badge/Laravel-12.x-orange.svg)](http://laravel.com)
[![Latest Stable Version](https://img.shields.io/packagist/v/yajra/laravel-datatables-fractal.svg)](https://packagist.org/packages/yajra/laravel-datatables-fractal)
[![Build Status](https://travis-ci.org/yajra/laravel-datatables-fractal.svg?branch=master)](https://travis-ci.org/yajra/laravel-datatables-fractal)
[![Continuous Integration](https://github.com/yajra/laravel-datatables-fractal/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/yajra/laravel-datatables-fractal/actions/workflows/continuous-integration.yml)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yajra/laravel-datatables-fractal/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yajra/laravel-datatables-fractal/?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/yajra/laravel-datatables-fractal.svg)](https://packagist.org/packages/yajra/laravel-datatables-fractal)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://packagist.org/packages/yajra/laravel-datatables-fractal)
Expand All @@ -12,7 +12,7 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave
## Requirements

- [PHP >= 8.2](http://php.net/)
- [Laravel 11.x](https://github.com/laravel/framework)
- [Laravel 12.x](https://github.com/laravel/framework)
- [Laravel DataTables](https://github.com/yajra/laravel-datatables)

## Documentations
Expand All @@ -27,10 +27,11 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave
| 9.x | 9.x |
| 10.x | 10.x |
| 11.x | 11.x |
| 12.x | 12.x |

## Quick Installation

`composer require yajra/laravel-datatables-fractal:^11.0`
`composer require yajra/laravel-datatables-fractal:^12.0`

### Register Service Provider (Optional on Laravel 5.5+)

Expand Down
104 changes: 59 additions & 45 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,62 @@
{
"name": "yajra/laravel-datatables-fractal",
"description": "Laravel DataTables Fractal Plugin.",
"keywords": [
"laravel",
"datatables",
"fractal",
"api"
],
"license": "MIT",
"authors": [
{
"name": "Arjay Angeles",
"email": "[email protected]"
}
],
"require": {
"php": "^8.2",
"yajra/laravel-datatables-oracle": "^11.0",
"league/fractal": "^0.20.1"
},
"require-dev": {
"nunomaduro/larastan": "^2.9.2",
"orchestra/testbench": "^9"
},
"autoload": {
"psr-4": {
"Yajra\\DataTables\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Yajra\\DataTables\\Fractal\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "11.x-dev"
"name": "yajra/laravel-datatables-fractal",
"description": "Laravel DataTables Fractal Plugin.",
"keywords": [
"laravel",
"datatables",
"fractal",
"api"
],
"license": "MIT",
"authors": [
{
"name": "Arjay Angeles",
"email": "[email protected]"
}
],
"require": {
"php": "^8.2",
"yajra/laravel-datatables-oracle": "^12",
"league/fractal": "^0.20.1"
},
"laravel": {
"providers": [
"Yajra\\DataTables\\FractalServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
"require-dev": {
"larastan/larastan": "^3.1",
"orchestra/testbench": "^10",
"laravel/pint": "^1.21",
"rector/rector": "^2.0"
},
"autoload": {
"psr-4": {
"Yajra\\DataTables\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Yajra\\DataTables\\Fractal\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "12.x-dev"
},
"laravel": {
"providers": [
"Yajra\\DataTables\\FractalServiceProvider"
]
}
},
"scripts": {
"test": "./vendor/bin/phpunit",
"pint": "./vendor/bin/pint",
"rector": "./vendor/bin/rector",
"stan": "./vendor/bin/phpstan analyse --memory-limit=2G --ansi --no-progress --no-interaction --configuration=phpstan.neon.dist",
"pr": [
"@pint",
"@rector",
"@stan",
"@test"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
8 changes: 2 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon

parameters:

Expand All @@ -9,11 +9,7 @@ parameters:
level: 5

ignoreErrors:
- '#Access to an undefined property Yajra\\DataTables\\FractalServiceProvider::\$transformer.#'
- '#Access to an undefined property Yajra\\DataTables\\FractalServiceProvider::\$serializer.#'
- identifier: function.alreadyNarrowedType

excludePaths:

checkMissingIterableValueType: false

checkGenericClassInNonGenericObjectType: false
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/config',
__DIR__.'/src',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
]);
};
4 changes: 1 addition & 3 deletions src/FractalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public function register(): void
return $fractal;
});

$this->app->singleton('datatables.transformer', function () {
return new FractalTransformer($this->app->make('datatables.fractal'));
});
$this->app->singleton('datatables.transformer', fn () => new FractalTransformer($this->app->make('datatables.fractal')));

$this->commands([
TransformerMakeCommand::class,
Expand Down
11 changes: 3 additions & 8 deletions src/Transformers/FractalTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@

class FractalTransformer
{
protected Manager $fractal;

/**
* FractalTransformer constructor.
*/
public function __construct(Manager $fractal)
{
$this->fractal = $fractal;
}
public function __construct(protected Manager $fractal) {}

/**
* Transform output using the given transformer and serializer.
Expand Down Expand Up @@ -65,7 +60,7 @@ protected function createSerializer(SerializerAbstract|string $serializer): Seri
return $serializer;
}

return new $serializer();
return new $serializer;
}

/**
Expand All @@ -79,6 +74,6 @@ protected function createTransformer(Closure|string|TransformerAbstract $transfo
return $transformer;
}

return new $transformer();
return new $transformer;
}
}