Skip to content

Commit 8dee933

Browse files
authored
Merge pull request #41 from tonysm/laravel-12
Laravel 12
2 parents 94aa1f7 + 960f35f commit 8dee933

17 files changed

+108
-111
lines changed

.github/workflows/php-cs-fixer.yml .github/workflows/linting.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ jobs:
1313
ref: ${{ github.head_ref }}
1414

1515
- name: Run PHP CS Fixer
16-
uses: docker://oskarstark/php-cs-fixer-ga
17-
with:
18-
args: --config=.php_cs.dist.php --allow-risky=yes
16+
uses: aglipanci/[email protected]
1917

2018
- name: Commit changes
2119
uses: stefanzweifel/git-auto-commit-action@v5

.github/workflows/run-tests.yml

+7-16
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,24 @@ on:
55
branches:
66
- main
77
pull_request:
8-
branches:
9-
- main
108

119
jobs:
1210
test:
13-
runs-on: ${{ matrix.os }}
11+
runs-on: ubuntu-latest
1412

1513
strategy:
1614
fail-fast: true
1715
matrix:
18-
# os: [ubuntu-latest, windows-latest]
19-
os: [ubuntu-latest]
20-
php: [8.1, 8.2]
21-
laravel: [10.*, 11.*]
16+
php: [8.2, 8.3, 8.4]
17+
laravel: [11.*, 12.*]
2218
stability: [prefer-lowest, prefer-stable]
2319
include:
24-
- laravel: 10.*
25-
testbench: 8.*
26-
collision: ^6.0
2720
- laravel: 11.*
2821
testbench: ^9.0
29-
collision: ^8.1
30-
exclude:
31-
- laravel: 11.*
32-
php: 8.1
22+
- laravel: 12.*
23+
testbench: ^10.0
3324

34-
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
25+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
3526

3627
steps:
3728
- name: Checkout code
@@ -51,7 +42,7 @@ jobs:
5142
5243
- name: Install dependencies
5344
run: |
54-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nunomaduro/collision:${{ matrix.collision }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update
45+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
5546
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
5647
5748
- name: Execute tests

composer.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.1",
18+
"php": "^8.2",
1919
"spatie/laravel-package-tools": "^1.16",
20-
"illuminate/contracts": "^10.0|^11.0"
20+
"illuminate/contracts": "^11.0|^12.0"
2121
},
2222
"require-dev": {
23-
"nunomaduro/collision": "^6.0|^8.1",
24-
"orchestra/testbench": "^8.0|^9.0",
25-
"phpunit/phpunit": "^10.5"
23+
"orchestra/testbench": "^9.0|^10.0",
24+
"phpunit/phpunit": "^10.5|^11.0"
2625
},
2726
"autoload": {
2827
"psr-4": {

rector.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\ValueObject\PhpVersion;
7+
8+
return RectorConfig::configure()
9+
->withPaths([
10+
__DIR__.'/src',
11+
__DIR__.'/tests',
12+
])
13+
->withPreparedSets(
14+
deadCode: true,
15+
codeQuality: true,
16+
typeDeclarations: true,
17+
privatization: true,
18+
earlyReturn: true,
19+
)
20+
->withAttributesSets()
21+
->withPhpSets()
22+
->withPhpVersion(PhpVersion::PHP_82);

src/Actions/AppendTailwindTag.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
class AppendTailwindTag
66
{
7-
public function __invoke(string $contents)
7+
public function __invoke(string $contents): ?string
88
{
99
if (str_contains($contents, '{{ tailwindcss(')) {
1010
return $contents;
1111
}
1212

1313
return preg_replace(
1414
'/(\s*)(<\/head>)/',
15-
PHP_EOL."\\1 <!-- TailwindCSS Styles -->".
15+
PHP_EOL.'\\1 <!-- TailwindCSS Styles -->'.
1616
"\\1 <link rel=\"stylesheet\" href=\"{{ tailwindcss('css/app.css') }}\" />\\1\\2",
1717
$contents,
1818
);

src/Commands/BuildCommand.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BuildCommand extends Command
2020

2121
protected $description = 'Generates a new build of Tailwind CSS for your project.';
2222

23-
public function handle()
23+
public function handle(): int
2424
{
2525
$binFile = config('tailwindcss.bin_path');
2626

@@ -35,7 +35,7 @@ public function handle()
3535
$sourcePath = $this->fixFilePathForOs(config('tailwindcss.build.source_file_path'));
3636
$sourceRelativePath = str_replace(rtrim(resource_path(), DIRECTORY_SEPARATOR), '', $sourcePath);
3737
$destinationPath = $this->fixFilePathForOs(config('tailwindcss.build.destination_path'));
38-
$destinationFileAbsolutePath = $destinationPath . DIRECTORY_SEPARATOR . trim($sourceRelativePath, DIRECTORY_SEPARATOR);
38+
$destinationFileAbsolutePath = $destinationPath.DIRECTORY_SEPARATOR.trim($sourceRelativePath, DIRECTORY_SEPARATOR);
3939
$destinationFileRelativePath = str_replace(rtrim(public_path(), DIRECTORY_SEPARATOR), '', $destinationFileAbsolutePath);
4040

4141
File::ensureDirectoryExists(dirname($destinationFileAbsolutePath));
@@ -57,7 +57,7 @@ public function handle()
5757
'-o', $destinationFileAbsolutePath,
5858
$this->option('watch') ? '--watch=always' : null,
5959
$this->shouldMinify() ? '-m' : null,
60-
]), function ($type, $output) {
60+
]), function ($type, $output): void {
6161
$this->output->write($output);
6262
});
6363

@@ -106,11 +106,19 @@ private function fixOsFilePathToUriPath(string $path): string
106106

107107
private function shouldVersion(): bool
108108
{
109-
return $this->option('digest') || $this->option('prod');
109+
if ($this->option('digest')) {
110+
return true;
111+
}
112+
113+
return (bool) $this->option('prod');
110114
}
111115

112116
private function shouldMinify(): bool
113117
{
114-
return $this->option('minify') || $this->option('prod');
118+
if ($this->option('minify')) {
119+
return true;
120+
}
121+
122+
return (bool) $this->option('prod');
115123
}
116124
}

src/Commands/DownloadCommand.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DownloadCommand extends Command
1616

1717
protected $description = 'Downloads the Tailwind CSS binary for the version specified in your config/tailwindcss.php.';
1818

19-
public function handle()
19+
public function handle(): int
2020
{
2121
$os = php_uname('s');
2222
$cpu = php_uname('m');
@@ -57,8 +57,10 @@ public function handle()
5757
return self::FAILURE;
5858
}
5959

60-
File::ensureDirectoryExists(dirname($targetPath));
61-
File::exists($targetPath) && File::delete($targetPath);
60+
File::ensureDirectoryExists(dirname((string) $targetPath));
61+
if (File::exists($targetPath)) {
62+
File::delete($targetPath);
63+
}
6264
File::put($targetPath, $contents);
6365
File::chmod($targetPath, 0755);
6466

src/Commands/InstallCommand.php

+25-40
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,43 @@ class InstallCommand extends Command
2020

2121
protected $description = 'Installs the Tailwind CSS scaffolding for new Laravel applications.';
2222

23-
public function handle()
23+
public function handle(): int
2424
{
2525
$this->ensureTailwindConfigExists();
2626
$this->ensureTailwindCliBinaryExists();
2727
$this->appendTailwindStylesToLayouts();
2828
$this->installMiddleware('\Tonysm\TailwindCss\Http\Middleware\AddLinkHeaderForPreloadedAssets::class');
2929
$this->addIngoreLines();
3030
$this->runFirstBuild();
31-
$this->removeUnusedFiles();
3231

3332
$this->newLine();
3433

35-
$this->components->info('TailwindCSS Laravel was installed successfully.');
34+
$this->components->info('Tailwind CSS Laravel was installed successfully.');
3635

3736
return self::SUCCESS;
3837
}
3938

40-
protected function phpBinary()
39+
protected function phpBinary(): string
4140
{
42-
return (new PhpExecutableFinder())->find(false) ?: 'php';
41+
return (new PhpExecutableFinder)->find(false) ?: 'php';
4342
}
4443

45-
private function ensureTailwindConfigExists()
44+
private function ensureTailwindConfigExists(): void
4645
{
4746
$this->copyStubToApp(
48-
stub: __DIR__ . '/../../stubs/postcss.config.js',
47+
stub: __DIR__.'/../../stubs/postcss.config.js',
4948
to: base_path('postcss.config.js'),
5049
);
5150

52-
if (! File::exists($appCssFilePath = resource_path('css/app.css')) || empty(trim(File::get($appCssFilePath))) || $this->mainCssIsDefault($appCssFilePath)) {
51+
if (! File::exists($appCssFilePath = resource_path('css/app.css')) || in_array(trim(File::get($appCssFilePath)), ['', '0'], true) || $this->mainCssIsDefault($appCssFilePath)) {
5352
$this->copyStubToApp(
54-
stub: __DIR__ . '/../../stubs/resources/css/app.css',
53+
stub: __DIR__.'/../../stubs/resources/css/app.css',
5554
to: $appCssFilePath,
5655
);
5756
}
5857
}
5958

60-
private function ensureTailwindCliBinaryExists()
59+
private function ensureTailwindCliBinaryExists(): void
6160
{
6261
if (! File::exists(config('tailwindcss.bin_path')) || $this->option('download')) {
6362
Process::forever()->tty(SymfonyProcess::isTtySupported())->run([
@@ -66,7 +65,7 @@ private function ensureTailwindCliBinaryExists()
6665
'tailwindcss:download',
6766
'--cli-version',
6867
$this->option('cli-version') ?: config('tailwindcss.version'),
69-
], function ($_type, $output) {
68+
], function ($_type, $output): void {
7069
$this->output->write($output);
7170
});
7271
}
@@ -81,12 +80,9 @@ private function copyStubToApp(string $stub, string $to): void
8180
/**
8281
* Install the middleware to a group in the application Http Kernel.
8382
*
84-
* @param string $after
85-
* @param string $name
8683
* @param string $group
87-
* @return void
8884
*/
89-
private function installMiddlewareAfter($after, $name, $group = 'web')
85+
private function installMiddlewareAfter(string $after, string $name, $group = 'web'): void
9086
{
9187
$httpKernel = file_get_contents(app_path('Http/Kernel.php'));
9288

@@ -98,8 +94,8 @@ private function installMiddlewareAfter($after, $name, $group = 'web')
9894
}
9995

10096
$modifiedMiddlewareGroup = str_replace(
101-
$after . ',',
102-
$after . ',' . PHP_EOL . ' ' . $name . ',',
97+
$after.',',
98+
$after.','.PHP_EOL.' '.$name.',',
10399
$middlewareGroup,
104100
);
105101

@@ -110,12 +106,12 @@ private function installMiddlewareAfter($after, $name, $group = 'web')
110106
));
111107
}
112108

113-
private function appendTailwindStylesToLayouts()
109+
private function appendTailwindStylesToLayouts(): void
114110
{
115111
$this->existingLayoutFiles()
116112
->each(fn ($file) => File::put(
117113
$file,
118-
(new AppendTailwindTag())(File::get($file)),
114+
(new AppendTailwindTag)(File::get($file)),
119115
));
120116
}
121117

@@ -126,7 +122,7 @@ private function existingLayoutFiles()
126122
->filter(fn ($file) => File::exists($file));
127123
}
128124

129-
private function installMiddleware(string $middleware)
125+
private function installMiddleware(string $middleware): void
130126
{
131127
if (file_exists(app_path('Http/Kernel.php'))) {
132128
$this->installMiddlewareAfter('SubstituteBindings::class', $middleware);
@@ -135,7 +131,7 @@ private function installMiddleware(string $middleware)
135131
}
136132
}
137133

138-
private function installMiddlewareToBootstrap(string $middleware, string $group = 'web', string $modifier = 'append')
134+
private function installMiddlewareToBootstrap(string $middleware, string $group = 'web', string $modifier = 'append'): void
139135
{
140136
$bootstrapApp = file_get_contents(base_path('bootstrap/app.php'));
141137

@@ -146,19 +142,19 @@ private function installMiddlewareToBootstrap(string $middleware, string $group
146142
$bootstrapApp = str_replace(
147143
'->withMiddleware(function (Middleware $middleware) {',
148144
'->withMiddleware(function (Middleware $middleware) {'
149-
. PHP_EOL . " \$middleware->{$group}({$modifier}: ["
150-
. PHP_EOL . " {$middleware},"
151-
. PHP_EOL . ' ]);'
152-
. PHP_EOL,
145+
.PHP_EOL." \$middleware->{$group}({$modifier}: ["
146+
.PHP_EOL." {$middleware},"
147+
.PHP_EOL.' ]);'
148+
.PHP_EOL,
153149
$bootstrapApp,
154150
);
155151

156152
file_put_contents(base_path('bootstrap/app.php'), $bootstrapApp);
157153
}
158154

159-
private function addIngoreLines()
155+
private function addIngoreLines(): void
160156
{
161-
$binary = basename(config('tailwindcss.bin_path'));
157+
$binary = basename((string) config('tailwindcss.bin_path'));
162158

163159
if (str_contains(File::get(base_path('.gitignore')), $binary)) {
164160
return;
@@ -173,28 +169,17 @@ private function addIngoreLines()
173169
LINES);
174170
}
175171

176-
private function runFirstBuild()
172+
private function runFirstBuild(): void
177173
{
178174
Process::forever()->tty(SymfonyProcess::isTtySupported())->run([
179175
$this->phpBinary(),
180176
'artisan',
181177
'tailwindcss:build',
182-
], function ($_type, $output) {
178+
], function ($_type, $output): void {
183179
$this->output->write($output);
184180
});
185181
}
186182

187-
private function removeUnusedFiles()
188-
{
189-
$files = [
190-
base_path('tailwind.config.js'),
191-
];
192-
193-
foreach ($files as $file) {
194-
File::exists($file) && File::delete($file);
195-
}
196-
}
197-
198183
private function mainCssIsDefault($appCssFilePath): bool
199184
{
200185
return trim(File::get($appCssFilePath)) === trim(<<<'CSS'

src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66

77
class AddLinkHeaderForPreloadedAssets
88
{
9-
public function __construct(private Manifest $manifest)
10-
{
11-
}
9+
public function __construct(private readonly Manifest $manifest) {}
1210

1311
public function handle($request, $next)
1412
{
15-
return tap($next($request), function ($response) {
16-
if (count($assets = $this->manifest->assetsForPreloading()) > 0) {
13+
return tap($next($request), function ($response): void {
14+
if (($assets = $this->manifest->assetsForPreloading()) !== []) {
1715
$response->header('Link', trim(implode(', ', array_filter(array_merge(
1816
[$response->headers->get('Link', null)],
19-
collect($assets)->map(fn ($attributes, $asset) => implode('; ', array_merge(
17+
collect($assets)->map(fn ($attributes, $asset): string => implode('; ', array_merge(
2018
["<$asset>"],
2119
collect(array_merge(['rel' => 'preload', 'as' => 'style'], $attributes))
22-
->map(fn ($value, $key) => "{$key}={$value}")
20+
->map(fn ($value, $key): string => "{$key}={$value}")
2321
->all(),
2422
)))->all(),
2523
)))));

0 commit comments

Comments
 (0)