Skip to content

Commit

Permalink
use php-cs-fixer for formatting (#29)
Browse files Browse the repository at this point in the history
* fix(build): rm key:generate in check-env target

The docker container is guaranteed to not be running at this point.  keygen happens last in the process.

* qa: switch from pint to php-cs-fixer

* ci: use make in run-checks action

* ci: run checks directly on the gh runner instance

* ci: use shivammathur/setup-php@v2

* style: run make fix

* ci: add unit tests to run-checks action
  • Loading branch information
chuckadams authored Oct 19, 2024
1 parent f2860d4 commit c19c1c0
Show file tree
Hide file tree
Showing 20 changed files with 1,328 additions and 122 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/run-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build container
run: docker build --target dev -t aspirepress/aspirecloud-cli -f ./docker/webapp/Dockerfile .
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Install Composer dependencies
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "composer install"
run: composer install

- name: Create .env file
run: cp .env.example .env

- name: Create App Key
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./artisan key:generate"
run: php artisan key:generate

- name: Run style checks
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./vendor/bin/pint --test"
- name: Run tests
run: |
vendor/bin/php-cs-fixer check
vendor/bin/phpstan --memory-limit=1G analyse
php artisan test tests/Unit
- name: Run quality check
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./vendor/bin/phpstan --memory-limit=1G analyse"
- name: Run unit tests
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./vendor/bin/pest"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.cache
/.fleet
/.idea
/.vscode
Expand Down
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$finder = (new PhpCsFixer\Finder)
->in(__DIR__)
->exclude([
'vendor',
'storage',
'bootstrap',
])
->notPath([
// 'dump.php',
// 'src/exception_file.php',
]);

return (new PhpCsFixer\Config)
->setRules([
'@PER-CS' => true,
'@PHP83Migration' => true,
])
->setFinder($finder)
->setCacheFile(__DIR__.'/.cache/.php_cs.cache');
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ endif
list:
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | perl -ne '/^(?:.*?:)?(.*?):.*##(.*$$)/ and printf "\033[36m%-30s\033[0m %s\n", $$1, $$2'

init: check-env down clean build network up install-composer reset-database generate-key ## Initial configuration tasks
init: check-env dirs down clean build network up install-composer reset-database generate-key ## Initial configuration tasks

dirs:
mkdir -p .cache

check-env:
@[ -f .env ] || { cp .env.example .env && bin/dcrun ./artisan key:generate; }
@[ -f .env ] || { cp .env.example .env; }

build: ## Builds the Docker containers
docker compose build
Expand Down Expand Up @@ -71,10 +74,17 @@ sh-%: ## Execute shell for the container where % is a service name (webapp, post
clear-cache: ## Clear cache
bin/dcrun php artisan optimize:clear

check: cs quality test ## Check all quality and test elements
lint: style quality ## Check code standards conformance

check: lint test ## Run lint and unit tests

fix: fix-style ## Run automated code fixes

style: ## Run code style checks
bin/dcrun vendor/bin/php-cs-fixer check

cs: ## Run code style checks
bin/dcrun vendor/bin/pint ${OPTS}
fix-style: ## Run code style fixes
bin/dcrun vendor/bin/php-cs-fixer fix

create-migration: ## Create a new database migration
bin/dcrun php artisan make:migration
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CatchAllController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(Request $request): Response
$response = Http::withHeaders([
'User-Agent' => $ua,
'Accept' => '*/*',
])->asForm()->send($request->getMethod(), 'https://api.wordpress.org/'.$path, [
])->asForm()->send($request->getMethod(), 'https://api.wordpress.org/' . $path, [
'query' => $queryParams,
'form_params' => $requestData,
]);
Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
use HasFactory;
use Notifiable;

/**
* The attributes that are mass assignable.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"require-dev": {
"aspirepress/aspirecloud-migrations": "dev-main",
"fakerphp/faker": "^1.23",
"friendsofphp/php-cs-fixer": "^3.64",
"larastan/larastan": "^2.0",
"laravel/pail": "^1.1",
"laravel/pint": "^1.18",
Expand Down
Loading

0 comments on commit c19c1c0

Please sign in to comment.