Skip to content

Commit

Permalink
Merge pull request #16600 from craftcms/pullrequests/samsonasik/start…
Browse files Browse the repository at this point in the history
…-using-rector

Start using Rector in CI/CD pipeline
  • Loading branch information
angrybrad authored Jan 31, 2025
2 parents 7547163 + 7d5d187 commit 15b60f3
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 26 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ jobs:
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: ${{ secrets.SLACK_CRAFT_WEBHOOK_URL }}

# this can be moved to .github repo once this is proven works on CI
rector:
strategy:
fail-fast: false

runs-on: ubuntu-latest
timeout-minutes: 8
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
# PHP 8.2 is required, so Rector's code is PHP 8.2 compatible even after refactoring
php-version: 8.2
coverage: none

- run: composer install --no-progress --ansi
- run: vendor/bin/rector process --dry-run --ansi
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@
},
"require-dev": {
"codeception/codeception": "^5.0.11",
"codeception/lib-innerbrowser": "4.0.1",
"codeception/module-asserts": "^3.0.0",
"codeception/module-datafactory": "^3.0.0",
"codeception/module-phpbrowser": "^3.0.0",
"codeception/module-rest": "^3.3.2",
"codeception/module-yii2": "^1.1.9",
"codeception/lib-innerbrowser": "4.0.1",
"craftcms/ecs": "dev-main",
"fakerphp/faker": "^1.19.0",
"league/factory-muffin": "^3.3.0",
"phpstan/phpstan": "^1.10.56",
"rector/rector": "^1.2",
"vlucas/phpdotenv": "^5.4.1",
"yiisoft/yii2-redis": "^2.0"
},
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

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

15 changes: 15 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/lib',
__DIR__ . '/src',
])
->withSkip([
__DIR__ . '/src/icons/index.php',
])
->withPhpSets(php56: true);
2 changes: 1 addition & 1 deletion src/base/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ private function _valueSql(?string $key): ?string
}

if ($key !== null && (!is_array($dbType) || !isset($dbType[$key]))) {
throw new InvalidArgumentException(sprintf('%s doesn’t store values under the key “%s”.', __CLASS__, $key));
throw new InvalidArgumentException(sprintf('%s doesn’t store values under the key “%s”.', self::class, $key));
}

$db = Craft::$app->getDb();
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ConfigSyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function initialState(bool $force = false): array
*/
protected function postComposerInstallState(): array
{
throw new NotSupportedException('postComposerInstallState() is not supported by ' . __CLASS__);
throw new NotSupportedException('postComposerInstallState() is not supported by ' . self::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/elements/GlobalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function defineBehaviors(): array
$behaviors = parent::defineBehaviors();
$behaviors['fieldLayout'] = [
'class' => FieldLayoutBehavior::class,
'elementType' => __CLASS__,
'elementType' => self::class,
];
return $behaviors;
}
Expand Down
2 changes: 1 addition & 1 deletion src/elements/db/ElementQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public function __set($name, $value)
*/
public function __toString()
{
return __CLASS__;
return self::class;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(string $html, array $config = [])
*/
public function selectorHtml(): string
{
throw new NotSupportedException(sprintf('%s should not be included in user-modifyable field layouts.', __CLASS__));
throw new NotSupportedException(sprintf('%s should not be included in user-modifyable field layouts.', self::class));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/addresses/AddressField.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function selectorLabel(): ?string
public function formHtml(ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Address) {
throw new InvalidArgumentException(sprintf('%s can only be used in address field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in address field layouts.', self::class));
}

$view = Craft::$app->getView();
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/addresses/CountryCodeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function defaultLabel(?ElementInterface $element = null, bool $static = f
protected function inputHtml(?ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Address) {
throw new InvalidArgumentException(sprintf('%s can only be used in address field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in address field layouts.', self::class));
}

return
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/addresses/LatLongField.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function selectorLabel(): ?string
protected function inputHtml(ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Address) {
throw new InvalidArgumentException(sprintf('%s can only be used in address field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in address field layouts.', self::class));
}

return
Expand Down
4 changes: 2 additions & 2 deletions src/fieldlayoutelements/assets/AltField.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function defaultLabel(?ElementInterface $element = null, bool $static = f
protected function translatable(?ElementInterface $element = null, bool $static = false): bool
{
if (!$element instanceof Asset) {
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', self::class));
}

return $element->getVolume()->altTranslationMethod !== Field::TRANSLATION_METHOD_NONE;
Expand All @@ -123,7 +123,7 @@ protected function translatable(?ElementInterface $element = null, bool $static
protected function translationDescription(?ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Asset) {
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', self::class));
}

return ElementHelper::translationDescription($element->getVolume()->altTranslationMethod);
Expand Down
4 changes: 2 additions & 2 deletions src/fieldlayoutelements/assets/AssetTitleField.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AssetTitleField extends TitleField
protected function translatable(?ElementInterface $element = null, bool $static = false): bool
{
if (!$element instanceof Asset) {
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', self::class));
}

return $element->getVolume()->titleTranslationMethod !== Field::TRANSLATION_METHOD_NONE;
Expand All @@ -40,7 +40,7 @@ protected function translatable(?ElementInterface $element = null, bool $static
protected function translationDescription(?ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Asset) {
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in asset field layouts.', self::class));
}

return ElementHelper::translationDescription($element->getVolume()->titleTranslationMethod);
Expand Down
6 changes: 3 additions & 3 deletions src/fieldlayoutelements/entries/EntryTitleField.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function fields(): array
protected function translatable(?ElementInterface $element = null, bool $static = false): bool
{
if (!$element instanceof Entry) {
throw new InvalidArgumentException(sprintf('%s can only be used in entry field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in entry field layouts.', self::class));
}

return $element->getType()->titleTranslationMethod !== Field::TRANSLATION_METHOD_NONE;
Expand All @@ -72,7 +72,7 @@ protected function translatable(?ElementInterface $element = null, bool $static
protected function translationDescription(?ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Entry) {
throw new InvalidArgumentException(sprintf('%s can only be used in entry field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in entry field layouts.', self::class));
}

return ElementHelper::translationDescription($element->getType()->titleTranslationMethod);
Expand All @@ -84,7 +84,7 @@ protected function translationDescription(?ElementInterface $element = null, boo
public function inputHtml(?ElementInterface $element = null, bool $static = false): ?string
{
if (!$element instanceof Entry) {
throw new InvalidArgumentException(sprintf('%s can only be used in entry field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in entry field layouts.', self::class));
}

if (!$element->getType()->hasTitleField) {
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/users/AffiliatedSiteField.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function instructions(ElementInterface $element = null, bool $static =
protected function inputHtml(?ElementInterface $element = null, bool $static = false): ?string
{
if ($element && !$element instanceof User) {
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', self::class));
}

if (!Craft::$app->getIsMultiSite()) {
Expand Down
4 changes: 2 additions & 2 deletions src/fieldlayoutelements/users/EmailField.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function inputHtml(?ElementInterface $element = null, bool $static = f
{
if ($element) {
if (!$element instanceof User) {
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', self::class));
}

if (
Expand All @@ -139,7 +139,7 @@ protected function inputHtml(?ElementInterface $element = null, bool $static = f
protected function inputAttributes(?ElementInterface $element = null, bool $static = false): array
{
if (!$element instanceof User) {
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', self::class));
}

return [
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/users/FullNameField.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FullNameField extends BaseFullNameField
protected function inputAttributes(?ElementInterface $element = null, bool $static = false): array
{
if (!$element instanceof User) {
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', self::class));
}

return [
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/users/PhotoField.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function defaultLabel(?ElementInterface $element = null, bool $static = f
protected function inputHtml(?ElementInterface $element = null, bool $static = false): ?string
{
if ($element && !$element instanceof User) {
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', self::class));
}

if (!$element?->id) {
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/users/UsernameField.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function inputHtml(?ElementInterface $element = null, bool $static = f
protected function inputAttributes(?ElementInterface $element = null, bool $static = false): array
{
if (!$element instanceof User) {
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', __CLASS__));
throw new InvalidArgumentException(sprintf('%s can only be used in user field layouts.', self::class));
}

return [
Expand Down
2 changes: 1 addition & 1 deletion src/queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ private function _lock(callable $callback, ?int $timeout = null, bool $throwExce

if ($acquireLock) {
$channel = $this->channel();
$mutexName = sprintf('%s::%s', __CLASS__, $channel);
$mutexName = sprintf('%s::%s', self::class, $channel);
if (!$this->mutex->acquire($mutexName, $timeout ?? $this->mutexTimeout)) {
if ($throwException) {
throw new MutexException($mutexName, "Could not acquire a mutex lock for the queue ($channel).");
Expand Down
2 changes: 1 addition & 1 deletion src/records/VolumeFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function tableName(): string
*/
public function getParent(): ActiveQueryInterface
{
return $this->hasOne(__CLASS__, ['id' => 'parentId']);
return $this->hasOne(self::class, ['id' => 'parentId']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/services/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function __construct($config = [])
{
if (isset($config['maxBackups'])) {
$config['maxDeltas'] = ArrayHelper::remove($config, 'maxBackups');
Craft::$app->getDeprecator()->log(__CLASS__ . '::maxBackups', '`' . __CLASS__ . '::maxBackups` has been deprecated. Use `maxDeltas` instead.');
Craft::$app->getDeprecator()->log(self::class . '::maxBackups', '`' . self::class . '::maxBackups` has been deprecated. Use `maxDeltas` instead.');
}

parent::__construct($config);
Expand Down

0 comments on commit 15b60f3

Please sign in to comment.