Skip to content

Commit

Permalink
Merge pull request #143 from BrianHenryIE/phpcs
Browse files Browse the repository at this point in the history
Add Php CodeSniffer and PHPStan Fix #84
  • Loading branch information
serhack committed Oct 19, 2023
2 parents 0d2fa4e + d2f7457 commit eda8248
Show file tree
Hide file tree
Showing 8 changed files with 1,379 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/phpstan.svg
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
@@ -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
@@ -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
@@ -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
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"
]
}
}

0 comments on commit eda8248

Please sign in to comment.