Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code quality maintenance, fixes and general improvements #153

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
eebcee9
Remove phpstan baseline as it is old and obsolete
coenjacobs Sep 12, 2024
ef3b2dc
Fixes resulting from no phpstan baseline being used anymore
coenjacobs Sep 12, 2024
eac01ed
Bump PHP and Composer versions to latest stables
coenjacobs Sep 12, 2024
7bc393e
Installed phpmd and basic configuration file
coenjacobs Sep 12, 2024
45f76f5
Fixed all code smells in main replacer class
coenjacobs Sep 12, 2024
707f808
Change boolean load dependencies flag to separate method
coenjacobs Sep 12, 2024
716cb13
CamelCasing all the things
coenjacobs Sep 12, 2024
f40546a
Dumbed down if else constructions in autoloader classes
coenjacobs Sep 12, 2024
b8ebe68
Reduce Mover complexity by abstracting file handling to FileHandler
coenjacobs Sep 13, 2024
8974877
Remove else case from moveFile method to reduce complexity
coenjacobs Sep 13, 2024
7f1a140
Setters for underscore case properties translated to snakeCase
coenjacobs Sep 16, 2024
26cc7d6
Removed all static calls that shouldn't be static in the first place
coenjacobs Sep 16, 2024
10e709b
Reduce complexity of moveFile method on Mover class
coenjacobs Sep 17, 2024
00470e7
Reduce complexity of movePackage method
coenjacobs Sep 17, 2024
defd190
Reduce complexity of deleteDepTargetDirs methods
coenjacobs Sep 17, 2024
be0ba40
Reduce Mover complexity by defering file path handling to autoloaders
coenjacobs Sep 19, 2024
3f8e10c
Suppress parameter not being used as it extends Symfony command class
coenjacobs Sep 19, 2024
b1a58c5
Add phpmd to test script and GitHub Actions
coenjacobs Sep 19, 2024
952d847
Merge pull request #154 from coenjacobs/phpmd-experiment
coenjacobs Sep 19, 2024
36a61f7
Cleanup, documentation fixes and formatting
coenjacobs Sep 19, 2024
4a5a07d
Enforce docblocks for complex methods by set thresholds
coenjacobs Sep 19, 2024
58e0644
Added enforced docblocks for complex methods
coenjacobs Sep 19, 2024
e755e61
Add doc check to GitHub Actions steps
coenjacobs Sep 19, 2024
b7f2029
Merge pull request #155 from coenjacobs/enforce-docblocks-complexity
coenjacobs Sep 19, 2024
f054665
Change coding standard to PSR-12
coenjacobs Sep 19, 2024
0d7ae1a
Minor changes to pass PSR-12 coding standards
coenjacobs Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,37 @@ jobs:
cache-to: type=gha,mode=max
- name: Run analysis
run: docker compose run --rm actions-tester composer test:phpstan
mess-detect:
runs-on: ubuntu-latest
name: Mess detector
steps:
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- uses: actions/checkout@v4
- name: Build Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}"
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run mess detector
run: docker compose run --rm actions-tester composer test:phpmd
doc-check:
runs-on: ubuntu-latest
name: Documentation check
steps:
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- uses: actions/checkout@v4
- name: Build Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}"
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run doc check
run: docker compose run --rm actions-tester composer test:docs
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM composer:2.7.7
FROM php:8.3.9-cli-alpine AS base
FROM composer:2.7.9
FROM php:8.3.11-cli-alpine AS base

FROM base AS builder
RUN apk update && apk add git
Expand Down
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
"symfony/console": "^5.4",
"symfony/finder": "^5.4",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/php-compatibility": "dev-develop"
"phpcompatibility/php-compatibility": "dev-develop",
"phpmd/phpmd": "^2.15",
"niels-de-blaauw/php-doc-check": "^0.4.0"
},
"scripts": {
"test": [
"@test:lint",
"@test:phpunit",
"@test:phpstan"
"@test:phpstan",
"@test:phpmd",
"@test:docs"
],
"test:lint": [
"composer validate",
Expand All @@ -57,6 +61,12 @@
],
"test:phpstan": [
"./vendor/bin/phpstan analyse -c phpstan.neon.dist --memory-limit=2G"
],
"test:phpmd": [
"./vendor/bin/phpmd src ansi phpmd.xml.dist"
],
"test:docs": [
"./vendor/bin/php-doc-check src"
]
}
}
4 changes: 2 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<!--suppress XmlUnboundNsPrefix -->
<ruleset name="mozart">
<description>Coding standard ruleset based on the PSR-2 coding standard.</description>
<rule ref="PSR2"/>
<description>Coding standard ruleset based on the PSR-12 coding standard.</description>
<rule ref="PSR12"/>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="8.0-8.3"/>
Expand Down
16 changes: 16 additions & 0 deletions phpmd.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<ruleset name="Rule set for PHPMD to detect code smells"
xmlns="https://phpmd.org/xml/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://phpmd.org/xml/ruleset/1.0.0
http://phpmd.org/xml/ruleset_xml_schema_1.0.0.xsd"
xsi:noNamespaceSchemaLocation="
http://phpmd.org/xml/ruleset_xml_schema_1.0.0.xsd">

<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/unusedcode.xml" />
</ruleset>
211 changes: 0 additions & 211 deletions phpstan-baseline.neon

This file was deleted.

3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includes:
- phpstan-baseline.neon

parameters:
level: 8
reportUnmatchedIgnoredErrors: false
Expand Down
27 changes: 27 additions & 0 deletions src/Composer/Autoload/AbstractAutoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace CoenJacobs\Mozart\Composer\Autoload;

use CoenJacobs\Mozart\Config\Package;

abstract class AbstractAutoloader implements Autoloader
{
private Package $package;

public function getPackage(): Package
{
return $this->package;
}

public function setPackage(Package $package): void
{
$this->package = $package;
}

public function getOutputDir(string $basePath, string $autoloadPath): string
{
$outputDir = $basePath . $autoloadPath;
$outputDir = str_replace('\\', DIRECTORY_SEPARATOR, $outputDir);
return $outputDir;
}
}
16 changes: 16 additions & 0 deletions src/Composer/Autoload/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

namespace CoenJacobs\Mozart\Composer\Autoload;

use CoenJacobs\Mozart\FilesHandler;
use Symfony\Component\Finder\SplFileInfo;

interface Autoloader
{
/**
* @param mixed $autoloadConfig
*/
public function processConfig($autoloadConfig): void;
public function getSearchNamespace(): string;
public function getOutputDir(string $basePath, string $autoloadPath): string;
/**
* @return array<string,SplFileInfo>
*/
public function getFiles(FilesHandler $files): array;
/**
* Returns the intended target path of a file, where it should be moved by
* the Mover class. This requires access to the Mozart configuration, for it
* to determine the target directory. This is done by checking the paths
* that are being registered for this autoloader, to see if they can be
* matched with the full path name of the provided file.
*/
public function getTargetFilePath(SplFileInfo $file): string;
}
Loading
Loading