chore: update quality tools + rewrite some migration files

* update php packages to latest
* update rector and ecs config
* update ci4/settings package to v2.1
This commit is contained in:
Yassine Doghri 2022-07-03 16:42:20 +00:00
parent ca55c248d0
commit 81f790868a
20 changed files with 713 additions and 806 deletions

View File

@ -303,7 +303,7 @@ class Mimes
/** /**
* Attempts to determine the best file extension for a given mime type. * Attempts to determine the best file extension for a given mime type.
* *
* @param string $proposedExtension - default extension (in case there is more than one with the same mime type) * @param string|null $proposedExtension - default extension (in case there is more than one with the same mime type)
* @return string|null The extension determined, or null if unable to match. * @return string|null The extension determined, or null if unable to match.
*/ */
public static function guessExtensionFromType(string $type, string $proposedExtension = null): ?string public static function guessExtensionFromType(string $type, string $proposedExtension = null): ?string

View File

@ -22,12 +22,20 @@ class AddEpisodeIdToPosts extends Migration
$fediverseTablesPrefix = config('Fediverse') $fediverseTablesPrefix = config('Fediverse')
->tablesPrefix; ->tablesPrefix;
$createQuery = <<<CODE_SAMPLE $this->forge->addColumn("{$fediverseTablesPrefix}posts", [
'episode_id' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
'after' => 'replies_count',
],
]);
$alterQuery = <<<CODE_SAMPLE
ALTER TABLE {$prefix}{$fediverseTablesPrefix}posts ALTER TABLE {$prefix}{$fediverseTablesPrefix}posts
ADD COLUMN `episode_id` INT UNSIGNED NULL AFTER `replies_count`,
ADD FOREIGN KEY {$prefix}{$fediverseTablesPrefix}posts_episode_id_foreign(episode_id) REFERENCES {$prefix}episodes(id) ON DELETE CASCADE; ADD FOREIGN KEY {$prefix}{$fediverseTablesPrefix}posts_episode_id_foreign(episode_id) REFERENCES {$prefix}episodes(id) ON DELETE CASCADE;
CODE_SAMPLE; CODE_SAMPLE;
$this->db->query($createQuery); $this->db->query($alterQuery);
} }
public function down(): void public function down(): void

View File

@ -22,12 +22,20 @@ class AddCreatedByToPosts extends Migration
$fediverseTablesPrefix = config('Fediverse') $fediverseTablesPrefix = config('Fediverse')
->tablesPrefix; ->tablesPrefix;
$createQuery = <<<CODE_SAMPLE $this->forge->addColumn("{$fediverseTablesPrefix}posts", [
'created_by' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
'after' => 'episode_id',
],
]);
$alterQuery = <<<CODE_SAMPLE
ALTER TABLE {$prefix}{$fediverseTablesPrefix}posts ALTER TABLE {$prefix}{$fediverseTablesPrefix}posts
ADD COLUMN `created_by` INT UNSIGNED AFTER `episode_id`,
ADD FOREIGN KEY {$prefix}{$fediverseTablesPrefix}posts_created_by_foreign(created_by) REFERENCES {$prefix}users(id) ON DELETE CASCADE; ADD FOREIGN KEY {$prefix}{$fediverseTablesPrefix}posts_created_by_foreign(created_by) REFERENCES {$prefix}users(id) ON DELETE CASCADE;
CODE_SAMPLE; CODE_SAMPLE;
$this->db->query($createQuery); $this->db->query($alterQuery);
} }
public function down(): void public function down(): void

View File

@ -9,7 +9,7 @@ use CodeIgniter\Database\Seeder;
class FakeSinglePodcastApiSeeder extends Seeder class FakeSinglePodcastApiSeeder extends Seeder
{ {
/** /**
* @return array<mixed> * @return array{id: int, file_path: string, file_size: int, file_mimetype: string, file_metadata: string, type: string, description: null, language_code: null, uploaded_by: int, updated_by: int, uploaded_at: string, updated_at: string}
*/ */
public static function cover(): array public static function cover(): array
{ {
@ -30,7 +30,7 @@ class FakeSinglePodcastApiSeeder extends Seeder
} }
/** /**
* @return array<mixed> * @return array{id: int, file_path: string, file_size: int, file_mimetype: string, file_metadata: string, type: string, description: null, language_code: null, uploaded_by: int, updated_by: int, uploaded_at: string, updated_at: string}
*/ */
public static function banner(): array public static function banner(): array
{ {
@ -51,7 +51,7 @@ class FakeSinglePodcastApiSeeder extends Seeder
} }
/** /**
* @return array<mixed> * @return array{id: int, uri: string, username: string, domain: string|false, private_key: string, public_key: string, display_name: string, summary: string, avatar_image_url: string, avatar_image_mimetype: string, cover_image_url: null, cover_image_mimetype: null, inbox_url: string, outbox_url: string, followers_url: string, followers_count: int, posts_count: int, is_blocked: int, created_at: string, updated_at: string}
*/ */
public static function actor(): array public static function actor(): array
{ {
@ -80,7 +80,7 @@ class FakeSinglePodcastApiSeeder extends Seeder
} }
/** /**
* @return array<mixed> * @return array{id: int, guid: string, actor_id: int, handle: string, title: string, description_markdown: string, description_html: string, cover_id: int, banner_id: int, language_code: string, category_id: int, parental_advisory: null, owner_name: string, owner_email: string, publisher: string, type: string, copyright: string, episode_description_footer_markdown: null, episode_description_footer_html: null, is_blocked: int, is_completed: int, is_locked: int, imported_feed_url: null, new_feed_url: null, payment_pointer: null, location_name: null, location_geo: null, location_osm: null, custom_rss: null, is_published_on_hubs: int, partner_id: null, partner_link_url: null, partner_image_url: null, created_by: int, updated_by: int, created_at: string, updated_at: string}
*/ */
public static function podcast(): array public static function podcast(): array
{ {

View File

@ -14,7 +14,7 @@ if (! function_exists('render_breadcrumb')) {
/** /**
* Renders the breadcrumb navigation through the Breadcrumb service * Renders the breadcrumb navigation through the Breadcrumb service
* *
* @param string $class to be added to the breadcrumb nav * @param string|null $class to be added to the breadcrumb nav
* @return string html breadcrumb * @return string html breadcrumb
*/ */
function render_breadcrumb(string $class = null): string function render_breadcrumb(string $class = null): string

View File

@ -14,7 +14,7 @@ if (! function_exists('icon')) {
* *
* @param string $name name of the icon file without the .svg extension * @param string $name name of the icon file without the .svg extension
* @param string $class to be added to the svg string * @param string $class to be added to the svg string
* @param 'social'|'podcasting'|'funding' $type type of icon to be added * @param string|null $type type of icon to be added
* @return string svg contents * @return string svg contents
*/ */
function icon(string $name, string $class = '', string $type = null): string function icon(string $name, string $class = '', string $type = null): string
@ -46,7 +46,7 @@ if (! function_exists('svg')) {
* Returns the inline svg image * Returns the inline svg image
* *
* @param string $name name of the image file without the .svg extension * @param string $name name of the image file without the .svg extension
* @param string $class to be added to the svg string * @param string|null $class to be added to the svg string
* @return string svg contents * @return string svg contents
*/ */
function svg(string $name, ?string $class = null): string function svg(string $name, ?string $class = null): string

View File

@ -9,12 +9,12 @@ use ErrorException;
class Vite class Vite
{ {
/** /**
* @var array<string, mixed> * @var array<string, mixed>|null
*/ */
protected ?array $manifestData = null; protected ?array $manifestData = null;
/** /**
* @var array<string, mixed> * @var array<string, mixed>|null
*/ */
protected ?array $manifestCSSData = null; protected ?array $manifestCSSData = null;

View File

@ -54,7 +54,7 @@ class ClipModel extends Model
]; ];
/** /**
* @var string * @noRector
*/ */
protected $returnType = BaseClip::class; protected $returnType = BaseClip::class;

View File

@ -309,7 +309,7 @@ class EpisodeModel extends Model
} }
/** /**
* @return array<string, int|Time> * @return array{number_of_seasons: int, number_of_episodes: int, first_published_at?: Time}
*/ */
public function getPodcastStats(int $podcastId): array public function getPodcastStats(int $podcastId): array
{ {

View File

@ -29,7 +29,7 @@ class MediaModel extends Model
protected $table = 'media'; protected $table = 'media';
/** /**
* @var string * @noRector
*/ */
protected $returnType = Document::class; protected $returnType = Document::class;

View File

@ -164,8 +164,6 @@ class PodcastModel extends Model
} }
/** /**
* @param 'activity'|'created_asc'|'created_desc' $orderBy
*
* @return Podcast[] * @return Podcast[]
*/ */
public function getAllPodcasts(string $orderBy = null): array public function getAllPodcasts(string $orderBy = null): array

View File

@ -17,7 +17,7 @@ class FileRules extends ValidationFileRules
/** /**
* Checks an uploaded file to verify that the dimensions are within a specified allowable dimension. * Checks an uploaded file to verify that the dimensions are within a specified allowable dimension.
*/ */
public function min_dims(string $blank = null, string $params): bool public function min_dims(string $blank = null, string $params = ''): bool
{ {
// Grab the file name off the top of the $params // Grab the file name off the top of the $params
// after we split it. // after we split it.
@ -59,7 +59,7 @@ class FileRules extends ValidationFileRules
/** /**
* Checks an uploaded image to verify that the ratio corresponds to the params * Checks an uploaded image to verify that the ratio corresponds to the params
*/ */
public function is_image_ratio(string $blank = null, string $params): bool public function is_image_ratio(string $blank = null, string $params = ''): bool
{ {
// Grab the file name off the top of the $params // Grab the file name off the top of the $params
// after we split it. // after we split it.

View File

@ -9,30 +9,30 @@
"php": "^8.0", "php": "^8.0",
"codeigniter4/framework": "^4.2.1", "codeigniter4/framework": "^4.2.1",
"james-heinrich/getid3": "^2.0.x-dev", "james-heinrich/getid3": "^2.0.x-dev",
"whichbrowser/parser": "^v2.1.1", "whichbrowser/parser": "^v2.1.7",
"geoip2/geoip2": "^v2.12.2", "geoip2/geoip2": "^v2.12.2",
"myth/auth": "dev-develop", "myth/auth": "dev-develop",
"league/commonmark": "^2.2", "league/commonmark": "^2.3.3",
"vlucas/phpdotenv": "^v5.3.0", "vlucas/phpdotenv": "^v5.4.1",
"league/html-to-markdown": "^v5.0.1", "league/html-to-markdown": "^v5.1.0",
"opawg/user-agents-php": "^v1.0", "opawg/user-agents-php": "^v1.0",
"adaures/ipcat-php": "^1.0", "adaures/ipcat-php": "^1.0",
"adaures/podcast-persons-taxonomy": "^1.0", "adaures/podcast-persons-taxonomy": "^1.0",
"phpseclib/phpseclib": "~2.0.30", "phpseclib/phpseclib": "~2.0.37",
"michalsn/codeigniter4-uuid": "dev-develop", "michalsn/codeigniter4-uuid": "dev-develop",
"essence/essence": "^3.5.4", "essence/essence": "^3.5.4",
"codeigniter4/settings": "^v1.0", "codeigniter4/settings": "^v2.1.0",
"chrisjean/php-ico": "^1.0", "chrisjean/php-ico": "^1.0.4",
"melbahja/seo": "^2.0" "melbahja/seo": "^v2.1.0"
}, },
"require-dev": { "require-dev": {
"mikey179/vfsstream": "v1.6.10", "mikey179/vfsstream": "v1.6.10",
"phpunit/phpunit": "^9.5.16", "phpunit/phpunit": "^9.5.21",
"captainhook/captainhook": "^5.10.7", "captainhook/captainhook": "^5.10.10",
"symplify/easy-coding-standard": "^10.1", "symplify/easy-coding-standard": "^10.3.3",
"phpstan/phpstan": "^1.4", "phpstan/phpstan": "^1.8.0",
"rector/rector": "^0.12.16", "rector/rector": "^0.12.23",
"symplify/coding-standard": "^10.1" "symplify/coding-standard": "^10.3.3"
}, },
"autoload": { "autoload": {
"exclude-from-classmap": [ "exclude-from-classmap": [

1352
composer.lock generated

File diff suppressed because it is too large Load Diff

21
ecs.php
View File

@ -1,19 +1,16 @@
<?php <?php
use PhpCsFixer\Fixer\Whitespace\IndentationTypeFixer; use PhpCsFixer\Fixer\Whitespace\IndentationTypeFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\Naming\StandardizeHereNowDocKeywordFixer; use Symplify\CodingStandard\Fixer\Naming\StandardizeHereNowDocKeywordFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList; use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff; use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
return static function (ContainerConfigurator $containerConfigurator): void { return static function (ECSConfig $ecsConfig): void {
$parameters = $containerConfigurator->parameters();
// alternative to CLI arguments, easier to maintain and extend // alternative to CLI arguments, easier to maintain and extend
$parameters->set(Option::PATHS, [ $ecsConfig->paths([
__DIR__ . '/app', __DIR__ . '/app',
__DIR__ . '/modules', __DIR__ . '/modules',
__DIR__ . '/themes', __DIR__ . '/themes',
@ -21,7 +18,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
__DIR__ . '/public', __DIR__ . '/public',
]); ]);
$parameters->set(Option::SKIP, [ $ecsConfig->skip([
// skip specific generated files // skip specific generated files
__DIR__ . '/modules/Admin/Language/*/PersonsTaxonomy.php', __DIR__ . '/modules/Admin/Language/*/PersonsTaxonomy.php',
@ -53,8 +50,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
AssignmentInConditionSniff::class, AssignmentInConditionSniff::class,
]); ]);
$containerConfigurator->import(SetList::PSR_12); $ecsConfig->sets([
$containerConfigurator->import(SetList::SYMPLIFY); SetList::PSR_12,
$containerConfigurator->import(SetList::COMMON); SetList::SYMPLIFY,
$containerConfigurator->import(SetList::CLEAN_CODE); SetList::COMMON,
SetList::CLEAN_CODE
]);
}; };

View File

@ -42,7 +42,7 @@ class Actor extends Entity
protected string $public_key_id; protected string $public_key_id;
/** /**
* @var Actor[] * @var \Modules\Fediverse\Entities\Actor[]|null
*/ */
protected ?array $followers = null; protected ?array $followers = null;

View File

@ -81,7 +81,7 @@ class ActivityModel extends BaseUuidModel
/** /**
* Inserts a new activity record in the database * Inserts a new activity record in the database
* *
* @param Time $scheduledAt * @param Time|null $scheduledAt
*/ */
public function newActivity( public function newActivity(
string $type, string $type,

View File

@ -86,7 +86,7 @@ class WebFinger
/** /**
* Get WebFinger response as an array * Get WebFinger response as an array
* *
* @return array<string, array|string> * @return array{subject: string, aliases: string[], links: array<mixed, array<string, string>>}
*/ */
public function toArray(): array public function toArray(): array
{ {

View File

@ -245,7 +245,7 @@ class InstallController extends Controller
{ {
$migrations = Services::migrations(); $migrations = Services::migrations();
$migrations->setNamespace('Sparks\Settings') $migrations->setNamespace('CodeIgniter\Settings')
->latest(); ->latest();
$migrations->setNamespace('Myth\Auth') $migrations->setNamespace('Myth\Auth')
->latest(); ->latest();

View File

@ -8,20 +8,17 @@ use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector; use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector; use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Core\Configuration\Option; use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion; use Rector\Core\ValueObject\PhpVersion;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector; use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector; use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php80\Rector\ClassMethod\OptionalParametersAfterRequiredRector; use Rector\Php80\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
use Rector\Set\ValueObject\SetList; use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void { return static function (RectorConfig $rectorConfig): void {
// get parameters // get parameters
$parameters = $containerConfigurator->parameters(); $rectorConfig->paths([
$parameters->set(Option::PATHS, [
__DIR__ . '/app', __DIR__ . '/app',
__DIR__ . '/modules', __DIR__ . '/modules',
__DIR__ . '/tests', __DIR__ . '/tests',
@ -29,27 +26,28 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]); ]);
// do you need to include constants, class aliases or custom autoloader? files listed will be executed // do you need to include constants, class aliases or custom autoloader? files listed will be executed
$parameters->set(Option::BOOTSTRAP_FILES, [ $rectorConfig->bootstrapFiles([
__DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', __DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php',
]); ]);
// Define what rule sets will be applied // Define what rule sets will be applied
$containerConfigurator->import(SetList::PHP_80); $rectorConfig->sets([SetList::PHP_80,
$containerConfigurator->import(SetList::TYPE_DECLARATION); SetList::TYPE_DECLARATION,
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT); SetList::TYPE_DECLARATION_STRICT,
$containerConfigurator->import(SetList::CODE_QUALITY); SetList::CODE_QUALITY,
$containerConfigurator->import(SetList::CODING_STYLE); SetList::CODING_STYLE,
$containerConfigurator->import(SetList::EARLY_RETURN); SetList::EARLY_RETURN,
$containerConfigurator->import(SetList::DEAD_CODE); SetList::DEAD_CODE,
$containerConfigurator->import(SetList::ORDER); ]);
// auto import fully qualified class names // auto import fully qualified class names
$parameters->set(Option::AUTO_IMPORT_NAMES, true); $rectorConfig->importNames();
// TODO: add parallel // TODO: add parallel run
// $parameters->set(Option::PARALLEL, true); // $rectorConfig->parallel();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
$parameters->set(Option::SKIP, [ $rectorConfig->phpVersion(PhpVersion::PHP_80);
$rectorConfig->skip([
__DIR__ . '/app/Views/errors/*', __DIR__ . '/app/Views/errors/*',
// skip specific generated files // skip specific generated files
@ -81,15 +79,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]); ]);
// Path to phpstan with extensions, that PHPStan in Rector uses to determine types // Path to phpstan with extensions, that PHPStan in Rector uses to determine types
$parameters->set( $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon');
Option::PHPSTAN_FOR_RECTOR_PATH,
__DIR__ . '/phpstan.neon',
);
$services = $containerConfigurator->services(); $rectorConfig->ruleWithConfiguration(ConsistentPregDelimiterRector::class, [
$services->set(ConsistentPregDelimiterRector::class)->call('configure', [ ConsistentPregDelimiterRector::DELIMITER => '~',
[
ConsistentPregDelimiterRector::DELIMITER => '~',
],
]); ]);
}; };