Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Aug 17, 2024
0 parents commit 4786e74
Show file tree
Hide file tree
Showing 60 changed files with 12,619 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on: [push, pull_request]

jobs:
testsuite:
name: Unittests
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
php-version: ['8.2', '8.3']

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json, fileinfo
tools: pecl
coverage: pcov

- name: Composer install
run: |
if [[ ${{ matrix.prefer-lowest == 'prefer-lowest' }} ]]; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
bin/phpunit --coverage-clover=coverage.xml
else
bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '8.2'
uses: codecov/codecov-action@v4

code-analysis:
name: Coding Standard & Static Analysis
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json, fileinfo
coverage: pcov
tools: pecl

- name: Composer install
run: composer update --prefer-lowest --prefer-stable

- name: Run phpcs
run: bin/phpcs --version && bin/phpcs --report=source --standard=phpcs.xml

- name: Run phpstan
run: bin/phpstan -V && bin/phpstan --error-format=github

- name: Run Infection
run: bin/infection
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/vendor/
/bin/
/.phive/
/.phpunit.cache/
/tmp/
/tools/
.idea/
.env
infection.log
phive.phar
cognitive-analysis.phar
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.DEFAULT_GOAL := help

help:
@echo "Available commands:"
@echo " - run-tests: Run tests"
@echo " - run-infection: Runs Infection mutation testing"
@echo " - coverage-text: Runs coverage text"
@echo " - coverage-html: Runs coverage html"
@echo " - all: Runs CS-Fixer, CS-Checker, Static Analyser and Tests"
@echo " - shell: Run shell"
@echo " - self-test: Run cognitive analyses self-test"
@echo " - self-test-halstead: Run cognitive analyses self-test"
@echo " - build-phar: Build phar"

run-tests:
@echo "Running tests"
docker compose run php composer test

run-infection:
@echo "Running infection mutation testing"
docker compose run php composer infection

coverage-text:
@echo "Running coverage text"
docker compose run php composer test-coverage

coverage-html:
@echo "Running coverage text"
docker compose run php composer test-coverage-html

all:
@echo "Running CS-Fixer, CS-Checker, Static Analyser and Tests"
docker compose run php composer all

shell:
@echo "Running shell"
docker compose run --service-ports --entrypoint /bin/bash php

self-test:
@echo "Running cognitive analyses self-test"
docker compose run php php analyse.php metrics:cognitive src

self-test-halstead:
@echo "Running cognitive analyses self-test"
docker compose run php php analyse.php metrics:halstead src

build-phar:
@echo "Building phar"
docker compose run php composer build-phar
13 changes: 13 additions & 0 deletions analyse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require 'vendor/autoload.php';

use Phauthentic\CodeQualityMetrics\Command\CognitiveMetricsCommand;
use Phauthentic\CodeQualityMetrics\Command\HalsteadMetricsCommand;
use Symfony\Component\Console\Application;

$application = new Application();
$application->add(new CognitiveMetricsCommand());
$application->add(new HalsteadMetricsCommand());

$application->run();
5 changes: 5 additions & 0 deletions box.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "./analyse.php",
"compression": "GZ",
"output": "cognitive-analysis.phar"
}
81 changes: 81 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "phauthentic/code-quality",
"type": "project",
"require": {
"php": "^8.1",
"nikic/php-parser": "^5.1",
"symfony/console": "^7.1",
"symfony/config": "^7.1",
"symfony/yaml": "^7.1"
},
"autoload": {
"psr-4": {
"Phauthentic\\CodeQualityMetrics\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Phauthentic\\CodeQualityMetrics\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Florian Krämer"
}
],
"require-dev": {
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^11.3",
"infection/infection": "^0.29.6",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.11",
"squizlabs/php_codesniffer": "^3.10",
"symfony/var-dumper": "^7.1"
},
"config": {
"bin-dir": "bin",
"allow-plugins": {
"infection/extension-installer": true
}
},
"scripts": {
"test": [
"phpunit"
],
"infection": [
"infection"
],
"test-coverage": [
"phpunit --coverage-text"
],
"test-coverage-html": [
"phpunit --coverage-html tmp/coverage/"
],
"cscheck": [
"phpcs src/ tests/ -s"
],
"csfix": [
"phpcbf src/ tests/"
],
"analyze": [
"phpstan analyse src/"
],
"phpmd": [
"bin/phpmd ./src text cleancode,codesize,controversial,design"
],
"benchmark": [
"bin/phpbench run tests/Benchmark/ --report=aggregate"
],
"all": [
"@csfix",
"@cscheck",
"@analyze",
"@test"
],
"build-phar": [
"if [ ! -f phive.phar ]; then wget -O phive.phar \"https://phar.io/releases/phive.phar\"; fi",
"if [ ! -f tools/box ]; then php phive.phar install humbug/box; fi",
"tools/box compile"
]
}
}
Loading

0 comments on commit 4786e74

Please sign in to comment.