Skip to content

Commit

Permalink
Merge pull request #5 from CommonGateway/feature/xz-45/code-sniffer
Browse files Browse the repository at this point in the history
Include codesniffer fixes
  • Loading branch information
rubenvdlinde authored Mar 22, 2023
2 parents 2dbb0c4 + 115b22d commit c0b18cd
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# .github/workflows/documentation.yml
name: Docs

on: [push]
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/phpcbf.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: phpcbf
name: php-cbf

on: [push]
on: [push, pull_request]

jobs:
build:
Expand All @@ -15,4 +15,12 @@ jobs:
tools: cs2pr, phpcbf

- name: Run phpcbf
run: phpcbf -q --report=checkstyle src | cs2pr
run: phpcbf .
continue-on-error: true
- name: Git commit
run: |
git config user.name "GitHub Actions"
git config user.email ""
git add src
git commit -m "Update src from PHP Codesniffer" || echo "No changes to commit"
git push
7 changes: 4 additions & 3 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: phpcs
name: php-cs

on: [push]
on: [push, pull_request]

jobs:
build:
Expand All @@ -15,4 +15,5 @@ jobs:
tools: cs2pr, phpcs

- name: Run phpcs
run: phpcs -q --report=checkstyle src | cs2pr
run: phpcs -q --report=checkstyle src | cs2pr
continue-on-error: true
17 changes: 7 additions & 10 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: phpcs
name: php-unit

on: [push]

Expand All @@ -8,14 +8,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
- uses: php-actions/composer@v6
with:
php-version: '8.2'
tools: cs2pr, phpcs

- name: Install PHPUnit
run: simple-phpunit install

php_version: "7.4"
php_extensions: redis exif
version: 2.x
command: require symfony/test-pack
- name: Run tests
run: simple-phpunit --coverage-text
run: php bin/phpunit --coverage-text
155 changes: 155 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for PHP_CodeSniffer itself, for more config -> for https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options.</description>

<file>README.md</file>
<file>PetStoreBundle.php</file>
<file>src</file>
<file>DependencyInjection</file>

<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>

<!-- Don't hide tokenizer exceptions -->
<rule ref="Internal.Tokenizer.Exception">
<type>error</type>
</rule>

<!-- Include the whole PEAR standard -->
<rule ref="PEAR">
<exclude name="PEAR.NamingConventions.ValidFunctionName"/>
<exclude name="PEAR.NamingConventions.ValidVariableName"/>
<exclude name="PEAR.Commenting.ClassComment"/>
<exclude name="PEAR.Commenting.FileComment.MissingCategoryTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingPackageTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingLinkTag"/>
<exclude name="PEAR.Commenting.FileComment.MissingVersion"/>
<exclude name="PEAR.Commenting.InlineComment"/>
</rule>

<!-- Include some sniffs from other standards that don't conflict with PEAR -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration"/>
<rule ref="Squiz.ControlStructures.ControlSignature"/>
<rule ref="Squiz.ControlStructures.ElseIfDeclaration"/>
<rule ref="Squiz.Commenting.ClosingDeclarationComment"/>
<rule ref="Squiz.Commenting.BlockComment"/>
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<rule ref="Squiz.Commenting.EmptyCatchComment"/>
<rule ref="Squiz.Commenting.InlineComment"/>
<rule ref="Squiz.Commenting.LongConditionClosingComment"/>
<rule ref="Squiz.Commenting.PostStatementComment"/>
<rule ref="Squiz.Commenting.VariableComment"/>
<rule ref="Squiz.Formatting.OperatorBracket"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"/>
<rule ref="Squiz.Operators.ComparisonOperatorUsage"/>
<rule ref="Squiz.PHP.DisallowInlineIf"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Strings.ConcatenationSpacing"/>
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing"/>
<rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace"/>
<rule ref="Squiz.WhiteSpace.FunctionSpacing"/>
<properties>
<property name="spacing" value="1"/>
<property name="spacingAfterLast" value="0"/>
<property name="spacingBeforeFirst" value="0"/>
</properties>
<rule ref="Squiz.WhiteSpace.MemberVarSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.DisallowYodaConditions"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
<rule ref="PSR2.Classes.PropertyDeclaration"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Files.EndFileNewline"/>
<rule ref="PSR12.Files.OpenTag"/>
<rule ref="Zend.Files.ClosingTag"/>

<!-- PEAR uses warnings for inline control structures, so switch back to errors -->
<rule ref="Generic.ControlStructures.InlineControlStructure">
<properties>
<property name="error" value="true"/>
</properties>
</rule>

<!-- We use custom indent rules for arrays -->
<rule ref="Generic.Arrays.ArrayIndent"/>
<rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNewLine">
<severity>0</severity>
</rule>

<!-- Check var names, but we don't want leading underscores for private vars -->
<rule ref="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
<severity>0</severity>
</rule>

<!-- Only one argument per line in multi-line function calls -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>

<!-- Have 12 chars padding maximum and always show as errors -->
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="maxPadding" value="12"/>
<property name="error" value="true"/>
</properties>
</rule>

<!-- Ban some functions -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="is_null" value="null"/>
<element key="create_function" value="null"/>
<element key="var_dump" value="null"/>
</property>
</properties>
</rule>

<!-- Private methods MUST not be prefixed with an underscore -->
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<type>error</type>
</rule>

<!-- Private properties MUST not be prefixed with an underscore -->
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<type>error</type>
</rule>

<!-- The testing bootstrap file uses string concats to stop IDEs seeing the class aliases -->
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>
</rule>

<!-- This test file specifically *needs* Windows line endings for testing purposes. -->
<rule ref="Generic.Files.LineEndings.InvalidEOLChar">
<exclude-pattern>tests/Core/Tokenizer/StableCommentWhitespaceWinTest\.php</exclude-pattern>
</rule>

</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
*/
class PetStoreHandler
{

/**
* @var PetStoreService
*/
private PetStoreService $petStoreService;


/**
* @param PetStoreService $petStoreService
*/
public function __construct(PetStoreService $petStoreService)
{
$this->petStoreService = $petStoreService;

}//end __construct()


/**
* This function returns the requered configuration as a [json-schema](https://json-schema.org/) array.
*
Expand All @@ -37,8 +41,10 @@ public function getConfiguration(): array
'required' => [],
'properties' => [],
];

}//end getConfiguration()


/**
* This function runs the service.
*
Expand All @@ -55,5 +61,8 @@ public function getConfiguration(): array
public function run(array $data, array $configuration): array
{
return $this->petStoreService->petStoreHandler($data, $configuration);

}//end run()


}//end class
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
class PetStoreService
{


/**
* An example handler that is triggerd by an action.
*
Expand All @@ -18,5 +20,8 @@ class PetStoreService
public function petStoreHandler(array $data, array $configuration): array
{
return ['response' => 'Hello. Your PetStoreBundle works'];

}//end petStoreHandler()


}//end class

0 comments on commit c0b18cd

Please sign in to comment.