Skip to content

Commit fefbd82

Browse files
authored
Add code style enforcement and GitHub Actions workflow for tests (#3)
* Add PHP_CodeSniffer and fix code style * Add test pipeline and SonarQube analysis * Fix job name of workflow
1 parent 082f2f2 commit fefbd82

File tree

5 files changed

+178
-1
lines changed

5 files changed

+178
-1
lines changed

.github/workflows/tests.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
test-all:
12+
name: Test PHP ${{ matrix.php-version }}
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
php-version: ['7.4', '8.0']
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup PHP ${{ matrix.php-version }}
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php-version }}
29+
tools: phpunit:9.5.0
30+
coverage: pcov
31+
32+
- name: Setup problem matchers for PHP
33+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
34+
35+
- name: Setup problem matchers for PHPUnit
36+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
37+
38+
- name: Get Composer Cache Directory
39+
id: composer-cache
40+
run: |
41+
echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
43+
- name: Cache Composer dependencies
44+
uses: actions/cache@v2
45+
with:
46+
path: ${{ steps.composer-cache.outputs.dir }}
47+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
48+
restore-keys: ${{ runner.os }}-composer-
49+
50+
- name: Install composer dependencies
51+
run: composer install --prefer-dist --ignore-platform-reqs
52+
53+
- name: Run tests
54+
run: composer test
55+
56+
- name: Run SonarQube analysis
57+
uses: sonarsource/sonarcloud-github-action@master
58+
if: matrix.php-version == '8.0'
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}

.phpcs.xml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="php-mqtt Code Style Standard">
3+
<description>php-mqtt Code Style Standard</description>
4+
5+
<rule ref="PSR1"/>
6+
<rule ref="PSR2">
7+
<exclude name="PSR2.Methods.MethodDeclaration.AbstractAfterVisibility"/>
8+
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis"/>
9+
</rule>
10+
11+
<rule ref="Generic.Arrays.ArrayIndent">
12+
<exclude name="Generic.Arrays.ArrayIndent.CloseBraceNotNewLine"/>
13+
</rule>
14+
<rule ref="Generic.Classes.DuplicateClassName"/>
15+
<rule ref="Generic.CodeAnalysis.EmptyStatement">
16+
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
17+
</rule>
18+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
19+
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
20+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
21+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
22+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
23+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
24+
<rule ref="Generic.Commenting.Todo">
25+
<exclude-pattern>src/*</exclude-pattern>
26+
</rule>
27+
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
28+
<rule ref="Generic.Files.ByteOrderMark"/>
29+
<rule ref="Generic.Files.LineEndings"/>
30+
<rule ref="Generic.Files.LineLength">
31+
<properties>
32+
<property name="lineLimit" value="150"/>
33+
<property name="absoluteLineLimit" value="0"/>
34+
</properties>
35+
</rule>
36+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
37+
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
38+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
39+
<rule ref="Generic.Functions.CallTimePassByReference"/>
40+
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
41+
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
42+
<rule ref="Generic.Metrics.CyclomaticComplexity">
43+
<properties>
44+
<property name="complexity" value="50"/>
45+
<property name="absoluteComplexity" value="100"/>
46+
</properties>
47+
</rule>
48+
<rule ref="Generic.Metrics.NestingLevel">
49+
<properties>
50+
<property name="nestingLevel" value="10"/>
51+
<property name="absoluteNestingLevel" value="30"/>
52+
</properties>
53+
</rule>
54+
<rule ref="Generic.NamingConventions.ConstructorName"/>
55+
<rule ref="Generic.PHP.LowerCaseConstant"/>
56+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
57+
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
58+
<rule ref="Generic.PHP.ForbiddenFunctions"/>
59+
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
60+
<rule ref="Generic.WhiteSpace.ScopeIndent">
61+
<properties>
62+
<property name="indent" value="4"/>
63+
</properties>
64+
</rule>
65+
<rule ref="MySource.PHP.EvalObjectFactory"/>
66+
<rule ref="PEAR.Commenting.ClassComment">
67+
<exclude name="PEAR.Commenting.ClassComment.MissingAuthorTag"/>
68+
<exclude name="PEAR.Commenting.ClassComment.MissingCategoryTag"/>
69+
<exclude name="PEAR.Commenting.ClassComment.MissingLicenseTag"/>
70+
<exclude name="PEAR.Commenting.ClassComment.MissingLinkTag"/>
71+
</rule>
72+
<rule ref="PEAR.Commenting.ClassComment.Missing"/>
73+
<rule ref="PEAR.Commenting.ClassComment.MissingPackageTag"/>
74+
<rule ref="PEAR.Commenting.InlineComment"/>
75+
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
76+
<rule ref="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose"/>
77+
<rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast"/>
78+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace">
79+
<exclude-pattern>src/*</exclude-pattern>
80+
</rule>
81+
<rule ref="Zend.Files.ClosingTag"/>
82+
83+
<file>src</file>
84+
85+
<arg name="colors"/>
86+
<arg value="sp"/>
87+
<ini name="memory_limit" value="128M"/>
88+
</ruleset>

composer.json

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"illuminate/support": "~7.0|~8.0",
2525
"php-mqtt/client": "v1.0.0-rc1"
2626
},
27+
"require-dev": {
28+
"squizlabs/php_codesniffer": "^3.5"
29+
},
2730
"autoload": {
2831
"psr-4": {
2932
"PhpMqtt\\Client\\": "src"
@@ -38,5 +41,12 @@
3841
"MQTT": "PhpMqtt\\Client\\Facades\\MQTT"
3942
}
4043
}
44+
},
45+
"scripts": {
46+
"fix:cs": "vendor/bin/phpcbf",
47+
"test": [
48+
"@test:cs"
49+
],
50+
"test:cs": "vendor/bin/phpcs"
4151
}
4252
}

sonar-project.properties

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sonar.organization=php-mqtt
2+
sonar.projectKey=php-mqtt_laravel-client
3+
4+
# Paths are relative to the sonar-project.properties file.
5+
sonar.sources=src
6+
#sonar.tests=tests
7+
8+
# Test report and code coverage related settings.
9+
#sonar.php.tests.reportPath=phpunit.report-junit.xml
10+
#sonar.php.coverage.reportPaths=phpunit.coverage-clover.xml
11+
12+
# Encoding of the source code. Default is default system encoding.
13+
sonar.sourceEncoding=UTF-8
14+
15+
# Links for sonarcloud.io page.
16+
sonar.links.ci=https://github.com/php-mqtt/laravel-client/actions
17+
sonar.links.scm=https://github.com/php-mqtt/laravel-client
18+
sonar.links.issue=https://github.com/php-mqtt/laravel-client/issues

src/Facades/MQTT.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* @method static void disconnect(string $connection = null)
1414
* @method static void publish(string $topic, string $message, bool $retain = false, string $connection = null)
1515
*
16-
* @see ConnectionManager
1716
* @package PhpMqtt\Client\Facades
17+
* @see ConnectionManager
1818
*/
1919
class MQTT extends Facade
2020
{

0 commit comments

Comments
 (0)