Skip to content

Commit

Permalink
Adds a set provider class (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfox authored Sep 11, 2024
1 parent 3ec89de commit a7306b9
Showing 1 changed file with 129 additions and 0 deletions.
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,
),
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;
}
}

0 comments on commit a7306b9

Please sign in to comment.