From 459848711c880197730c4b62d6be008da28ef91a Mon Sep 17 00:00:00 2001 From: Cameron Bryers <12287346+Cambis@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:11:44 +1200 Subject: [PATCH] :sparkles: feat: update coding standards - Update rector - Update phpstan --- .changeset/early-balloons-add.md | 5 +++++ composer.json | 2 +- ecs.php | 3 +++ phpstan.neon.dist | 19 +++++++++++++++++-- rector.php | 4 +++- src/Enum/Browser.php | 2 +- src/Model/Announcement.php | 23 ++++++++++++----------- src/Model/BrowserVersion.php | 17 +++++++++-------- 8 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 .changeset/early-balloons-add.md diff --git a/.changeset/early-balloons-add.md b/.changeset/early-balloons-add.md new file mode 100644 index 0000000..d155de2 --- /dev/null +++ b/.changeset/early-balloons-add.md @@ -0,0 +1,5 @@ +--- +"silverstripe-browser-update": major +--- + +Major release diff --git a/composer.json b/composer.json index f84091d..82e76b1 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "silverstripe/siteconfig": "^4.0 || ^5.0" }, "require-dev": { - "cambis/silverstripe-rector": "^0.5.0", + "cambis/silverstripe-rector": "^0.6", "ergebnis/composer-normalize": "^2.42", "php-parallel-lint/php-parallel-lint": "^1.4", "phpstan/extension-installer": "^1.3", diff --git a/ecs.php b/ecs.php index 9630d63..c55be91 100644 --- a/ecs.php +++ b/ecs.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer; use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff; use Symplify\EasyCodingStandard\Config\ECSConfig; @@ -26,4 +27,6 @@ ]) ->withSkip([ NotOperatorWithSuccessorSpaceFixer::class, + // See: https://github.com/silverstripe/silverstripe-standards/issues/8 + SelfAccessorFixer::class, ]); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 23b164e..a4535f0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,5 @@ +includes: + - phar://phpstan.phar/conf/bleedingEdge.neon parameters: level: 9 paths: @@ -15,8 +17,6 @@ parameters: universalObjectCratesClasses: - SilverStripe\Core\Config\Config_ForClass - SilverStripe\Forms\GridField\GridState_Data - - SilverStripe\ORM\DataObjectInterface - - SilverStripe\View\ArrayData - SilverStripe\View\ViewableData - Symbiote\QueuedJobs\Services\AbstractQueuedJob ignoreErrors: @@ -62,3 +62,18 @@ parameters: message: "#^Access to an undefined property DNADesign\\\\BrowserUpdate\\\\Extension\\\\SiteConfigExtension\\:\\:\\$BrowserAnnouncementID\\.$#" count: 1 path: tests/php/View/TemplateProviderTest.php + + - + message: "#^Class DNADesign\\\\BrowserUpdate\\\\Extension\\\\SiteConfigExtension @extends tag contains unresolvable type\\.$#" + count: 1 + path: src/Extension/SiteConfigExtension.php + + - + message: "#^PHPDoc tag @var with type DNADesign\\\\BrowserUpdate\\\\Extension\\\\SiteConfigExtension is not subtype of type SilverStripe\\\\SiteConfig\\\\SiteConfig\\.$#" + count: 1 + path: src/View/TemplateProvider.php + + - + message: "#^PHPDoc tag @var with type DNADesign\\\\BrowserUpdate\\\\Extension\\\\SiteConfigExtension is not subtype of type SilverStripe\\\\SiteConfig\\\\SiteConfig\\.$#" + count: 1 + path: tests/php/View/TemplateProviderTest.php diff --git a/rector.php b/rector.php index 41305f9..27df8b5 100644 --- a/rector.php +++ b/rector.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Cambis\SilverstripeRector\Set\ValueObject\SilverstripeLevelSetList; +use Cambis\SilverstripeRector\Set\ValueObject\SilverstripeSetList; use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php83\Rector\ClassConst\AddTypeToConstRector; @@ -20,14 +21,15 @@ ]) ->withSets([ LevelSetList::UP_TO_PHP_83, + SilverstripeLevelSetList::UP_TO_SILVERSTRIPE_52, SetList::CODE_QUALITY, SetList::CODING_STYLE, SetList::DEAD_CODE, SetList::EARLY_RETURN, SetList::PRIVATIZATION, + SilverstripeSetList::CODE_QUALITY, PHPUnitSetList::PHPUNIT_90, PHPUnitSetList::PHPUNIT_CODE_QUALITY, - SilverstripeLevelSetList::UP_TO_SILVERSTRIPE_52, ])->withSkip([ ClosureToArrowFunctionRector::class, // These may cause a downgrade to fail diff --git a/src/Enum/Browser.php b/src/Enum/Browser.php index af20fdc..36fa726 100644 --- a/src/Enum/Browser.php +++ b/src/Enum/Browser.php @@ -21,7 +21,7 @@ public static function getDropdownFieldOptions(): array { $options = []; - foreach (self::cases() as $case) { + foreach (Browser::cases() as $case) { $options[$case->value] = $case->name; } diff --git a/src/Model/Announcement.php b/src/Model/Announcement.php index e2167a3..8fab90c 100644 --- a/src/Model/Announcement.php +++ b/src/Model/Announcement.php @@ -18,18 +18,18 @@ use SilverStripe\Security\PermissionProvider; /** - * @property string $Name - * @property string $Msg - * @property string $Msgmore - * @property string $Bupdate - * @property string $Bignore - * @property string $Remind - * @property string $Bnever + * @property ?string $Name + * @property ?string $Msg + * @property ?string $Msgmore + * @property ?string $Bupdate + * @property ?string $Bignore + * @property ?string $Remind + * @property ?string $Bnever * @property int $Reminder * @property int $ReminderClosed * @property bool $Test * @property bool $NewWindow - * @property string $Url + * @property ?string $Url * @property bool $NoClose * @property bool $NoMessage * @property bool $NoPermanentHide @@ -128,7 +128,7 @@ public function getCMSFields(): FieldList $gridFieldConfig ); - self::removeMessageFields($fields); + Announcement::removeMessageFields($fields); $fields->removeByName([ 'Sort', @@ -138,7 +138,7 @@ public function getCMSFields(): FieldList $fields->addFieldsToTab('Root.Main', [ TextField::create('Name', 'Name') ->setDescription('For CMS reference only.'), - self::getMessageCompositeField(), + Announcement::getMessageCompositeField(), $gridField, NumericField::create('Reminder', 'reminder') ->setDescription('After how many hours should the message reappear (0 = show all the time).'), @@ -173,6 +173,7 @@ public function getCMSFields(): FieldList $this->extend('updateCMSFields', $fields); + /** @phpstan-ignore-next-line return.type */ return $fields; } @@ -193,7 +194,7 @@ public function getBrowserUpdateConfig(): array 'url' => $this->Url, 'noclose' => $this->NoClose, 'no_permanent_hide' => $this->NoPermanentHide, - 'api' => self::config()->get('browser_update_api_version'), + 'api' => Announcement::config()->get('browser_update_api_version'), 'insecure' => $this->Insecure, 'unsupported' => $this->Unsupported, ]; diff --git a/src/Model/BrowserVersion.php b/src/Model/BrowserVersion.php index 509d8d0..e72a448 100644 --- a/src/Model/BrowserVersion.php +++ b/src/Model/BrowserVersion.php @@ -16,12 +16,12 @@ /** * @property string $Browser * @property float $Version - * @property string $Msg - * @property string $Msgmore - * @property string $Bupdate - * @property string $Bignore - * @property string $Remind - * @property string $Bnever + * @property ?string $Msg + * @property ?string $Msgmore + * @property ?string $Bupdate + * @property ?string $Bignore + * @property ?string $Remind + * @property ?string $Bnever * @property int $AnnouncementID * @method Announcement Announcement() */ @@ -79,7 +79,7 @@ public function getCMSFields(): FieldList { $fields = parent::getCMSFields(); - self::removeMessageFields($fields); + BrowserVersion::removeMessageFields($fields); $fields->removeByName([ 'AnnouncementID', @@ -99,11 +99,12 @@ public function getCMSFields(): FieldList 'If 0 is selected then the latest version of the browser required.' . '

' ), - self::getMessageCompositeField(), + BrowserVersion::getMessageCompositeField(), ]); $this->extend('updateCMSFields', $fields); + /** @phpstan-ignore-next-line return.type */ return $fields; }