Skip to content

Commit

Permalink
Merge pull request #127 from ember-nexus/github-issue/114
Browse files Browse the repository at this point in the history
Add PHP Mess Detector, closes #114.
  • Loading branch information
Syndesi authored Sep 17, 2023
2 parents 1929ebc + 3fe88dd commit 6e50036
Show file tree
Hide file tree
Showing 28 changed files with 285 additions and 12 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,29 @@ jobs:
with:
name: docker-image-api-dev-amd
path: /tmp/docker
- name: Mutant Test
- name: Leak Test
run: |
docker load < /tmp/docker/api-dev-amd.tar.gz
docker run -v $(pwd):/var/www/html api:dev-amd sh -c "composer install --quiet && composer test:leak"
test-mess-detector:
runs-on: ubuntu-latest
name: 'Mess Detector'
needs:
- build-docker-image
continue-on-error: true
steps:
- uses: actions/checkout@v3
- run: mkdir -p /tmp/docker
- uses: actions/download-artifact@v3
with:
name: docker-image-api-dev-amd
path: /tmp/docker
- name: Mess Detector
run: |
docker load < /tmp/docker/api-dev-amd.tar.gz
docker run -v $(pwd):/var/www/html api:dev-amd sh -c "composer install --quiet && composer mess"
test-feature:
runs-on: buildjet-4vcpu-ubuntu-2204
name: 'Feature Test'
Expand Down Expand Up @@ -216,7 +234,7 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Feature Test
- name: Example Generation Test
run: |
chmod 777 test-feature-prepare
docker load < /tmp/docker/api-dev-amd.tar.gz
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add WebDAV HTTP methods to the allowed HTTP method lists.
- Add 'Example Generation Test' to CI.
- Enable phpstan rule for enforcing [safe functions](https://github.com/thecodingmachine/safe), closes #55.
- Add PHP Mess Detector, closes #114.

## 0.0.28 - 2023-09-14
### Added
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"guzzlehttp/guzzle": "^7.5",
"infection/infection": "^0.27",
"phpbench/phpbench": "^1.2",
"phpmd/phpmd": "^2.13",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.6",
"phpunit/php-code-coverage": "^9.2",
Expand Down Expand Up @@ -105,6 +106,7 @@
"psalm:fix-dry": "php vendor/bin/psalm --alter --issues=MissingParamType,MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType --dry-run",
"psalm:fix-apply": "php vendor/bin/psalm --alter --issues=MissingParamType,MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType",
"phpstan": "vendor/bin/phpstan",
"mess": "vendor/bin/phpmd src,lib,tests text phpmd.xml",
"benchmark": "vendor/bin/phpbench run --report=aggregate --progress dots",
"benchmark:csv": "vendor/bin/phpbench run --report=bare --output=csv-file",
"benchmark:plot": "python benchmark/plot/plot.py",
Expand Down
162 changes: 154 additions & 8 deletions composer.lock
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion lib/EmberNexusBundle/src/Service/EmberNexusConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Exception;

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
class EmberNexusConfiguration
{
public const PAGE_SIZE = 'pageSize';
Expand Down Expand Up @@ -42,7 +46,7 @@ class EmberNexusConfiguration
private static function getValueFromConfig(array $configuration, array $keyParts): mixed
{
$currentKeyParts = [];
foreach ($keyParts as $i => $keyPart) {
foreach ($keyParts as $keyPart) {
$currentKeyParts[] = $keyPart;
if (!array_key_exists($keyPart, $configuration)) {
throw new Exception(sprintf("Configuration must contain key '%s'.", implode('.', $currentKeyParts)));
Expand Down
35 changes: 35 additions & 0 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="pcsg-generated-ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/
</description>
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess"/>
<exclude name="ElseExpression"/>
<exclude name="BooleanArgumentFlag"/>
</rule>
<rule ref="rulesets/codesize.xml">
<exclude name="ExcessiveMethodLength"/>
<exclude name="TooManyPublicMethods"/>
<exclude name="TooManyMethods"/>
<exclude name="ExcessivePublicCount"/>
</rule>
<rule ref="rulesets/controversial.xml">
<exclude name="CamelCaseClassName"/>
<exclude name="CamelCaseParameterName"/>
<exclude name="Superglobals"/>
</rule>
<rule ref="rulesets/design.xml">
<exclude name="NumberOfChildren"/>
<exclude name="CouplingBetweenObjects"/>
</rule>
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable"/>
<exclude name="LongVariable"/>
<exclude name="LongClassName"/>
</rule>
<rule ref="rulesets/unusedcode.xml"/>
</ruleset>
3 changes: 3 additions & 0 deletions src/Command/BackupFetchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public function copyFile(FilesystemOperator $source, string $sourcePath, Filesys
);
}

/**
* @SuppressWarnings(PHPMD.CountInLoopExpression)
*/
private function findBackupRootFolder(Filesystem $filesystem): ?string
{
$stack = ['/'];
Expand Down
3 changes: 3 additions & 0 deletions src/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function __construct(
parent::__construct();
}

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$dataUuid = UuidV4::fromString('3a3c2f8b-d1bd-40fd-b381-82de60539c9f');
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/Element/PostIndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
class PostIndexController extends AbstractController
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Element/PutElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function putElement(string $uuid, Request $request): Response
*/
$data = \Safe\json_decode($request->getContent(), true);

foreach ($element->getProperties() as $name => $value) {
foreach (array_keys($element->getProperties()) as $name) {
if ('id' === $name) {
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/File/DeleteElementFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
class DeleteElementFileController extends AbstractController
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/File/GetElementFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
class GetElementFileController extends AbstractController
{
public function __construct(
Expand Down
Loading

0 comments on commit 6e50036

Please sign in to comment.