Skip to content

Commit

Permalink
Added rector/rector
Browse files Browse the repository at this point in the history
  • Loading branch information
tdwesten committed Jan 20, 2025
1 parent e51efeb commit 585980a
Show file tree
Hide file tree
Showing 65 changed files with 389 additions and 252 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"test": [
"./vendor/bin/pest"
"./vendor/bin/pest && ./vendor/bin/rector"
],
"generate-field": [
"php field-generator/Generator.php"
Expand All @@ -38,7 +38,8 @@
"orchestra/testbench": "^9.0",
"spatie/laravel-ray": "^1.39",
"pestphp/pest-plugin-laravel": "^3",
"statamic/eloquent-driver": "^4.16"
"statamic/eloquent-driver": "^4.16",
"rector/rector": "^2.0"
},
"config": {
"allow-plugins": {
Expand Down
119 changes: 118 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion field-generator/FieldTestTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Tdwesten\StatamicBuilder\Enums\VisibilityOption;

it('can render to a array', function () {
it('can render to a array', function (): void {
$field = new \Tdwesten\StatamicBuilder\FieldTypes\__Field__('title');
$field->displayName('Display Name')
->instructions('Enter the title')
Expand Down
19 changes: 19 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/config',
__DIR__ . '/field-generator',
__DIR__ . '/resources',
__DIR__ . '/src',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
6 changes: 3 additions & 3 deletions src/Console/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ private function exportBlueprints()
{
$namespaces = collect(config('statamic.builder.blueprints', []));

$namespaces->each(function ($blueprints, $namespace) {
$namespaces->each(function ($blueprints, $namespace): void {
$blueprints = collect($blueprints);

$blueprints->each(function ($blueprint, $handle) use ($namespace) {
$blueprints->each(function ($blueprint, $handle) use ($namespace): void {
$this->exportBlueprint($namespace, $handle, $blueprint);
});
});
Expand Down Expand Up @@ -64,7 +64,7 @@ private function exportFieldSets()
{
$namespaces = collect(config('statamic.builder.fieldsets', []));

$namespaces->each(function ($fieldset) {
$namespaces->each(function ($fieldset): void {
$this->exportFieldset($fieldset);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/CollectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function initializeCollections()

$this->collections = collect();

$collections->each(function (string $collection) {
$collections->each(function (string $collection): void {
if (class_exists($collection, true)) {
$this->collections->put($collection::handle(), $collection);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/GlobalRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function initializeGlobals()

$this->globals = collect();

$globals->each(function (string $set) {
$globals->each(function (string $set): void {
if (class_exists($set, true)) {
$this->globals->put($set::handle(), $set);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/TaxonomyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function initializeTaxonomies()

$this->taxonomies = collect();

$taxonomies->each(function (string $taxonomy) {
$taxonomies->each(function (string $taxonomy): void {
if (class_exists($taxonomy, true)) {
$this->taxonomies->put($taxonomy::handle(), $taxonomy);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
use Tdwesten\StatamicBuilder\FieldTypes\Text;
use Tests\Helpers\TestBlueprint;

test('Has a title', function () {
test('Has a title', function (): void {
$blueprint = TestBlueprint::make('test_blueprint');

expect($blueprint->toArray()['title'])->toBe(
'Test Blueprint'
);
});

it('can be set to hidden', function () {
it('can be set to hidden', function (): void {
$blueprint = TestBlueprint::make('test_blueprint');
$blueprint->hidden(true);

expect($blueprint->toArray()['hide'])->toBe(true);
});

test('Tabs are renderd', function () {
test('Tabs are renderd', function (): void {
$blueprint = TestBlueprint::make('test_blueprint');

$expected = [
Expand Down Expand Up @@ -58,7 +58,7 @@
expect($blueprint->toArray())->toBe($expected);
});

it('throws an exception when adding a field to a tab', function () {
it('throws an exception when adding a field to a tab', function (): void {
$blueprint = TestBlueprint::make('test_blueprint');
$blueprint
->title('School')
Expand All @@ -69,14 +69,14 @@
$blueprint->toArray();
})->throws(BlueprintRenderException::class, 'Only sections are allowed in tabs');

test('you can set a title', function () {
test('you can set a title', function (): void {
$blueprint = TestBlueprint::make('test_blueprint');
$blueprint->title('School');

expect($blueprint->toArray()['title'])->toBe('School');
});

test('you can get the handle', function () {
test('you can get the handle', function (): void {
$blueprint = TestBlueprint::make('test_blueprint');

expect($blueprint->getHandle())->toBe('test_blueprint');
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
use Tests\Helpers\MultisiteTestCollection;
use Tests\Helpers\TestCollection;

test('Has a title', function () {
test('Has a title', function (): void {
$collection = new TestCollection;

expect($collection->title())->toBe(
'Shows'
);
});

test('Has a handle', function () {
test('Has a handle', function (): void {
$collection = new TestCollection;

expect($collection->handle())->toBe(
'shows'
);
});

test('Has a route', function () {
test('Has a route', function (): void {
$collection = new TestCollection;

expect($collection->route())->toBe(
'/shows/{slug}'
);
});

test('Has multiple route for multisites', function () {
test('Has multiple route for multisites', function (): void {
$collection = new MultisiteTestCollection;

expect($collection->route())->toBe(
Expand All @@ -38,15 +38,15 @@
);
});

test('Can have multiple sites', function () {
test('Can have multiple sites', function (): void {
$collection = new MultisiteTestCollection;

expect($collection->sites())->toBe(
['en', 'de']
);
});

test('Has slugs', function () {
test('Has slugs', function (): void {
$collection = new TestCollection;

expect($collection->slugs())->toBeTrue();
Expand Down
Loading

0 comments on commit 585980a

Please sign in to comment.