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
This commit is contained in:
parent
082f2f25b1
commit
fefbd82c59
|
@ -0,0 +1,61 @@
|
||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-all:
|
||||||
|
name: Test PHP ${{ matrix.php-version }}
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php-version: ['7.4', '8.0']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup PHP ${{ matrix.php-version }}
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php-version }}
|
||||||
|
tools: phpunit:9.5.0
|
||||||
|
coverage: pcov
|
||||||
|
|
||||||
|
- name: Setup problem matchers for PHP
|
||||||
|
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
|
||||||
|
|
||||||
|
- name: Setup problem matchers for PHPUnit
|
||||||
|
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||||
|
|
||||||
|
- name: Get Composer Cache Directory
|
||||||
|
id: composer-cache
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||||
|
|
||||||
|
- name: Cache Composer dependencies
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||||
|
restore-keys: ${{ runner.os }}-composer-
|
||||||
|
|
||||||
|
- name: Install composer dependencies
|
||||||
|
run: composer install --prefer-dist --ignore-platform-reqs
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: composer test
|
||||||
|
|
||||||
|
- name: Run SonarQube analysis
|
||||||
|
uses: sonarsource/sonarcloud-github-action@master
|
||||||
|
if: matrix.php-version == '8.0'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="php-mqtt Code Style Standard">
|
||||||
|
<description>php-mqtt Code Style Standard</description>
|
||||||
|
|
||||||
|
<rule ref="PSR1"/>
|
||||||
|
<rule ref="PSR2">
|
||||||
|
<exclude name="PSR2.Methods.MethodDeclaration.AbstractAfterVisibility"/>
|
||||||
|
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="Generic.Arrays.ArrayIndent">
|
||||||
|
<exclude name="Generic.Arrays.ArrayIndent.CloseBraceNotNewLine"/>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Generic.Classes.DuplicateClassName"/>
|
||||||
|
<rule ref="Generic.CodeAnalysis.EmptyStatement">
|
||||||
|
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
|
||||||
|
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
|
||||||
|
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
|
||||||
|
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
|
||||||
|
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
|
||||||
|
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
|
||||||
|
<rule ref="Generic.Commenting.Todo">
|
||||||
|
<exclude-pattern>src/*</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
|
||||||
|
<rule ref="Generic.Files.ByteOrderMark"/>
|
||||||
|
<rule ref="Generic.Files.LineEndings"/>
|
||||||
|
<rule ref="Generic.Files.LineLength">
|
||||||
|
<properties>
|
||||||
|
<property name="lineLimit" value="150"/>
|
||||||
|
<property name="absoluteLineLimit" value="0"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
|
||||||
|
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
|
||||||
|
<rule ref="Generic.Formatting.SpaceAfterCast"/>
|
||||||
|
<rule ref="Generic.Functions.CallTimePassByReference"/>
|
||||||
|
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
|
||||||
|
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
|
||||||
|
<rule ref="Generic.Metrics.CyclomaticComplexity">
|
||||||
|
<properties>
|
||||||
|
<property name="complexity" value="50"/>
|
||||||
|
<property name="absoluteComplexity" value="100"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Generic.Metrics.NestingLevel">
|
||||||
|
<properties>
|
||||||
|
<property name="nestingLevel" value="10"/>
|
||||||
|
<property name="absoluteNestingLevel" value="30"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Generic.NamingConventions.ConstructorName"/>
|
||||||
|
<rule ref="Generic.PHP.LowerCaseConstant"/>
|
||||||
|
<rule ref="Generic.PHP.DeprecatedFunctions"/>
|
||||||
|
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
|
||||||
|
<rule ref="Generic.PHP.ForbiddenFunctions"/>
|
||||||
|
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
|
||||||
|
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||||
|
<properties>
|
||||||
|
<property name="indent" value="4"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
<rule ref="MySource.PHP.EvalObjectFactory"/>
|
||||||
|
<rule ref="PEAR.Commenting.ClassComment">
|
||||||
|
<exclude name="PEAR.Commenting.ClassComment.MissingAuthorTag"/>
|
||||||
|
<exclude name="PEAR.Commenting.ClassComment.MissingCategoryTag"/>
|
||||||
|
<exclude name="PEAR.Commenting.ClassComment.MissingLicenseTag"/>
|
||||||
|
<exclude name="PEAR.Commenting.ClassComment.MissingLinkTag"/>
|
||||||
|
</rule>
|
||||||
|
<rule ref="PEAR.Commenting.ClassComment.Missing"/>
|
||||||
|
<rule ref="PEAR.Commenting.ClassComment.MissingPackageTag"/>
|
||||||
|
<rule ref="PEAR.Commenting.InlineComment"/>
|
||||||
|
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
|
||||||
|
<rule ref="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose"/>
|
||||||
|
<rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast"/>
|
||||||
|
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace">
|
||||||
|
<exclude-pattern>src/*</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
<rule ref="Zend.Files.ClosingTag"/>
|
||||||
|
|
||||||
|
<file>src</file>
|
||||||
|
|
||||||
|
<arg name="colors"/>
|
||||||
|
<arg value="sp"/>
|
||||||
|
<ini name="memory_limit" value="128M"/>
|
||||||
|
</ruleset>
|
|
@ -24,6 +24,9 @@
|
||||||
"illuminate/support": "~7.0|~8.0",
|
"illuminate/support": "~7.0|~8.0",
|
||||||
"php-mqtt/client": "v1.0.0-rc1"
|
"php-mqtt/client": "v1.0.0-rc1"
|
||||||
},
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"squizlabs/php_codesniffer": "^3.5"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"PhpMqtt\\Client\\": "src"
|
"PhpMqtt\\Client\\": "src"
|
||||||
|
@ -38,5 +41,12 @@
|
||||||
"MQTT": "PhpMqtt\\Client\\Facades\\MQTT"
|
"MQTT": "PhpMqtt\\Client\\Facades\\MQTT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"fix:cs": "vendor/bin/phpcbf",
|
||||||
|
"test": [
|
||||||
|
"@test:cs"
|
||||||
|
],
|
||||||
|
"test:cs": "vendor/bin/phpcs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
sonar.organization=php-mqtt
|
||||||
|
sonar.projectKey=php-mqtt_laravel-client
|
||||||
|
|
||||||
|
# Paths are relative to the sonar-project.properties file.
|
||||||
|
sonar.sources=src
|
||||||
|
#sonar.tests=tests
|
||||||
|
|
||||||
|
# Test report and code coverage related settings.
|
||||||
|
#sonar.php.tests.reportPath=phpunit.report-junit.xml
|
||||||
|
#sonar.php.coverage.reportPaths=phpunit.coverage-clover.xml
|
||||||
|
|
||||||
|
# Encoding of the source code. Default is default system encoding.
|
||||||
|
sonar.sourceEncoding=UTF-8
|
||||||
|
|
||||||
|
# Links for sonarcloud.io page.
|
||||||
|
sonar.links.ci=https://github.com/php-mqtt/laravel-client/actions
|
||||||
|
sonar.links.scm=https://github.com/php-mqtt/laravel-client
|
||||||
|
sonar.links.issue=https://github.com/php-mqtt/laravel-client/issues
|
|
@ -13,8 +13,8 @@ use PhpMqtt\Client\Contracts\MqttClient;
|
||||||
* @method static void disconnect(string $connection = null)
|
* @method static void disconnect(string $connection = null)
|
||||||
* @method static void publish(string $topic, string $message, bool $retain = false, string $connection = null)
|
* @method static void publish(string $topic, string $message, bool $retain = false, string $connection = null)
|
||||||
*
|
*
|
||||||
* @see ConnectionManager
|
|
||||||
* @package PhpMqtt\Client\Facades
|
* @package PhpMqtt\Client\Facades
|
||||||
|
* @see ConnectionManager
|
||||||
*/
|
*/
|
||||||
class MQTT extends Facade
|
class MQTT extends Facade
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue