Skip to content

Commit

Permalink
start with adding phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkeschiren committed Dec 5, 2024
1 parent 28425de commit 09de3b5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/phpcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PHPCS check

on:
pull_request: {}
workflow_dispatch: {}
push:
branches: ["main"]

jobs:
phpcs:
name: PHPCS
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
lfs: false
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: cs2pr
- name: Install dependencies
run:
composer init --name=matomo/rebelmetrics --quiet;
composer --no-plugins config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -n;
composer config repositories.matomo-coding-standards vcs https://github.com/matomo-org/matomo-coding-standards -n;
composer require matomo-org/matomo-coding-standards:dev-master;
composer install --dev --prefer-dist --no-progress --no-suggest
- name: Check PHP code styles
id: phpcs
run: ./vendor/bin/phpcs --report-full --standard=tests/phpcs.xml --report-checkstyle=./phpcs-report.xml
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml --prepend-filename
2 changes: 0 additions & 2 deletions .github/workflows/semgrep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
workflow_dispatch: {}
push:
branches: ["main"]
schedule:
- cron: '05 07 * * *'

jobs:
semgrep:
Expand Down
33 changes: 33 additions & 0 deletions tests/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<ruleset name="rebelMetrics" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<description>Matomo coding standard</description>

<arg name="extensions" value="php" />

<file>.</file>

<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="Matomo"></rule>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="250" />
</properties>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
</rule>

<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<!-- Allow using method name without camel caps in tests as long as some methods are named test_* -->
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<!-- Allow using multiple classes in one file for tests -->
<exclude-pattern>tests/*</exclude-pattern>
</rule>
</ruleset>

0 comments on commit 09de3b5

Please sign in to comment.