Skip to content

Commit

Permalink
build: replaced php-cs-fixer with Laravel Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
roelofr committed Apr 19, 2024
1 parent b45b75e commit 627e829
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 174 deletions.
32 changes: 0 additions & 32 deletions .php-cs-fixer.dist.php

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"spatie/image": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.9",
"laravel/pint": "^1.15",
"orchestra/testbench": "^8.0 || ^9.0",
"php-parallel-lint/php-parallel-lint": "^1.3"
},
Expand All @@ -44,7 +44,7 @@
"parallel-lint --exclude .git --exclude vendor ."
],
"format": [
"php-cs-fixer fix"
"pint"
]
},
"scripts-descriptions": {
Expand Down
14 changes: 14 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"preset": "laravel",
"rules": {
"php_unit_method_casing": {
"case": "camel_case"
},
"php_unit_test_annotation": {
"style": "prefix"
},
"no_superfluous_phpdoc_tags": true,
"declare_strict_types": true,
"strict_param": true
}
}
9 changes: 4 additions & 5 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

declare(strict_types=1);

use Illuminate\Support\Facades\Route;

use Advoor\NovaEditorJs\Http\Controllers\EditorJsImageUploadController;
use Advoor\NovaEditorJs\Http\Controllers\EditorJsLinkController;
use Illuminate\Support\Facades\Route;

Route::post('upload/file', EditorJsImageUploadController::class . '@file')->name('editor-js-upload-image-by-file');
Route::post('upload/url', EditorJsImageUploadController::class . '@url')->name('editor-js-upload-image-by-url');
Route::get('fetch/url', EditorJsLinkController::class . '@fetch')->name('editor-js-fetch-url');
Route::post('upload/file', EditorJsImageUploadController::class.'@file')->name('editor-js-upload-image-by-file');
Route::post('upload/url', EditorJsImageUploadController::class.'@url')->name('editor-js-upload-image-by-url');
Route::get('fetch/url', EditorJsLinkController::class.'@fetch')->name('editor-js-fetch-url');
21 changes: 10 additions & 11 deletions src/FieldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Advoor\NovaEditorJs;

use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Laravel\Nova\Nova;
use Laravel\Nova\Events\ServingNova;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;

/**
* @property-read \Illuminate\Foundation\Application $app
Expand All @@ -27,21 +27,21 @@ public function boot()
});

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

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

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

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

if (!$this->app->configurationIsCached() && !$this->app->isProduction()) {
if (! $this->app->configurationIsCached() && ! $this->app->isProduction()) {
$this->checkForConfigDeprecations();
}
}
Expand All @@ -59,7 +59,7 @@ protected function routes()

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

/**
Expand All @@ -76,7 +76,6 @@ public function register()

/**
* Check for deprecated config keys.
*
*/
protected function checkForConfigDeprecations(): void
{
Expand Down
55 changes: 26 additions & 29 deletions src/Http/Controllers/EditorJsImageUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function file(Request $request): JsonResponse
'success' => 1,
'file' => [
'url' => Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($path),
'thumbnails' => $thumbnails
]
'thumbnails' => $thumbnails,
],
]);
}

Expand All @@ -96,35 +96,35 @@ public function url(Request $request): JsonResponse
// Fetch URL
try {
$response = Http::timeout(5)->get($url)->throw();
} catch (ConnectionException | RequestException) {
} catch (ConnectionException|RequestException) {
return response()->json([
'success' => 0,
]);
}

// Validate mime type
$mime = (new finfo())->buffer($response->body(), FILEINFO_MIME_TYPE);
if (!in_array($mime, self::VALID_IMAGE_MIMES, true)) {
if (! in_array($mime, self::VALID_IMAGE_MIMES, true)) {
return response()->json([
'success' => 0,
]);
}

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

return response()->json([
'success' => 1,
'file' => [
'url' => Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($nameWithPath)
]
'url' => Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($nameWithPath),
],
]);
}

/**
* @param array $alterations
* @param array $alterations
*/
private function applyAlterations($path, $alterations = [])
{
Expand All @@ -133,54 +133,54 @@ private function applyAlterations($path, $alterations = [])

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

if (!empty($alterations)) {
if (! empty($alterations)) {
$imageSettings = $alterations;
}

if (empty($imageSettings)) {
return;
}

if (!empty($imageSettings['resize']['width'])) {
if (! empty($imageSettings['resize']['width'])) {
$image->width($imageSettings['resize']['width']);
}

if (!empty($imageSettings['resize']['height'])) {
if (! empty($imageSettings['resize']['height'])) {
$image->height($imageSettings['resize']['height']);
}

if (!empty($imageSettings['optimize'])) {
if (! empty($imageSettings['optimize'])) {
$image->optimize();
}

if (!empty($imageSettings['adjustments']['brightness'])) {
if (! empty($imageSettings['adjustments']['brightness'])) {
$image->brightness($imageSettings['adjustments']['brightness']);
}

if (!empty($imageSettings['adjustments']['contrast'])) {
if (! empty($imageSettings['adjustments']['contrast'])) {
$image->contrast($imageSettings['adjustments']['contrast']);
}

if (!empty($imageSettings['adjustments']['gamma'])) {
if (! empty($imageSettings['adjustments']['gamma'])) {
$image->gamma($imageSettings['adjustments']['gamma']);
}

if (!empty($imageSettings['effects']['blur'])) {
if (! empty($imageSettings['effects']['blur'])) {
$image->blur($imageSettings['effects']['blur']);
}

if (!empty($imageSettings['effects']['pixelate'])) {
if (! empty($imageSettings['effects']['pixelate'])) {
$image->pixelate($imageSettings['effects']['pixelate']);
}

if (!empty($imageSettings['effects']['greyscale'])) {
if (! empty($imageSettings['effects']['greyscale'])) {
$image->greyscale();
}
if (!empty($imageSettings['effects']['sepia'])) {
if (! empty($imageSettings['effects']['sepia'])) {
$image->sepia();
}

if (!empty($imageSettings['effects']['sharpen'])) {
if (! empty($imageSettings['effects']['sharpen'])) {
$image->sharpen($imageSettings['effects']['sharpen']);
}

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

$generatedThumbnails = [];

if (!empty($thumbnailSettings)) {
if (! empty($thumbnailSettings)) {
foreach ($thumbnailSettings as $thumbnailName => $setting) {
$filename = pathinfo($path, PATHINFO_FILENAME);
$extension = pathinfo($path, PATHINFO_EXTENSION);

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

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

Expand All @@ -227,20 +227,17 @@ private function applyThumbnails($path)
return $generatedThumbnails;
}


/**
*/
private function deleteThumbnails($path)
{
$thumbnailSettings = config('nova-editor-js.toolSettings.image.thumbnails');

if (!empty($thumbnailSettings)) {
if (! empty($thumbnailSettings)) {
foreach ($thumbnailSettings as $thumbnailName => $setting) {
$filename = pathinfo($path, PATHINFO_FILENAME);
$extension = pathinfo($path, PATHINFO_EXTENSION);

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

Storage::disk('local')->delete($path, $newThumbnailPath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/EditorJsLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function fetch(Request $request): JsonResponse
try {
$url = $request->input('url');
$response = Http::timeout(5)->get($url)->throw();
} catch (ConnectionException | RequestException) {
} catch (ConnectionException|RequestException) {
return response()->json([
'success' => 0,
]);
Expand Down
3 changes: 2 additions & 1 deletion src/NovaEditorJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* @method static HtmlString generateHtmlOutput(iterable|string $data)
* @method static void addRender(string $block, callable $callback)
*
* @see NovaEditorJsConverter
*/
class NovaEditorJs extends Facade
Expand All @@ -28,7 +29,7 @@ protected static function getFacadeAccessor()
*/
public static function make(mixed $name, $attribute = null, $resolveCallback = null)
{
trigger_deprecation('advoor/nova-editor-js', '3.0', "NovaEditorJs has been converted to a Facade, use NovaEditorJsField::make instead");
trigger_deprecation('advoor/nova-editor-js', '3.0', 'NovaEditorJs has been converted to a Facade, use NovaEditorJsField::make instead');

return NovaEditorJsField::make($name, $attribute, $resolveCallback);
}
Expand Down
8 changes: 4 additions & 4 deletions src/NovaEditorJsCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Advoor\NovaEditorJs;

use Illuminate\Support\Str;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\Str;
use JsonException;

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

Expand Down
9 changes: 5 additions & 4 deletions src/NovaEditorJsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class NovaEditorJsConverter
{
/**
* List of callbacks that can render blocks
*
* @var array<Closure>
*/
protected array $renderCallbacks = [];
Expand All @@ -27,8 +28,8 @@ public function __construct()
/**
* Add a custom render callback for the given block.
*
* @param string $block Name of the block, as defined in the JSON
* @param callable $callback Closure that returns a string (or a Stringable)
* @param string $block Name of the block, as defined in the JSON
* @param callable $callback Closure that returns a string (or a Stringable)
*/
public function addRender(string $block, callable $callback): void
{
Expand All @@ -47,7 +48,7 @@ public function generateHtmlOutput(mixed $data): HtmlString
}

// Clean non-string data
if (!is_string($data)) {
if (! is_string($data)) {
try {
$data = json_encode($data, JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
Expand Down Expand Up @@ -106,7 +107,7 @@ protected function registerDefaultCallbacks(): void
$this->addRender(
'image',
fn ($block) => view('nova-editor-js::image', array_merge($block['data'], [
'classes' => $this->calculateImageClasses($block['data'])
'classes' => $this->calculateImageClasses($block['data']),
]))->render()
);

Expand Down
Loading

0 comments on commit 627e829

Please sign in to comment.