diff --git a/.gitattributes b/.gitattributes index 9be6f60f..d5b57104 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,3 +13,4 @@ /Makefile export-ignore /psalm-baseline.xml export-ignore /psalm.xml export-ignore +/rector.php export-ignore diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 01c24919..1d765050 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,3 @@ +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-file-size + * @ergebnis-bot @localheinz diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a8c04a0c..34cf4cb0 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -6,7 +6,6 @@ For details, take a look at the following workflow configuration files: - [`workflows/integrate.yaml`](workflows/integrate.yaml) - [`workflows/merge.yaml`](workflows/merge.yaml) -- [`workflows/prune.yaml`](workflows/prune.yaml) - [`workflows/release.yaml`](workflows/release.yaml) - [`workflows/renew.yaml`](workflows/renew.yaml) - [`workflows/triage.yaml`](workflows/triage.yaml) @@ -47,9 +46,45 @@ make dependency-analysis to run a dependency analysis. +## Mutation Tests + +We are using [`infection/infection`](https://github.com/infection/infection) to ensure a minimum quality of the tests. + +Enable `Xdebug` and run + +```sh +make mutation-tests +``` + +to run mutation tests. + +## Refactoring + +We are using [`rector/rector`](https://github.com/rectorphp/rector) to automatically refactor code. + +Run + +```sh +make refactoring +``` + +to automatically refactor code. + +## Security Analysis + +We are using [`composer`](https://github.com/composer/composer) to run a security analysis. + +Run + +```sh +make security-analysis +``` + +to run a security analysis. + ## Static Code Analysis -We are using [`vimeo/psalm`](https://github.com/vimeo/psalm) to statically analyze the code. +We are using [`phpstan/phpstan`](https://github.com/phpstan/phpstan) and [`vimeo/psalm`](https://github.com/vimeo/psalm) to statically analyze the code. Run @@ -59,7 +94,7 @@ make static-code-analysis to run a static code analysis. -We are also using the baseline feature of [`vimeo/psalm`](https://psalm.dev/docs/running_psalm/dealing_with_code_issues/#using-a-baseline-file). +We are also using the baseline features of [`phpstan/phpstan`](https://phpstan.org/user-guide/baseline) and [`vimeo/psalm`](https://psalm.dev/docs/running_psalm/dealing_with_code_issues/#using-a-baseline-file). Run @@ -67,9 +102,9 @@ Run make static-code-analysis-baseline ``` -to regenerate the baseline in [`../psalm-baseline.xml`](../psalm-baseline.xml). +to regenerate the baselines in [`../phpstan-baseline.neon`](../phpstan-baseline.neon) and [`../psalm-baseline.xml`](../psalm-baseline.xml). -:exclamation: Ideally, the baseline should shrink over time. +:exclamation: Ideally, the baselines should shrink over time. ## Tests @@ -83,18 +118,6 @@ make tests to run all the tests. -## Mutation Tests - -We are using [`infection/infection`](https://github.com/infection/infection) to ensure a minimum quality of the tests. - -Enable `pcov` or `Xdebug` and run - -```sh -make mutation-tests -``` - -to run mutation tests. - ## Extra lazy? Run @@ -103,7 +126,7 @@ Run make ``` -to enforce coding standards, run a static code analysis, and run tests! +to automatically refactor code, enforce coding standards, run a static code analysis, and run tests! ## Help diff --git a/.github/settings.yml b/.github/settings.yml index 7860d11c..3c2ac30d 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -18,6 +18,8 @@ branches: - context: "Coding Standards (8.1, locked)" - context: "Dependency Analysis (8.1, locked)" - context: "Mutation Tests (8.1, locked)" + - context: "Refactoring (8.1, locked)" + - context: "Security Analysis (8.1, locked)" - context: "Static Code Analysis (8.1, locked)" - context: "Tests (8.1, locked)" - context: "Tests (8.2, locked)" @@ -58,10 +60,6 @@ labels: color: "ee0701" description: "" - - name: "stale" - color: "eeeeee" - description: "" - # https://docs.github.com/en/rest/reference/repos#update-a-repository repository: diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index af81d3b6..f32eab8a 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -83,7 +83,7 @@ jobs: uses: "actions/checkout@v3.3.0" - name: "Lint YAML files" - uses: "ibiqlik/action-yamllint@v3.1" + uses: "ibiqlik/action-yamllint@v3.1.1" with: config_file: ".yamllint.yaml" file_or_dir: "." @@ -127,8 +127,10 @@ jobs: uses: "actions/cache@v3.3.1" with: path: ".build/php-cs-fixer" - key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.sha }}" - restore-keys: "php-${{ matrix.php-version }}-php-cs-fixer-" + key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}" + restore-keys: | + php-${{ matrix.php-version }}-php-cs-fixer-main + php-${{ matrix.php-version }}-php-cs-fixer- - name: "Run friendsofphp/php-cs-fixer" run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --verbose" @@ -156,6 +158,7 @@ jobs: coverage: "none" extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + tools: "phive" - name: "Set up problem matchers for PHP" run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" @@ -175,6 +178,11 @@ jobs: with: dependencies: "${{ matrix.dependencies }}" + - name: "Install dependencies with phive" + uses: "ergebnis/.github/actions/phive/install@1.8.0" + with: + trust-gpg-keys: "0x033E5F8D801A2F8D" + - name: "Run maglnet/composer-require-checker" run: ".phive/composer-require-checker check --config-file=$(pwd)/composer-require-checker.json" @@ -225,6 +233,96 @@ jobs: XDEBUG_MODE: "coverage" run: "vendor/bin/infection --ansi --configuration=infection.json --logger-github" + refactoring: + name: "Refactoring" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "8.1" + + dependencies: + - "locked" + + steps: + - name: "Checkout" + uses: "actions/checkout@v3.3.0" + + - name: "Set up PHP" + uses: "shivammathur/setup-php@2.24.0" + with: + coverage: "none" + extensions: "none, ctype, dom, intl, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" + php-version: "${{ matrix.php-version }}" + + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + + - name: "Determine composer cache directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.8.0" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v3.3.1" + with: + path: "${{ env.COMPOSER_CACHE_DIR }}" + key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" + + - name: "Install ${{ matrix.dependencies }} dependencies with composer" + uses: "ergebnis/.github/actions/composer/install@1.8.0" + with: + dependencies: "${{ matrix.dependencies }}" + + - name: "Create cache directory for rector/rector" + run: "mkdir -p .build/rector" + + - name: "Cache cache directory for rector/rector" + uses: "actions/cache@v3.3.0" + with: + path: ".build/rector" + key: "php-${{ matrix.php-version }}-rector-${{ github.ref_name }}" + restore-keys: | + php-${{ matrix.php-version }}-rector-main + php-${{ matrix.php-version }}-rector- + + - name: "Run automated refactoring with rector/rector" + run: "vendor/bin/rector --ansi --config=rector.php --dry-run" + + security-analysis: + name: "Security Analysis" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "8.1" + + dependencies: + - "locked" + + steps: + - name: "Checkout" + uses: "actions/checkout@v3.3.1" + + - name: "Set up PHP" + uses: "shivammathur/setup-php@2.24.0" + with: + coverage: "none" + extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" + php-version: "${{ matrix.php-version }}" + + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + + - name: "Validate composer.json and composer.lock" + run: "composer validate --ansi --strict" + + - name: "Check installed packages for security vulnerability advisories" + run: "composer audit --ansi" + static-code-analysis: name: "Static Code Analysis" @@ -246,7 +344,7 @@ jobs: uses: "shivammathur/setup-php@2.24.0" with: coverage: "none" - extensions: "none, ctype, curl, dom, json, mbstring, pcntl, phar, posix, simplexml, tokenizer, xml, xmlwriter" + extensions: "none, ctype, curl, dom, json, mbstring, opcache, pcntl, phar, posix, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" - name: "Set up problem matchers for PHP" diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml index a2420c0d..c79d5d22 100644 --- a/.github/workflows/merge.yaml +++ b/.github/workflows/merge.yaml @@ -34,8 +34,8 @@ jobs: - name: "Assign @ergebnis-bot" uses: "ergebnis/.github/actions/github/pull-request/add-assignee@1.8.0" with: - github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" assignee: "ergebnis-bot" + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - name: "Approve pull request" uses: "ergebnis/.github/actions/github/pull-request/approve@1.8.0" diff --git a/.github/workflows/prune.yaml b/.github/workflows/prune.yaml deleted file mode 100644 index 8b559cf3..00000000 --- a/.github/workflows/prune.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# https://docs.github.com/en/actions - -name: "Prune" - -on: # yamllint disable-line rule:truthy - schedule: - - cron: "0 12 * * *" - -env: - DAYS_BEFORE_CLOSE: 14 - DAYS_BEFORE_STALE: 180 - -jobs: - prune: - name: "Issues" - - runs-on: "ubuntu-latest" - - steps: - - name: "Prune issues and pull requests" - uses: "actions/stale@v7.0.0" - with: - days-before-close: "${{ env.DAYS_BEFORE_CLOSE }}" - days-before-stale: "${{ env.DAYS_BEFORE_STALE }}" - repo-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - stale-issue-label: "stale" - stale-issue-message: | - Since this issue has not had any activity within the last ${{ env.DAYS_BEFORE_STALE }} days, I have marked it as stale. - - I will close it if no further activity occurs within the next ${{ env.DAYS_BEFORE_CLOSE }} days. - stale-pr-label: "stale" - stale-pr-message: | - Since this pull request has not had any activity within the last ${{ env.DAYS_BEFORE_STALE }} days, I have marked it as stale. - - I will close it if no further activity occurs within the next ${{ env.DAYS_BEFORE_CLOSE }} days. diff --git a/.github/workflows/renew.yaml b/.github/workflows/renew.yaml index cc20923a..47913d75 100644 --- a/.github/workflows/renew.yaml +++ b/.github/workflows/renew.yaml @@ -61,8 +61,10 @@ jobs: uses: "actions/cache@v3.3.1" with: path: ".build/php-cs-fixer" - key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.sha }}" - restore-keys: "php-${{ matrix.php-version }}-php-cs-fixer-" + key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}" + restore-keys: | + php-${{ matrix.php-version }}-php-cs-fixer-main + php-${{ matrix.php-version }}-php-cs-fixer- - name: "Run friendsofphp/php-cs-fixer" run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --verbose" diff --git a/.gitignore b/.gitignore index 3d890bb5..cd9aa25f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /.build/ /.notes/ +/.phive/ /demo/obsidian/ -!/demo/obsidian/.gitkeep /vendor/ +!/.phive/phars.xml +!/demo/obsidian/.gitkeep diff --git a/.phive/phars.xml b/.phive/phars.xml index 2b83ffc4..6eea48c8 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,4 +1,4 @@ - + diff --git a/Makefile b/Makefile index a7a9aab5..a6a600a9 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,20 @@ .PHONY: it -it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets +it: refactoring coding-standards security-analysis static-code-analysis tests ## Runs the refactoring, coding-standards, security-analysis, static-code-analysis, and tests targets .PHONY: code-coverage code-coverage: vendor ## Collects coverage from running unit tests with phpunit/phpunit mkdir -p .build/phpunit - vendor/bin/phpunit --configuration=test/phpunit.xml --coverage-text --testsuite=unit,integration + vendor/bin/phpunit --configuration=test/Unit/phpunit.xml --coverage-text .PHONY: coding-standards -coding-standards: vendor ## Normalizes composer.json with ergebnis/composer-normalize, lints YAML files with yamllint and fixes code style issues with friendsofphp/php-cs-fixer - composer normalize +coding-standards: vendor ## Lints YAML files with yamllint, normalizes composer.json with ergebnis/composer-normalize, and fixes code style issues with friendsofphp/php-cs-fixer yamllint -c .yamllint.yaml --strict . + composer normalize mkdir -p .build/php-cs-fixer vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose .PHONY: dependency-analysis -dependency-analysis: vendor ## Runs a dependency analysis with maglnet/composer-require-checker +dependency-analysis: phive vendor ## Runs a dependency analysis with maglnet/composer-require-checker .phive/composer-require-checker check --config-file=$(shell pwd)/composer-require-checker.json .PHONY: help @@ -26,6 +26,19 @@ mutation-tests: vendor ## Runs mutation tests with infection/infection mkdir -p .build/infection vendor/bin/infection --configuration=infection.json +.PHONY: phive +phive: .phive ## Installs dependencies with phive + mkdir -p .build/phive + PHIVE_HOME=.build/phive phive install --trust-gpg-keys 0x033E5F8D801A2F8D + +.PHONY: refactoring +refactoring: vendor ## Runs automated refactoring with rector/rector + vendor/bin/rector process --config=rector.php + +.PHONY: security-analysis +security-analysis: vendor ## Runs a security analysis with composer + composer audit + .PHONY: static-code-analysis static-code-analysis: vendor ## Runs a static code analysis with vimeo/psalm mkdir -p .build/psalm diff --git a/README.md b/README.md index 220fbad1..46e1bc16 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # day-one-to-obsidian-converter [![Integrate](https://github.com/ergebnis/day-one-to-obsidian-converter/workflows/Integrate/badge.svg)](https://github.com/ergebnis/day-one-to-obsidian-converter/actions) -[![Prune](https://github.com/ergebnis/day-one-to-obsidian-converter/workflows/Prune/badge.svg)](https://github.com/ergebnis/day-one-to-obsidian-converter/actions) +[![Merge](https://github.com/ergebnis/day-one-to-obsidian-converter/workflows/Merge/badge.svg)](https://github.com/ergebnis/day-one-to-obsidian-converter/actions) [![Release](https://github.com/ergebnis/day-one-to-obsidian-converter/workflows/Release/badge.svg)](https://github.com/ergebnis/day-one-to-obsidian-converter/actions) [![Renew](https://github.com/ergebnis/day-one-to-obsidian-converter/workflows/Renew/badge.svg)](https://github.com/ergebnis/day-one-to-obsidian-converter/actions) @@ -10,8 +10,7 @@ [![Latest Stable Version](https://poser.pugx.org/ergebnis/day-one-to-obsidian-converter/v/stable)](https://packagist.org/packages/ergebnis/day-one-to-obsidian-converter) [![Total Downloads](https://poser.pugx.org/ergebnis/day-one-to-obsidian-converter/downloads)](https://packagist.org/packages/ergebnis/day-one-to-obsidian-converter) - -Provides a console command for converting [DayOne](https://dayoneapp.com) journals to [Obsidian](https://obsidian.md) notes. +[![Monthly Downloads](http://poser.pugx.org/ergebnis/day-one-to-obsidian-converter/d/monthly)](https://packagist.org/packages/ergebnis/day-one-to-obsidian-converter) ## Installation @@ -90,4 +89,4 @@ The files in [`demo/day-one/`](demo/day-one/) are taken from [Importing data to ## Curious what I am up to? -Follow me on [Twitter](https://twitter.com/localheinz)! +Follow me on [Twitter](https://twitter.com/intent/follow?screen_name=localheinz)! diff --git a/composer-require-checker.json b/composer-require-checker.json index 67d0aa16..b8b091ad 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -1,19 +1,3 @@ { - "symbol-whitelist": [ - "array", - "bool", - "callable", - "false", - "float", - "int", - "iterable", - "null", - "object", - "parent", - "self", - "static", - "string", - "true", - "void" - ] + "symbol-whitelist": [] } diff --git a/composer.json b/composer.json index f4eb62c0..51c47cad 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "infection/infection": "~0.26.19", "phpunit/phpunit": "^9.6.5", "psalm/plugin-phpunit": "~0.18.4", + "rector/rector": "~0.15.21", "vimeo/psalm": "^5.8" }, "autoload": { diff --git a/composer.lock b/composer.lock index d30e36e5..bdce083c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cdc2106abf7c788daf396094a06f0ae4", + "content-hash": "53cbe054525fe23dea5e58816d606eb9", "packages": [ { "name": "ergebnis/json-schema-validator", @@ -3390,6 +3390,65 @@ }, "time": "2022-10-14T12:47:21+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.6", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "50d089a3e0904b0fe7e2cf2d4fd37d427d64235a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/50d089a3e0904b0fe7e2cf2d4fd37d427d64235a", + "reference": "50d089a3e0904b0fe7e2cf2d4fd37d427d64235a", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.10.6" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-03-09T16:55:12+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.26", @@ -4019,6 +4078,67 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "rector/rector", + "version": "0.15.21", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "1cee8cc5d6d836e1bf9a3006d7b062adde3a6022" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/1cee8cc5d6d836e1bf9a3006d7b062adde3a6022", + "reference": "1cee8cc5d6d836e1bf9a3006d7b062adde3a6022", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.10.1" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.15-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/0.15.21" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2023-03-06T11:44:29+00:00" + }, { "name": "sanmai/later", "version": "0.1.2", diff --git a/psalm.xml b/psalm.xml index 12df516b..00713658 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,6 +6,8 @@ cacheDirectory=".build/psalm" errorBaseline="psalm-baseline.xml" errorLevel="1" + findUnusedBaselineEntry="true" + findUnusedCode="true" findUnusedVariablesAndParams="true" resolveFromConfigFile="true" strictBinaryOperands="true" @@ -17,6 +19,7 @@ + diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..026283f5 --- /dev/null +++ b/rector.php @@ -0,0 +1,33 @@ +cacheDirectory(__DIR__ . '/.build/rector/'); + + $rectorConfig->import(__DIR__ . '/vendor/fakerphp/faker/rector-migrate.php'); + + $rectorConfig->paths([ + __DIR__ . '/src/', + __DIR__ . '/test/', + ]); + + $rectorConfig->phpVersion(Core\ValueObject\PhpVersion::PHP_81); + + $rectorConfig->sets([ + PHPUnit\Set\PHPUnitSetList::PHPUNIT_90, + ]); +};