Skip to content

Commit

Permalink
✨ feat: update coding standards
Browse files Browse the repository at this point in the history
- Update rector
- Update phpstan
  • Loading branch information
Cambis committed Sep 11, 2024
1 parent ecbb4a8 commit 4598487
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-balloons-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"silverstripe-browser-update": major
---

Major release
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,4 +27,6 @@
])
->withSkip([
NotOperatorWithSuccessorSpaceFixer::class,
// See: https://github.com/silverstripe/silverstripe-standards/issues/8
SelfAccessorFixer::class,
]);
19 changes: 17 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 9
paths:
Expand All @@ -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:
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 12 additions & 11 deletions src/Model/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -128,7 +128,7 @@ public function getCMSFields(): FieldList
$gridFieldConfig
);

self::removeMessageFields($fields);
Announcement::removeMessageFields($fields);

$fields->removeByName([
'Sort',
Expand All @@ -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).'),
Expand Down Expand Up @@ -173,6 +173,7 @@ public function getCMSFields(): FieldList

$this->extend('updateCMSFields', $fields);

/** @phpstan-ignore-next-line return.type */
return $fields;
}

Expand All @@ -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,
];
Expand Down
17 changes: 9 additions & 8 deletions src/Model/BrowserVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*/
Expand Down Expand Up @@ -79,7 +79,7 @@ public function getCMSFields(): FieldList
{
$fields = parent::getCMSFields();

self::removeMessageFields($fields);
BrowserVersion::removeMessageFields($fields);

$fields->removeByName([
'AnnouncementID',
Expand All @@ -99,11 +99,12 @@ public function getCMSFields(): FieldList
'If 0 is selected then the latest version of the browser required.' .
'</p>'
),
self::getMessageCompositeField(),
BrowserVersion::getMessageCompositeField(),
]);

$this->extend('updateCMSFields', $fields);

/** @phpstan-ignore-next-line return.type */
return $fields;
}

Expand Down

0 comments on commit 4598487

Please sign in to comment.