Skip to content
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

Adds a set provider class #248

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
129 changes: 129 additions & 0 deletions src/Set/LaravelSetProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

namespace RectorLaravel\Set;

use Rector\Set\Contract\SetProviderInterface;
use Rector\Set\ValueObject\Set;
use RectorLaravel\Set\Packages\Livewire\LivewireSetList;

final class LaravelSetProvider implements SetProviderInterface
{
private const GROUP_NAME = 'laravel';

/**
* @var string[]
*/
private const LARAVEL_FIVE = [
LaravelSetList::LARAVEL_50,
LaravelSetList::LARAVEL_51,
LaravelSetList::LARAVEL_52,
LaravelSetList::LARAVEL_53,
LaravelSetList::LARAVEL_54,
LaravelSetList::LARAVEL_55,
LaravelSetList::LARAVEL_56,
LaravelSetList::LARAVEL_57,
LaravelSetList::LARAVEL_58,
];

/**
* @var string[]
*/
private const LARAVEL_POST_FIVE = [
LaravelSetList::LARAVEL_60,
LaravelSetList::LARAVEL_70,
LaravelSetList::LARAVEL_80,
LaravelSetList::LARAVEL_90,
LaravelSetList::LARAVEL_100,
LaravelSetList::LARAVEL_110,
];

public function provide(): array
{
return [
new Set(
self::GROUP_NAME,
'array/str func to static calls',
LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL
),
new Set(self::GROUP_NAME, 'Code quality', LaravelSetList::LARAVEL_CODE_QUALITY),
new Set(
self::GROUP_NAME,
'Container strings to FQN types',
LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,
),
new Set(
'Laravel Code Quality',
'array/str functions to static calls',
LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL
),
new Set(self::GROUP_NAME, 'Code quality', LaravelSetList::LARAVEL_CODE_QUALITY),
new Set(
self::GROUP_NAME,
'Container strings to FQN types',
LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,
),
new Set(
self::GROUP_NAME,
'Code Quality for Laravel',
LaravelSetList::LARAVEL_CODE_QUALITY,
GeniJaho marked this conversation as resolved.
Show resolved Hide resolved
),
new Set(
self::GROUP_NAME,
'Replaces If statements with helpers',
LaravelSetList::LARAVEL_IF_HELPERS,
),
new Set(
self::GROUP_NAME,
'Replace facades with service injection',
LaravelSetList::LARAVEL_STATIC_TO_INJECTION,
),
new Set(
self::GROUP_NAME,
'Rename Alias to FQN Classes',
LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES,
),
new Set(
self::GROUP_NAME,
'Replace Magic Methods to Query Builder',
LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER,
),
new Set(
self::GROUP_NAME,
'Upgrade Legacy Factories to Modern Factories',
LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES,
),
new Set(
self::GROUP_NAME,
'Livewire 3.0',
LivewireSetList::LIVEWIRE_30,
),
...$this->getLaravelVersions(),
];
}

/**
* @return Set[]
*/
private function getLaravelVersions(): array
{
$versions = [];

foreach (self::LARAVEL_FIVE as $index => $version) {
$versions[] = new Set(
self::GROUP_NAME,
'Laravel Framework 5.' . $index,
$version,
);
}

foreach (self::LARAVEL_POST_FIVE as $index => $version) {
$versions[] = new Set(
self::GROUP_NAME,
'Laravel Framework ' . ($index + 6) . '.0',
$version,
);
}

return $versions;
}
}
Loading