Skip to content

Commit

Permalink
Merge pull request #85 from skaut/slevomat-coding-standard
Browse files Browse the repository at this point in the history
Added slevomat coding standard
  • Loading branch information
marekdedic authored Dec 23, 2023
2 parents 3983ea4 + b63957b commit 3f91461
Show file tree
Hide file tree
Showing 48 changed files with 323 additions and 130 deletions.
15 changes: 9 additions & 6 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
* @package wordpress-stubs
*/

declare(strict_types = 1);

return array(
'target_php_version' => '7.3',
'backward_compatibility_checks' => false, // Covered by PHPCS.
'warn_about_redundant_use_namespaced_class' => true,
// Covered by PHPCS.
'backward_compatibility_checks' => false,
'directory_list' => array(
'stubs',
'.phan',
),
'suppress_issue_types' => array(
'PhanTypeMissingReturn',
),
'plugins' => array(
'PreferNamespaceUsePlugin',
'SuspiciousParamOrderPlugin',
'UnusedSuppressionPlugin',
),
'suppress_issue_types' => array(
'PhanTypeMissingReturn',
),
'target_php_version' => '7.3',
'warn_about_redundant_use_namespaced_class' => true,
);
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"squizlabs/php_codesniffer": "^3.0",
"wp-coding-standards/wpcs": "^3.0",
"phan/phan": "^5.0",
"phpstan/phpstan": "^1.4"
"phpstan/phpstan": "^1.4",
"slevomat/coding-standard": "^8.14"
},
"scripts": {
"phpcs": "phpcs",
Expand Down
67 changes: 66 additions & 1 deletion composer.lock

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

48 changes: 48 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,52 @@
<property name="blank_line_check" value="true"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard">
<!-- Incompatible with PHP version requirements -->
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>

<!-- Conflicts with WPCS -->
<exclude name="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces.NoEmptyLineBeforeClosingBrace"/>
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName"/>
<exclude name="SlevomatCodingStandard.Whitespaces.DuplicateSpaces.DuplicateSpaces"/>

<!-- Covered by PHPMD -->
<exclude name="SlevomatCodingStandard.Files.FunctionLength.FunctionLength"/>
<exclude name="SlevomatCodingStandard.Functions.FunctionLength.FunctionLength"/>

<!-- Not applicable to stubs -->
<exclude name="SlevomatCodingStandard.Classes.ForbiddenPublicProperty.ForbiddenPublicProperty"/>
<exclude name="SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousErrorNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Functions.DisallowEmptyFunction.EmptyFunction"/>
<exclude name="SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter"/>
<exclude name="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint.UselessDocComment"/>

<!-- Disabled due to style preferences -->
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes"/>
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment"/>
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment.MultiLinePropertyComment"/>
<exclude name="SlevomatCodingStandard.Files.FileLength.FileTooLong"/>
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration.MissingTrailingComma"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions.NonFullyQualifiedException"/>
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces.NonFullyQualified"/>
<exclude name="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint"/>
</rule>

<rule ref="SlevomatCodingStandard.Attributes.AttributesOrder">
<properties>
<property name="orderAlphabetically" value="true" />
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Files.LineLength">
<properties>
<property name="ignoreComments" value="true"/>
</properties>
</rule>
</ruleset>
3 changes: 3 additions & 0 deletions stubs/PHPUnit/Framework/class-assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* @package wordpress-stubs
*/

declare(strict_types = 1);

namespace PHPUnit\Framework;

class Assert {

/**
* @param string $expected
* @param mixed $actual
Expand Down
3 changes: 3 additions & 0 deletions stubs/PHPUnit/Framework/class-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* @package wordpress-stubs
*/

declare(strict_types = 1);

namespace PHPUnit\Framework;

class TestCase extends Assert {

}
9 changes: 6 additions & 3 deletions stubs/WordPress-test/class-wp-unittestcase-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* @package wordpress-stubs
*/

/**
*/
class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
declare(strict_types = 1);

use PHPUnit\Framework\TestCase;

class WP_UnitTestCase_Base extends TestCase {

}
5 changes: 3 additions & 2 deletions stubs/WordPress-test/class-wp-unittestcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @package wordpress-stubs
*/

/**
*/
declare(strict_types = 1);

class WP_UnitTestCase extends WP_UnitTestCase_Base {

}
2 changes: 2 additions & 0 deletions stubs/WordPress-test/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @package wordpress-stubs
*/

declare(strict_types = 1);

/**
* @param string $tag
* @param callable $function_to_add
Expand Down
13 changes: 8 additions & 5 deletions stubs/WordPress/class-requests-cookie-jar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
* @package wordpress-stubs
*/

declare(strict_types = 1);

/**
* @implements ArrayAccess<string, string>
* @implements IteratorAggregate<string, string>
*/
class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {

/**
* @param string $key
*
* @return bool
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetExists( $key ) {
}

Expand All @@ -22,7 +25,7 @@ public function offsetExists( $key ) {
*
* @return string|null
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetGet( $key ) {
}

Expand All @@ -32,7 +35,7 @@ public function offsetGet( $key ) {
*
* @return void
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetSet( $key, $value ) {
}

Expand All @@ -41,14 +44,14 @@ public function offsetSet( $key, $value ) {
*
* @return void
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetUnset( $key ) {
}

/**
* @return ArrayIterator<string, string>
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function getIterator() {
}
}
5 changes: 3 additions & 2 deletions stubs/WordPress/class-requests-exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @package wordpress-stubs
*/

/**
*/
declare(strict_types = 1);

class Requests_Exception extends Exception {

}
5 changes: 3 additions & 2 deletions stubs/WordPress/class-requests-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* @package wordpress-stubs
*/

/**
*/
declare(strict_types = 1);

class Requests_Response {

/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
* @package wordpress-stubs
*/

declare(strict_types = 1);

/**
* @implements ArrayAccess<string, string>
* @implements IteratorAggregate<string, string>
*/
class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {

/**
* @param string $key
*
* @return bool
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetExists( $key ) {
}

Expand All @@ -22,7 +25,7 @@ public function offsetExists( $key ) {
*
* @return string|null
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetGet( $key ) {
}

Expand All @@ -32,7 +35,7 @@ public function offsetGet( $key ) {
*
* @return void
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetSet( $key, $value ) {
}

Expand All @@ -41,14 +44,14 @@ public function offsetSet( $key, $value ) {
*
* @return void
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetUnset( $key ) {
}

/**
* @return ArrayIterator<string, string>
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function getIterator() {
}
}
5 changes: 3 additions & 2 deletions stubs/WordPress/class-requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* @package wordpress-stubs
*/

/**
*/
declare(strict_types = 1);

class Requests {

/**
* @param array<int|string, array{url: string, headers?: array<string, string>, data?: array<int|string, string>|string, type?: string, cookies?: array<string, string>|Requests_Cookie_Jar}> $requests
* @param array{timeout?: float, connect_timeout?: float, useragent?: string, follow_redirects?: bool, redirects?: int, blocking?: bool, filename?: string|bool, auth?: Requests_Auth|array<string>|bool, proxy?: Requests_Proxy|array<string>|string|bool, max_bytes?: int|bool, idn?: bool, transport?: string|Requests_Transport, hooks?: Requests_Hooker, verify?: string|bool, verifyname?: bool, data_format?: string, complete?: callable} $options {
Expand Down
5 changes: 3 additions & 2 deletions stubs/WordPress/class-wp-admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* @package wordpress-stubs
*/

/**
*/
declare(strict_types = 1);

class WP_Admin_Bar {

/**
* @param array{id: string, title?: string, parent?: string, href?: string, group?: bool, meta?: array{html?: string, class?: string, rel?: string, onclick?: string, target?: string, title?: string, tabindex?: string}} $node {
* @type string $id
Expand Down
Loading

0 comments on commit 3f91461

Please sign in to comment.