diff --git a/.github/workflows/lint-php.yaml b/.github/workflows/lint-php.yaml new file mode 100644 index 00000000..599b36c9 --- /dev/null +++ b/.github/workflows/lint-php.yaml @@ -0,0 +1,28 @@ +--- +name: Lint +on: + - push + - pull_request + +jobs: + xml-linters: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + - name: Download schema + run: wget https://apps.nextcloud.com/schema/apps/info.xsd + - name: Lint info.xml + uses: ChristophWurst/xmllint-action@v1 + with: + xml-file: ./appinfo/info.xml + xml-schema-file: ./info.xsd + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --dry-run --diff lib \ No newline at end of file diff --git a/.gitignore b/.gitignore index 005d7250..3a03e275 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ js/ build/ coverage/ .php_cs.cache +.php-cs-fixer.cache vendor memories.tar.gz /test-results/ diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 00000000..3ca302e7 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,58 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +$finder = PhpCsFixer\Finder::create() + ->ignoreDotFiles(false) + ->ignoreVCSIgnored(true) + ->exclude('tests/Fixtures') + ->in(__DIR__) + ->append([ + __DIR__.'/dev-tools/doc.php', + // __DIR__.'/php-cs-fixer', disabled, as we want to be able to run bootstrap file even on lower PHP version, to show nice message + ]) +; + +$config = new PhpCsFixer\Config(); +$config + ->setRiskyAllowed(true) + ->setRules([ + '@PHP71Migration' => false, + '@PHP71Migration:risky' => false, + '@PHPUnit75Migration:risky' => true, + '@PhpCsFixer' => true, + '@PhpCsFixer:risky' => true, + 'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead + 'modernize_strpos' => false, // needs PHP 8+ or polyfill + ]) + ->setFinder($finder) +; + +// special handling of fabbot.io service if it's using too old PHP CS Fixer version +if (false !== getenv('FABBOT_IO')) { + try { + PhpCsFixer\FixerFactory::create() + ->registerBuiltInFixers() + ->registerCustomFixers($config->getCustomFixers()) + ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules())) + ; + } catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) { + $config->setRules([]); + } catch (UnexpectedValueException $e) { + $config->setRules([]); + } catch (InvalidArgumentException $e) { + $config->setRules([]); + } +} + +return $config; \ No newline at end of file