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

Add Php CodeSniffer and PHPStan Fix #84 #143

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/phpstan.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions .github/workflows/phpcbf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Run PHP CodeSniffer

# Run PHPCBF to fix changes then annotate PHPCS
# NB: Pull requests from forks do not have access to repository secrets so cannot commit changes.

on:
push:
branches:
- master

jobs:
php-codesniffer:
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

strategy:
matrix:
php: [ '8.0' ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer, cs2pr
extensions: zip

- name: Run composer install
continue-on-error: true
run: composer install

- name: Run PHPCBF to fix what it can
continue-on-error: true
run: vendor/bin/phpcbf

- name: Run PHPCS to add annotations to the code
continue-on-error: true
run: vendor/bin/phpcs -q -n --report=checkstyle | cs2pr

- name: Commit PHPCBF changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "🤖 PHPCBF"

62 changes: 62 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Run PHPStan

# Run PHPStan to annotate the code

on:
push:
branches:
- master

jobs:
phpstan:
runs-on: ubuntu-latest

strategy:
matrix:
php: [ '8.0' ]

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer, cs2pr
extensions: zip

- name: Run composer install
continue-on-error: true
run: composer install

- name: Run PHPStan to add annotations to the code
id: run-phpstan
continue-on-error: true
run: |
vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 1G --no-progress --error-format=checkstyle | cs2pr

- name: Get PhpStan level
id: phpstan-level
run: |
LEVEL=$(cat phpstan.neon | grep level | sed "s/[^0-9]*//")
echo "level=$LEVEL" >> "$GITHUB_OUTPUT"

- name: Check success
if: steps.run-phpstan.outcome == 'success'
run: curl -o .github/phpstan.svg https://img.shields.io/badge/PHPStan-Level%20${{ steps.phpstan-level.outputs.level}}-2a5ea7.svg

- name: Check failures
if: steps.run-phpstan.outcome != 'success'
run: curl -o .github/phpstan.svg https://img.shields.io/badge/PHPStan-Level%20${{ steps.phpstan-level.outputs.level}}❌-lightgrey.svg

- name: Commit README badge changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: ".github/phpstan.svg"
commit_message: "🤖 PhpStan"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![PHPCS PSR-12](https://img.shields.io/badge/PHPCS-PSR–12-226146.svg)](https://www.php-fig.org/psr/psr-12/) [![PHPStan ](.github/phpstan.svg)](https://phpstan.org/)

# Monero Library
A Monero library written in PHP by the [Monero Integrations](https://monerointegrations.com) [team](https://github.com/monero-integrations/monerophp/graphs/contributors).

Expand Down
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,46 @@
"email": "sneurlax@gmail.com"
}
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"require": {
"php": ">=7.2.0",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "*",
"phpstan/extension-installer": "*",
"squizlabs/php_codesniffer": "*",
"brainmaestro/composer-git-hooks": "^2.8"
},
"suggest": {
"ext-gmp": "Used to have a multiple math precision for generating address"
},
"autoload": {
"psr-4": {
"MoneroIntegrations\\MoneroPhp\\": "src/"
}
},
"extra": {
"hooks": {
"pre-commit": [
"phpcbf"
]
}
},
"scripts": {
"post-install-cmd": "cghooks add --ignore-lock",
"post-update-cmd": "cghooks update",
"lint": [
"phpcbf || true",
"phpcs || true",
"phpstan analyse --memory-limit 1G"
]
}
}
Loading