Skip to content

Commit

Permalink
PHPCS: Implement StaticClosure rule (#12908)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Jan 9, 2023
1 parent 789970c commit 1898c43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
47 changes: 19 additions & 28 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,21 @@
<!-- Reports useless @var annotation for constants because the type of constant is always clear. -->
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint" />

<!-- Enforces correct space usage in array functions. -->
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
<properties>
<property name="spacesCountAfterKeyword" value="0" />
<property name="spacesCountBeforeArrow" value="1" />
<property name="spacesCountAfterArrow" value="1" />
<property name="allowMultiLine" value="true" />
</properties>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<exclude-pattern>web-stories.php</exclude-pattern>
<exclude-pattern>includes/compat/*</exclude-pattern>
<exclude-pattern>includes/templates/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude-pattern>web-stories.php</exclude-pattern>
<exclude-pattern>includes/compat/*</exclude-pattern>
<properties>
<property name="enableMixedTypeHint" value="false" />
<property name="enableUnionTypeHint" value="false" />
<property name="enableIntersectionTypeHint" value="false" />
<property name="enableStandaloneNullTrueFalseTypeHints" value="false" />
</properties>
</rule>

<!-- Disallows grouped use declarations. -->
Expand Down Expand Up @@ -200,12 +207,7 @@
<property name="allowMultiLine" value="true"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<exclude-pattern>web-stories.php</exclude-pattern>
<exclude-pattern>includes/compat/*</exclude-pattern>
<exclude-pattern>includes/templates/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />

<!-- Class names should be referenced via ::class constant when possible. -->
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference">
Expand All @@ -214,14 +216,14 @@
</properties>
</rule>

<!-- Requires declaring visibility for class constants. -->
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility" />

<rule ref="SlevomatCodingStandard.PHP">
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion" />
<exclude name="SlevomatCodingStandard.PHP.DisallowReference" />
</rule>

<!-- Requires declaring visibility for class constants. -->
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility" />

<rule ref="SlevomatCodingStandard.Variables">
<exclude name="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable" />
</rule>
Expand All @@ -231,17 +233,6 @@
ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"
/>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude-pattern>web-stories.php</exclude-pattern>
<exclude-pattern>includes/compat/*</exclude-pattern>
<properties>
<property name="enableMixedTypeHint" value="false" />
<property name="enableUnionTypeHint" value="false" />
<property name="enableIntersectionTypeHint" value="false" />
<property name="enableStandaloneNullTrueFalseTypeHints" value="false" />
</properties>
</rule>

<!-- Reports forbidden annotations. -->
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/integration/tests/AMP/Sanitization.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public function test_get_sanitizers_with_dev_mode(): void {
$validation_error_callback = [ $this->instance, 'validation_error_callback' ];
add_filter(
'web_stories_amp_dev_mode_element_xpaths',
fn( $xpaths ) => array_merge( $xpaths, $element_xpaths )
static fn( $xpaths ) => array_merge( $xpaths, $element_xpaths )
);

// Check that AMP_Dev_Mode_Sanitizer is not registered if not in dev mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function test_it_can_return_the_actual_service_it_represents(): void {
}

public function test_it_throws_when_instantiating_an_invalid_service(): void {
$callable = fn() => new stdClass();
$callable = static fn() => new stdClass();
$lazy_service = new LazilyInstantiatedService( $callable );

$this->expectException( InvalidService::class );
Expand Down

0 comments on commit 1898c43

Please sign in to comment.