Skip to content

Commit 627e829

Browse files
committed
build: replaced php-cs-fixer with Laravel Pint
1 parent b45b75e commit 627e829

21 files changed

+161
-174
lines changed

.php-cs-fixer.dist.php

-32
This file was deleted.

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"spatie/image": "^3.0"
2222
},
2323
"require-dev": {
24-
"friendsofphp/php-cs-fixer": "^3.9",
24+
"laravel/pint": "^1.15",
2525
"orchestra/testbench": "^8.0 || ^9.0",
2626
"php-parallel-lint/php-parallel-lint": "^1.3"
2727
},
@@ -44,7 +44,7 @@
4444
"parallel-lint --exclude .git --exclude vendor ."
4545
],
4646
"format": [
47-
"php-cs-fixer fix"
47+
"pint"
4848
]
4949
},
5050
"scripts-descriptions": {

pint.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"php_unit_method_casing": {
5+
"case": "camel_case"
6+
},
7+
"php_unit_test_annotation": {
8+
"style": "prefix"
9+
},
10+
"no_superfluous_phpdoc_tags": true,
11+
"declare_strict_types": true,
12+
"strict_param": true
13+
}
14+
}

routes/api.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use Illuminate\Support\Facades\Route;
6-
75
use Advoor\NovaEditorJs\Http\Controllers\EditorJsImageUploadController;
86
use Advoor\NovaEditorJs\Http\Controllers\EditorJsLinkController;
7+
use Illuminate\Support\Facades\Route;
98

10-
Route::post('upload/file', EditorJsImageUploadController::class . '@file')->name('editor-js-upload-image-by-file');
11-
Route::post('upload/url', EditorJsImageUploadController::class . '@url')->name('editor-js-upload-image-by-url');
12-
Route::get('fetch/url', EditorJsLinkController::class . '@fetch')->name('editor-js-fetch-url');
9+
Route::post('upload/file', EditorJsImageUploadController::class.'@file')->name('editor-js-upload-image-by-file');
10+
Route::post('upload/url', EditorJsImageUploadController::class.'@url')->name('editor-js-upload-image-by-url');
11+
Route::get('fetch/url', EditorJsLinkController::class.'@fetch')->name('editor-js-fetch-url');

src/FieldServiceProvider.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace Advoor\NovaEditorJs;
66

77
use Illuminate\Contracts\Config\Repository as ConfigRepository;
8-
use Laravel\Nova\Nova;
9-
use Laravel\Nova\Events\ServingNova;
10-
use Illuminate\Support\ServiceProvider;
118
use Illuminate\Support\Facades\Route;
9+
use Illuminate\Support\ServiceProvider;
10+
use Laravel\Nova\Events\ServingNova;
11+
use Laravel\Nova\Nova;
1212

1313
/**
1414
* @property-read \Illuminate\Foundation\Application $app
@@ -27,21 +27,21 @@ public function boot()
2727
});
2828

2929
$this->publishes([
30-
__DIR__ . '/config/nova-editor-js.php' => base_path('config/nova-editor-js.php'),
30+
__DIR__.'/config/nova-editor-js.php' => base_path('config/nova-editor-js.php'),
3131
], 'editorjs-config');
3232

3333
$this->publishes([
34-
__DIR__ . '/../resources/views' => resource_path('views/vendor/nova-editor-js'),
34+
__DIR__.'/../resources/views' => resource_path('views/vendor/nova-editor-js'),
3535
], 'views');
3636

37-
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'nova-editor-js');
37+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'nova-editor-js');
3838

3939
Nova::serving(function (ServingNova $event) {
40-
Nova::script('nova-editor-js', __DIR__ . '/../dist/js/field.js');
41-
Nova::style('nova-editor-js', __DIR__ . '/../dist/css/field.css');
40+
Nova::script('nova-editor-js', __DIR__.'/../dist/js/field.js');
41+
Nova::style('nova-editor-js', __DIR__.'/../dist/css/field.css');
4242
});
4343

44-
if (!$this->app->configurationIsCached() && !$this->app->isProduction()) {
44+
if (! $this->app->configurationIsCached() && ! $this->app->isProduction()) {
4545
$this->checkForConfigDeprecations();
4646
}
4747
}
@@ -59,7 +59,7 @@ protected function routes()
5959

6060
Route::middleware(['nova'])
6161
->prefix('nova-vendor/editor-js-field')
62-
->group(__DIR__ . '/../routes/api.php');
62+
->group(__DIR__.'/../routes/api.php');
6363
}
6464

6565
/**
@@ -76,7 +76,6 @@ public function register()
7676

7777
/**
7878
* Check for deprecated config keys.
79-
*
8079
*/
8180
protected function checkForConfigDeprecations(): void
8281
{

src/Http/Controllers/EditorJsImageUploadController.php

+26-29
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function file(Request $request): JsonResponse
7171
'success' => 1,
7272
'file' => [
7373
'url' => Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($path),
74-
'thumbnails' => $thumbnails
75-
]
74+
'thumbnails' => $thumbnails,
75+
],
7676
]);
7777
}
7878

@@ -96,35 +96,35 @@ public function url(Request $request): JsonResponse
9696
// Fetch URL
9797
try {
9898
$response = Http::timeout(5)->get($url)->throw();
99-
} catch (ConnectionException | RequestException) {
99+
} catch (ConnectionException|RequestException) {
100100
return response()->json([
101101
'success' => 0,
102102
]);
103103
}
104104

105105
// Validate mime type
106106
$mime = (new finfo())->buffer($response->body(), FILEINFO_MIME_TYPE);
107-
if (!in_array($mime, self::VALID_IMAGE_MIMES, true)) {
107+
if (! in_array($mime, self::VALID_IMAGE_MIMES, true)) {
108108
return response()->json([
109109
'success' => 0,
110110
]);
111111
}
112112

113113
$urlBasename = basename(parse_url(url($url), PHP_URL_PATH));
114-
$nameWithPath = config('nova-editor-js.toolSettings.image.path') . '/' . uniqid() . $urlBasename;
114+
$nameWithPath = config('nova-editor-js.toolSettings.image.path').'/'.uniqid().$urlBasename;
115115
Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->put($nameWithPath, $response->body());
116116
event(new EditorJsImageUploaded(config('nova-editor-js.toolSettings.image.disk'), $nameWithPath));
117117

118118
return response()->json([
119119
'success' => 1,
120120
'file' => [
121-
'url' => Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($nameWithPath)
122-
]
121+
'url' => Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($nameWithPath),
122+
],
123123
]);
124124
}
125125

126126
/**
127-
* @param array $alterations
127+
* @param array $alterations
128128
*/
129129
private function applyAlterations($path, $alterations = [])
130130
{
@@ -133,54 +133,54 @@ private function applyAlterations($path, $alterations = [])
133133

134134
$imageSettings = config('nova-editor-js.toolSettings.image.alterations');
135135

136-
if (!empty($alterations)) {
136+
if (! empty($alterations)) {
137137
$imageSettings = $alterations;
138138
}
139139

140140
if (empty($imageSettings)) {
141141
return;
142142
}
143143

144-
if (!empty($imageSettings['resize']['width'])) {
144+
if (! empty($imageSettings['resize']['width'])) {
145145
$image->width($imageSettings['resize']['width']);
146146
}
147147

148-
if (!empty($imageSettings['resize']['height'])) {
148+
if (! empty($imageSettings['resize']['height'])) {
149149
$image->height($imageSettings['resize']['height']);
150150
}
151151

152-
if (!empty($imageSettings['optimize'])) {
152+
if (! empty($imageSettings['optimize'])) {
153153
$image->optimize();
154154
}
155155

156-
if (!empty($imageSettings['adjustments']['brightness'])) {
156+
if (! empty($imageSettings['adjustments']['brightness'])) {
157157
$image->brightness($imageSettings['adjustments']['brightness']);
158158
}
159159

160-
if (!empty($imageSettings['adjustments']['contrast'])) {
160+
if (! empty($imageSettings['adjustments']['contrast'])) {
161161
$image->contrast($imageSettings['adjustments']['contrast']);
162162
}
163163

164-
if (!empty($imageSettings['adjustments']['gamma'])) {
164+
if (! empty($imageSettings['adjustments']['gamma'])) {
165165
$image->gamma($imageSettings['adjustments']['gamma']);
166166
}
167167

168-
if (!empty($imageSettings['effects']['blur'])) {
168+
if (! empty($imageSettings['effects']['blur'])) {
169169
$image->blur($imageSettings['effects']['blur']);
170170
}
171171

172-
if (!empty($imageSettings['effects']['pixelate'])) {
172+
if (! empty($imageSettings['effects']['pixelate'])) {
173173
$image->pixelate($imageSettings['effects']['pixelate']);
174174
}
175175

176-
if (!empty($imageSettings['effects']['greyscale'])) {
176+
if (! empty($imageSettings['effects']['greyscale'])) {
177177
$image->greyscale();
178178
}
179-
if (!empty($imageSettings['effects']['sepia'])) {
179+
if (! empty($imageSettings['effects']['sepia'])) {
180180
$image->sepia();
181181
}
182182

183-
if (!empty($imageSettings['effects']['sharpen'])) {
183+
if (! empty($imageSettings['effects']['sharpen'])) {
184184
$image->sharpen($imageSettings['effects']['sharpen']);
185185
}
186186

@@ -199,13 +199,13 @@ private function applyThumbnails($path)
199199

200200
$generatedThumbnails = [];
201201

202-
if (!empty($thumbnailSettings)) {
202+
if (! empty($thumbnailSettings)) {
203203
foreach ($thumbnailSettings as $thumbnailName => $setting) {
204204
$filename = pathinfo($path, PATHINFO_FILENAME);
205205
$extension = pathinfo($path, PATHINFO_EXTENSION);
206206

207-
$newThumbnailName = $filename . $thumbnailName . '.' . $extension;
208-
$newThumbnailPath = config('nova-editor-js.toolSettings.image.path') . '/' . $newThumbnailName;
207+
$newThumbnailName = $filename.$thumbnailName.'.'.$extension;
208+
$newThumbnailPath = config('nova-editor-js.toolSettings.image.path').'/'.$newThumbnailName;
209209

210210
Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->copy($path, $newThumbnailPath);
211211

@@ -227,20 +227,17 @@ private function applyThumbnails($path)
227227
return $generatedThumbnails;
228228
}
229229

230-
231-
/**
232-
*/
233230
private function deleteThumbnails($path)
234231
{
235232
$thumbnailSettings = config('nova-editor-js.toolSettings.image.thumbnails');
236233

237-
if (!empty($thumbnailSettings)) {
234+
if (! empty($thumbnailSettings)) {
238235
foreach ($thumbnailSettings as $thumbnailName => $setting) {
239236
$filename = pathinfo($path, PATHINFO_FILENAME);
240237
$extension = pathinfo($path, PATHINFO_EXTENSION);
241238

242-
$newThumbnailName = $filename . $thumbnailName . '.' . $extension;
243-
$newThumbnailPath = config('nova-editor-js.toolSettings.image.path') . '/' . $newThumbnailName;
239+
$newThumbnailName = $filename.$thumbnailName.'.'.$extension;
240+
$newThumbnailPath = config('nova-editor-js.toolSettings.image.path').'/'.$newThumbnailName;
244241

245242
Storage::disk('local')->delete($path, $newThumbnailPath);
246243
}

src/Http/Controllers/EditorJsLinkController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function fetch(Request $request): JsonResponse
3434
try {
3535
$url = $request->input('url');
3636
$response = Http::timeout(5)->get($url)->throw();
37-
} catch (ConnectionException | RequestException) {
37+
} catch (ConnectionException|RequestException) {
3838
return response()->json([
3939
'success' => 0,
4040
]);

src/NovaEditorJs.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/**
1010
* @method static HtmlString generateHtmlOutput(iterable|string $data)
1111
* @method static void addRender(string $block, callable $callback)
12+
*
1213
* @see NovaEditorJsConverter
1314
*/
1415
class NovaEditorJs extends Facade
@@ -28,7 +29,7 @@ protected static function getFacadeAccessor()
2829
*/
2930
public static function make(mixed $name, $attribute = null, $resolveCallback = null)
3031
{
31-
trigger_deprecation('advoor/nova-editor-js', '3.0', "NovaEditorJs has been converted to a Facade, use NovaEditorJsField::make instead");
32+
trigger_deprecation('advoor/nova-editor-js', '3.0', 'NovaEditorJs has been converted to a Facade, use NovaEditorJsField::make instead');
3233

3334
return NovaEditorJsField::make($name, $attribute, $resolveCallback);
3435
}

src/NovaEditorJsCast.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Advoor\NovaEditorJs;
66

7-
use Illuminate\Support\Str;
87
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
8+
use Illuminate\Support\Str;
99
use JsonException;
1010

1111
class NovaEditorJsCast implements CastsAttributes
@@ -26,11 +26,11 @@ private static function getErrorObject(string $exceptionMessage): NovaEditorJsDa
2626
'version' => self::BROKEN_VERSION,
2727
'blocks' => [
2828
[
29-
"id" => Str::random(10),
29+
'id' => Str::random(10),
3030
'type' => 'paragraph',
3131
'data' => [
3232
'text' => sprintf(
33-
"<b>Oh no!</b><br>It looks like this component failed to load.<br>Please contact your system administrator.<br>Error code: %s",
33+
'<b>Oh no!</b><br>It looks like this component failed to load.<br>Please contact your system administrator.<br>Error code: %s',
3434
e($exceptionMessage)
3535
),
3636
],
@@ -48,7 +48,7 @@ public function get($model, string $key, $value, array $attributes): ?NovaEditor
4848
{
4949
try {
5050
// Recursively decode JSON, to solve a bug where the JSON is double-encoded.
51-
while (is_string($value) && !empty($value)) {
51+
while (is_string($value) && ! empty($value)) {
5252
$value = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
5353
}
5454

src/NovaEditorJsConverter.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class NovaEditorJsConverter
1515
{
1616
/**
1717
* List of callbacks that can render blocks
18+
*
1819
* @var array<Closure>
1920
*/
2021
protected array $renderCallbacks = [];
@@ -27,8 +28,8 @@ public function __construct()
2728
/**
2829
* Add a custom render callback for the given block.
2930
*
30-
* @param string $block Name of the block, as defined in the JSON
31-
* @param callable $callback Closure that returns a string (or a Stringable)
31+
* @param string $block Name of the block, as defined in the JSON
32+
* @param callable $callback Closure that returns a string (or a Stringable)
3233
*/
3334
public function addRender(string $block, callable $callback): void
3435
{
@@ -47,7 +48,7 @@ public function generateHtmlOutput(mixed $data): HtmlString
4748
}
4849

4950
// Clean non-string data
50-
if (!is_string($data)) {
51+
if (! is_string($data)) {
5152
try {
5253
$data = json_encode($data, JSON_THROW_ON_ERROR);
5354
} catch (JsonException $exception) {
@@ -106,7 +107,7 @@ protected function registerDefaultCallbacks(): void
106107
$this->addRender(
107108
'image',
108109
fn ($block) => view('nova-editor-js::image', array_merge($block['data'], [
109-
'classes' => $this->calculateImageClasses($block['data'])
110+
'classes' => $this->calculateImageClasses($block['data']),
110111
]))->render()
111112
);
112113

0 commit comments

Comments
 (0)