Skip to content

Commit

Permalink
Merge pull request #47 from matomo-org/spice-psr
Browse files Browse the repository at this point in the history
Adds test for PHPCS
  • Loading branch information
snake14 authored Oct 20, 2024
2 parents 48db268 + b02c5c3 commit 62fe312
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PHPCS check

on: pull_request

permissions:
actions: read
checks: read
contents: read
deployments: none
issues: read
packages: none
pull-requests: read
repository-projects: none
security-events: none
statuses: read

jobs:
phpcs:
name: PHPCS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: false
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr
- name: Install dependencies
run:
composer init --name=matomo/taskstimetable --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=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
7 changes: 2 additions & 5 deletions Controller.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\TasksTimetable;

use Piwik\Common;
Expand All @@ -20,7 +22,6 @@
*/
class Controller extends \Piwik\Plugin\ControllerAdmin
{

public function index()
{
Piwik::checkUserHasSuperUserAccess();
Expand Down Expand Up @@ -57,7 +58,6 @@ public function index()
$view->tasks = $tasksFormatted;

return $view->render();

}

/**
Expand All @@ -71,6 +71,3 @@ protected function getFormattedDatetime($timestamp)
return Date::factory($timestamp)->getLocalized($dateFormat) . ' ' . Date::factory($timestamp)->getLocalized(' h:mm:ss');
}
}



2 changes: 2 additions & 0 deletions Menu.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\TasksTimetable;

use Piwik\Menu\MenuAdmin;
Expand Down
5 changes: 3 additions & 2 deletions TasksTimetable.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\TasksTimetable;

/**
*
*/
class TasksTimetable extends \Piwik\Plugin
{

public function registerEvents()
{
return [
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
];
];
}

public function getClientSideTranslationKeys(&$translations)
Expand Down
36 changes: 36 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<ruleset name="tasksTimetable" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<description>Matomo Coding Standard for TasksTimetable plugin</description>

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

<file>.</file>

<exclude-pattern>tests/javascript/*</exclude-pattern>
<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">
<!-- Classnames for our update files don't match PascalCase, this can't be changed easily -->
<exclude-pattern>Updates/*</exclude-pattern>
</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>
4 changes: 3 additions & 1 deletion tests/Fixtures/FakeTasksFixture.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\TasksTimetable\tests\Fixtures;

use Piwik\Date;
Expand Down Expand Up @@ -32,4 +34,4 @@ public function setUp(): void

Option::set('TaskScheduler.timetable', serialize($fakeTasks));
}
}
}
3 changes: 2 additions & 1 deletion tests/System/CheckDirectDependencyUseCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Piwik - free/libre analytics platform
*
Expand Down Expand Up @@ -44,4 +45,4 @@ public function testCommand()
],
], $checkDirectDependencyUse->usesFoundList[$pluginName]);
}
}
}

0 comments on commit 62fe312

Please sign in to comment.