Skip to content
Closed
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
12 changes: 12 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
APP_ENV=testing
APP_KEY=base64:u1iFSaBTsAgO6yMzWOHPAEcPMYTYAV6cxaWKNtkfizI=

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sumotest
DB_USERNAME=root
DB_PASSWORD=root

SESSION_DRIVER=array
QUEUE_CONNECTION=sync
82 changes: 82 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: PHP Composer

on:
workflow_dispatch:
push:
# Ignore code coverage badge branch
branches-ignore: [ "image-data" ]

permissions:
contents: read

jobs:
build:
name: kimarite-build
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v3

- name: PHP Security Checker
uses: symfonycorp/security-checker-action@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: cs2pr

- name: Start Mariadb
run: |
sudo systemctl start mysql.service
mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS sumotest;'


- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress

- name: Install NPM dependencies
run: |
npm ci
npm run build

- name: Syntax
run: vendor/bin/parallel-lint --exclude vendor .

- name: Laravel Pint
run: vendor/bin/pint

- name: Tests
run: |
php artisan migrate --env=testing
XDEBUG_MODE=coverage php artisan test --coverage-clover=clover.xml

- name: Make code coverage badge
uses: timkrase/phpunit-coverage-badge@v1.2.1
with:
coverage_badge_path: output/coverage.svg
push_badge: false
- name: Git push to image-data branch
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./output
publish_branch: image-data
github_token: ${{ secrets.GITHUB_TOKEN }}
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
- name: Static analysis
run: vendor/bin/phpstan analyse
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ In another: `npm run dev`

Browse to http://127.0.0.1:8000/

# Automated tests

Create a test DB called `sumotest` and run `php artisan migrate` on it.

# Production install

```
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/ConfirmablePasswordController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Auth/NewPasswordController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down Expand Up @@ -30,7 +32,7 @@ public function create(Request $request): Response
/**
* Handle an incoming new password request.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function store(Request $request): RedirectResponse
{
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Auth/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand All @@ -25,7 +27,7 @@ public function create(): Response
/**
* Handle an incoming password reset link request.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function store(Request $request): RedirectResponse
{
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand Down
17 changes: 8 additions & 9 deletions app/Http/Controllers/KimariteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ public function getCounts(Request $request): JsonResponse
'divisions.*' => 'string',
'from' => 'required|date_format:Y-m',
'to' => 'nullable|date_format:Y-m|after_or_equal:from',
//'annual' => 'required|boolean',
// 'annual' => 'required|boolean',
]);

// Check for validation failure
if ($validator->fails()) {
return new JsonResponse([
'error' => 'Invalid input data',
'messages' => $validator->errors()
'messages' => $validator->errors(),
], 422);
}

$types = $request->input('types');
$divisions = $request->input('divisions');
$from = Str::replace('-', '', $request->input('from'));
$to = Str::replace('-', '', $request->input('to'));
$annual = (bool)$request->input('annual', false);
$annual = (bool) $request->input('annual', false);

// Use a subquery to get the percentages
$subQuery = DB::table('basho_totals')
Expand All @@ -70,13 +70,12 @@ public function getCounts(Request $request): JsonResponse
DB::raw('SUM(kc.count) AS total'),
DB::raw('SUM(kc.count) / bt.basho_total * 100 AS percentage')
)
->leftJoinSub($subQuery, 'bt', fn ($join) =>
$join->on('kc.basho_id', '=', 'bt.basho_id')
->leftJoinSub($subQuery, 'bt', fn ($join) => $join->on('kc.basho_id', '=', 'bt.basho_id')
)
->whereIn('kc.type', $types)
->whereIn('kc.division', $divisions)
->where('kc.basho_id', '>=', $from)
->when(!empty($to), fn($q) => $q->where('kc.basho_id', '<=', $to))
->when(! empty($to), fn ($q) => $q->where('kc.basho_id', '<=', $to))
->groupBy('type', 'basho_id')
->orderBy('basho_id')
->get();
Expand All @@ -90,7 +89,7 @@ public function getCounts(Request $request): JsonResponse

foreach ($flatTotals as $flatTotal) {
$key = $counts->search(fn (array $count) => Str::lower($count['type']) === $flatTotal->type);

$counts->transform(function (array $count, int $index) use ($key, $flatTotal) {
if ($index === $key) {
$count['groupedCounts'][] = $flatTotal;
Expand All @@ -104,7 +103,7 @@ public function getCounts(Request $request): JsonResponse
// there's no data for them given the requested types and divisions
$bashoIds = BashoTotal::select('basho_id')
->where('basho_id', '>=', $from)
->when(!empty($to), fn($q) => $q->where('basho_id', '<=', $to))
->when(! empty($to), fn ($q) => $q->where('basho_id', '<=', $to))
->distinct()
->orderBy('basho_id')
->get()
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Requests\ProfileUpdateRequest;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RefreshController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function rebuild(Request $request): JsonResponse
public function refreshBashoPercentages(Request $request): JsonResponse
{
$this->aggregator->refreshBashoPercentages();

return new JsonResponse([
'message' => 'Success',
]);
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Http\Request;
Expand All @@ -17,7 +19,7 @@ class HandleInertiaRequests extends Middleware
/**
* Determine the current asset version.
*/
public function version(Request $request): string|null
public function version(Request $request): ?string
{
return parent::version($request);
}
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Auth;

use Illuminate\Auth\Events\Lockout;
Expand Down Expand Up @@ -35,7 +37,7 @@ public function rules(): array
/**
* Attempt to authenticate the request's credentials.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function authenticate(): void
{
Expand All @@ -55,7 +57,7 @@ public function authenticate(): void
/**
* Ensure the login request is not rate limited.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function ensureIsNotRateLimited(): void
{
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/ProfileUpdateRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Models\User;
Expand Down
4 changes: 1 addition & 3 deletions app/Models/KimariteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Illuminate\Database\Eloquent\Model;

class KimariteType extends Model
{
}
class KimariteType extends Model {}
4 changes: 2 additions & 2 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
)
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
\App\Http\Middleware\HandleInertiaRequests::class,
\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
App\Http\Middleware\HandleInertiaRequests::class,
Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
]);

//
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
],
"license": "MIT",
"require": {
"php": "^8.3",
"php": "^8.4",
"inertiajs/inertia-laravel": "^2.0",
"laravel/framework": "^11.9",
"laravel/framework": "^12.0",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"stuartmcgill/sumoapi-php": "^0.8.0",
Expand All @@ -19,12 +19,14 @@
"require-dev": {
"barryvdh/laravel-debugbar": "^3.14",
"fakerphp/faker": "^1.23",
"larastan/larastan": "^3.0",
"laravel/breeze": "^2.1",
"laravel/pint": "^1.17",
"laravel/pint": "^1.22",
"laravel/sail": "^1.33",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.0",
"phpunit/phpunit": "^11.0.1"
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpunit/phpunit": "^12.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading