From ed679b4685e1846ab0887aae54412b144533516a Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Sat, 13 Jul 2024 18:49:39 +0200 Subject: [PATCH] Add development tools --- .gitattributes | 121 +++++++++++++++++++++++++++++++++++++++++ .gitignore | 6 ++ .php-cs-fixer.dist.php | 16 +++--- composer.json | 36 +++++++++++- phpcs.xml.dist | 10 ++++ phpdoc.dist.xml | 39 +++++++++++++ psalm.xml.dist | 23 ++++++++ 7 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 .gitattributes create mode 100644 phpcs.xml.dist create mode 100644 phpdoc.dist.xml create mode 100644 psalm.xml.dist diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..deb86b8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,121 @@ +### +# https://github.com/gitattributes/gitattributes/blob/master/Common.gitattributes +### + +# Auto detect text files and perform LF normalization +* text=auto + +# +# The above will handle all files NOT found below +# + +# Documents +*.bibtex text diff=bibtex +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain +*.md text diff=markdown +*.mdx text diff=markdown +*.tex text diff=tex +*.adoc text +*.textile text +*.mustache text +*.csv text eol=crlf +*.tab text +*.tsv text +*.txt text +*.sql text +*.epub diff=astextplain + +# Graphics +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.tif binary +*.tiff binary +*.ico binary +# SVG treated as text by default. +*.svg text +# If you want to treat it as binary, +# use the following line instead. +# *.svg binary +*.eps binary + +# Scripts +*.bash text eol=lf +*.fish text eol=lf +*.ksh text eol=lf +*.sh text eol=lf +*.zsh text eol=lf +# These are explicitly windows files and should use crlf +*.bat text eol=crlf +*.cmd text eol=crlf +*.ps1 text eol=crlf + +# Serialisation +*.json text +*.toml text +*.xml text +*.yaml text +*.yml text + +# Archives +*.7z binary +*.gz binary +*.tar binary +*.tgz binary +*.zip binary + +# Text files where line endings should be preserved +*.patch -text + +# +# Exclude files from exporting +# + +.gitattributes export-ignore +.gitignore export-ignore +.gitkeep export-ignore + +### +# https://github.com/gitattributes/gitattributes/blob/master/PHP.gitattributes +### + +# PHP files +*.php text eol=lf diff=php +*.phpt text eol=lf diff=php +*.phtml text eol=lf diff=html +*.twig text eol=lf +*.phar binary + +# Configuration +phpcs.xml text eol=lf +phpunit.xml text eol=lf +phpstan.neon text eol=lf +psalm.xml text eol=lf + +### +# Open Culture Consulting custom additions +### + +# Configuration +.editorconfig text eol=lf +*.dist.xml text eol=lf +*.xml.dist text eol=lf +*.neon text eol=lf + +# Generated documentation +doc/* linguist-generated=true + +# Exclude files from exporting +.github/* export-ignore +.phpdoc/* export-ignore +phpdoc.dist.xml export-ignore diff --git a/.gitignore b/.gitignore index 723e47a..0fae00d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ +/.phpdoc/cache/ /.vscode/ /config/config.yml /data/ /var/ /vendor/ +.php-cs-fixer.cache .php-cs-fixer.php +phpcs.xml +phpdoc.xml phpstan.neon +psalm.xml +TODO diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b3966d9..385bca2 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,7 +1,7 @@ * * This program is free software: you can redistribute it and/or modify @@ -24,15 +24,15 @@ namespace PhpCsFixer; /** * Configuration for PHP-CS-Fixer. + * * @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst * * @return ConfigInterface */ -return (new Config()) +$config = new Config(); +$finder = new Finder(); + +return $config ->setRiskyAllowed(true) - ->setRules([ - '@PSR12' => true, - ]) - ->setFinder( - (new Finder())->in(__DIR__) - ); + ->setRules(['@PSR12' => true]) + ->setFinder($finder->in([__DIR__ . '/src'])); diff --git a/composer.json b/composer.json index 784e46b..d1d3c1a 100644 --- a/composer.json +++ b/composer.json @@ -42,15 +42,23 @@ "symfony/yaml": "^6.4" }, "require-dev": { + "phpdocumentor/shim": "^3.5", "phpstan/phpstan": "^1.10", "phpstan/phpstan-strict-rules": "^1.5", - "friendsofphp/php-cs-fixer": "^3.48" + "friendsofphp/php-cs-fixer": "^3.48", + "squizlabs/php_codesniffer": "^3.10", + "vimeo/psalm": "^5.25" }, "autoload": { "psr-4": { "OCC\\OaiPmh2\\": "src/" } }, + "config": { + "allow-plugins": { + "phpdocumentor/shim": true + } + }, "scripts": { "pre-install-cmd": [ "@php -r \"!is_dir('./data') && mkdir('./data', 0775);\"", @@ -71,10 +79,34 @@ "doctrine:initialize-database": [ "@php bin/cli orm:schema-tool:update --complete --force", "@php bin/cli oai:formats:update --quiet" + ], + "php-cs-fixer:check": [ + "@php vendor/bin/php-cs-fixer check" + ], + "php-cs-fixer:fix": [ + "@php vendor/bin/php-cs-fixer fix" + ], + "phpcs:check": [ + "@php vendor/bin/phpcs" + ], + "phpdoc:build": [ + "@php vendor/bin/phpdoc" + ], + "phpstan:check": [ + "@php vendor/bin/phpstan" + ], + "psalm:check": [ + "@php vendor/bin/psalm" ] }, "scripts-descriptions": { "doctrine:clear-cache": "Clears the Doctrine/ORM metadata, query and result caches", - "doctrine:initialize-database": "Initializes a new database (NOT RECOMMENDED IN PRODUCTION!)" + "doctrine:initialize-database": "Initializes a new database (NOT RECOMMENDED IN PRODUCTION!)", + "php-cs-fixer:check": "Runs a code check with PHP Coding Standards Fixer and reports problems. If a custom configuration file '.php-cs-fixer.php' exists, it will be used instead of the default settings in '.php-cs-fixer.dist.php'.", + "php-cs-fixer:fix": "Runs a code check with PHP Coding Standards Fixer and tries to fix all issues. If a custom configuration file '.php-cs-fixer.php' exists, it will be used instead of the default settings in '.php-cs-fixer.dist.php'.", + "phpcs:check": "Runs a code check with PHP_CodeSniffer and reports problems. If a custom configuration file '.phpcs.xml' exists, it will be used instead of the default settings in '.phpcs.xml.dist'.", + "phpdoc:build": "Builds the documentation from source files in ./src and additional templates in .phpdoc/. If a custom configuration file 'phpdoc.xml' exists, it will be used instead of the default settings in 'phpdoc.dist.xml'.", + "phpstan:check": "Runs a code check with PHPStan static code analyzer and reports problems. If a custom configuration file 'phpstan.neon' exists, it will be used instead of the default settings in 'phpstan.dist.neon'.", + "psalm:check": "Runs a code check with Psalm static code analyzer and reports problems. If a custom configuration file 'psalm.xml' exists, it will be used instead of the default settings in 'psalm.xml.dist'." } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..0e5fe24 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,10 @@ + + + Open Culture Consulting strictly follows PSR standards. + ./src + + + + + + diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 0000000..3194742 --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,39 @@ + + + OAI-PMH2 Data Provider + + doc + .phpdoc/cache + + + + + /src + + + php + + OAIPMH2 + true + + extends + implements + phpstan-require-implements + psalm-suppress + + + + + /.phpdoc/guide + + guides + + + + + + diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 0000000..606f492 --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,23 @@ + + + + + + + + + + + + + +