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.
*
* @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.
*/
public static function guessExtensionFromType(string $type, string $proposedExtension = null): ?string

View File

@ -22,12 +22,20 @@ class AddEpisodeIdToPosts extends Migration
$fediverseTablesPrefix = config('Fediverse')
->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
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;
CODE_SAMPLE;
$this->db->query($createQuery);
$this->db->query($alterQuery);
}
public function down(): void

View File

@ -22,12 +22,20 @@ class AddCreatedByToPosts extends Migration
$fediverseTablesPrefix = config('Fediverse')
->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
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;
CODE_SAMPLE;
$this->db->query($createQuery);
$this->db->query($alterQuery);
}
public function down(): void

View File

@ -9,7 +9,7 @@ use CodeIgniter\Database\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
{
@ -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
{
@ -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
{
@ -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
{

View File

@ -14,7 +14,7 @@ if (! function_exists('render_breadcrumb')) {
/**
* 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
*/
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 $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
*/
function icon(string $name, string $class = '', string $type = null): string
@ -46,7 +46,7 @@ if (! function_exists('svg')) {
* Returns the inline svg image
*
* @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
*/
function svg(string $name, ?string $class = null): string

View File

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

View File

@ -54,7 +54,7 @@ class ClipModel extends Model
];
/**
* @var string
* @noRector
*/
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
{

View File

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

View File

@ -164,8 +164,6 @@ class PodcastModel extends Model
}
/**
* @param 'activity'|'created_asc'|'created_desc' $orderBy
*
* @return Podcast[]
*/
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.
*/
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
// 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
*/
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
// after we split it.

View File

@ -9,30 +9,30 @@
"php": "^8.0",
"codeigniter4/framework": "^4.2.1",
"james-heinrich/getid3": "^2.0.x-dev",
"whichbrowser/parser": "^v2.1.1",
"whichbrowser/parser": "^v2.1.7",
"geoip2/geoip2": "^v2.12.2",
"myth/auth": "dev-develop",
"league/commonmark": "^2.2",
"vlucas/phpdotenv": "^v5.3.0",
"league/html-to-markdown": "^v5.0.1",
"league/commonmark": "^2.3.3",
"vlucas/phpdotenv": "^v5.4.1",
"league/html-to-markdown": "^v5.1.0",
"opawg/user-agents-php": "^v1.0",
"adaures/ipcat-php": "^1.0",
"adaures/podcast-persons-taxonomy": "^1.0",
"phpseclib/phpseclib": "~2.0.30",
"phpseclib/phpseclib": "~2.0.37",
"michalsn/codeigniter4-uuid": "dev-develop",
"essence/essence": "^3.5.4",
"codeigniter4/settings": "^v1.0",
"chrisjean/php-ico": "^1.0",
"melbahja/seo": "^2.0"
"codeigniter4/settings": "^v2.1.0",
"chrisjean/php-ico": "^1.0.4",
"melbahja/seo": "^v2.1.0"
},
"require-dev": {
"mikey179/vfsstream": "v1.6.10",
"phpunit/phpunit": "^9.5.16",
"captainhook/captainhook": "^5.10.7",
"symplify/easy-coding-standard": "^10.1",
"phpstan/phpstan": "^1.4",
"rector/rector": "^0.12.16",
"symplify/coding-standard": "^10.1"
"phpunit/phpunit": "^9.5.21",
"captainhook/captainhook": "^5.10.10",
"symplify/easy-coding-standard": "^10.3.3",
"phpstan/phpstan": "^1.8.0",
"rector/rector": "^0.12.23",
"symplify/coding-standard": "^10.3.3"
},
"autoload": {
"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
use PhpCsFixer\Fixer\Whitespace\IndentationTypeFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\Naming\StandardizeHereNowDocKeywordFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
return static function (ECSConfig $ecsConfig): void {
// alternative to CLI arguments, easier to maintain and extend
$parameters->set(Option::PATHS, [
$ecsConfig->paths([
__DIR__ . '/app',
__DIR__ . '/modules',
__DIR__ . '/themes',
@ -21,7 +18,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
__DIR__ . '/public',
]);
$parameters->set(Option::SKIP, [
$ecsConfig->skip([
// skip specific generated files
__DIR__ . '/modules/Admin/Language/*/PersonsTaxonomy.php',
@ -53,8 +50,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
AssignmentInConditionSniff::class,
]);
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::SYMPLIFY);
$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::CLEAN_CODE);
$ecsConfig->sets([
SetList::PSR_12,
SetList::SYMPLIFY,
SetList::COMMON,
SetList::CLEAN_CODE
]);
};

View File

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

View File

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

View File

@ -86,7 +86,7 @@ class WebFinger
/**
* 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
{

View File

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

View File

@ -8,20 +8,17 @@ use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Core\Configuration\Option;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php80\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
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
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
$rectorConfig->paths([
__DIR__ . '/app',
__DIR__ . '/modules',
__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
$parameters->set(Option::BOOTSTRAP_FILES, [
$rectorConfig->bootstrapFiles([
__DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php',
]);
// Define what rule sets will be applied
$containerConfigurator->import(SetList::PHP_80);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODING_STYLE);
$containerConfigurator->import(SetList::EARLY_RETURN);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::ORDER);
$rectorConfig->sets([SetList::PHP_80,
SetList::TYPE_DECLARATION,
SetList::TYPE_DECLARATION_STRICT,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::EARLY_RETURN,
SetList::DEAD_CODE,
]);
// auto import fully qualified class names
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
// TODO: add parallel
// $parameters->set(Option::PARALLEL, true);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
$rectorConfig->importNames();
// TODO: add parallel run
// $rectorConfig->parallel();
$parameters->set(Option::SKIP, [
$rectorConfig->phpVersion(PhpVersion::PHP_80);
$rectorConfig->skip([
__DIR__ . '/app/Views/errors/*',
// 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
$parameters->set(
Option::PHPSTAN_FOR_RECTOR_PATH,
__DIR__ . '/phpstan.neon',
);
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon');
$services = $containerConfigurator->services();
$services->set(ConsistentPregDelimiterRector::class)->call('configure', [
[
ConsistentPregDelimiterRector::DELIMITER => '~',
],
$rectorConfig->ruleWithConfiguration(ConsistentPregDelimiterRector::class, [
ConsistentPregDelimiterRector::DELIMITER => '~',
]);
};