Skip to content

Commit

Permalink
Fixes coding style with laravel pint
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-staab committed Nov 10, 2024
1 parent 09aa83f commit 9717f7a
Show file tree
Hide file tree
Showing 159 changed files with 4,400 additions and 3,764 deletions.
10 changes: 5 additions & 5 deletions app/Console/Commands/LegacyMigrateFilesToStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ class LegacyMigrateFilesToStorage extends Command
*/
public function handle()
{
FileInfo::lazy(20)->each(function (FileInfo $fileInfo){
FileInfo::lazy(20)->each(function (FileInfo $fileInfo) {
$data = $fileInfo->fileData;
$link = $fileInfo->link;
$beleg = ExpensesReceipt::find($link);
$expenses_id = $beleg?->auslagen_id;
$pdfData = $data->data;
$hash = $fileInfo->hashname;
$path = "auslagen/$expenses_id/$hash.pdf";
if ($pdfData !== null){
if(empty($data->diskpath)){
if ($pdfData !== null) {
if (empty($data->diskpath)) {
$data->diskpath = $path;
}
if(!\Storage::has($path)){
if (! \Storage::has($path)) {
\Storage::put($path, $pdfData);
}
if ($this->argument('delete') === "true"){
if ($this->argument('delete') === 'true') {
$data->data = null;
}
$data->save();
Expand Down
1 change: 0 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
5 changes: 2 additions & 3 deletions app/Exceptions/LegacyDieException.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Throwable;

class LegacyDieException extends Exception
{
public string $debug;

public function __construct(int $code = 0, string $message = "", string $debug = '', ?Throwable $previous = null)
public function __construct(int $code = 0, string $message = '', string $debug = '', ?Throwable $previous = null)
{
$this->debug = $debug;
parent::__construct($message, $code, $previous);
Expand Down
4 changes: 2 additions & 2 deletions app/Exceptions/LegacyJsonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class LegacyJsonException extends Exception
{

public mixed $content;

public function __construct(mixed $content)
{
$this->content = $content;
parent::__construct("", 200, null);
parent::__construct('', 200, null);
}
}
4 changes: 1 addition & 3 deletions app/Exceptions/LegacyRedirectException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Throwable;

class LegacyRedirectException extends Exception
{
Expand Down
13 changes: 6 additions & 7 deletions app/Exports/LegacyBudgetExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
use Maatwebsite\Excel\Concerns\WithPreCalculateFormulas;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class LegacyBudgetExport implements FromView,
WithColumnFormatting, WithColumnWidths, WithPreCalculateFormulas
class LegacyBudgetExport implements FromView, WithColumnFormatting, WithColumnWidths, WithPreCalculateFormulas
{
use Exportable;

public function __construct(public LegacyBudgetPlan $plan){}
public function __construct(public LegacyBudgetPlan $plan) {}

public function view() : View
public function view(): View
{

return view('exports.legacy.budget-plan', [
Expand All @@ -42,10 +41,11 @@ public function columnFormats(): array
public function sum(string $column, array|Collection $rows)
{
$rows = collect($rows);
$fields = $rows->map(function ($row) use ($column){
$fields = $rows->map(function ($row) use ($column) {
return "$column$row";
})->join(',');
return "=SUM(" . $fields . ")";

return '=SUM('.$fields.')';
}

public function columnWidths(): array
Expand All @@ -58,5 +58,4 @@ public function columnWidths(): array
'E' => 15,
];
}

}
11 changes: 7 additions & 4 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

class AuthController
{
public function __construct(private readonly AuthService $authService) {}

public function __construct(private readonly AuthService $authService){}

public function login(){
public function login()
{
return $this->authService->prepareLogin();
}

Expand All @@ -27,11 +27,14 @@ public function callback(Request $request): RedirectResponse

Auth::login($user);
}

return redirect()->intended(RouteServiceProvider::HOME);
}

public function logout() {
public function logout()
{
Auth::logout();

// call after logout routine
return $this->authService->afterLogout();
}
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/BudgetPlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

class BudgetPlanController extends Controller
{

public function index(){
public function index()
{
$plans = BudgetPlan::orderByDesc('start_date')->get();

return view('budget-plan.index', ['plans' => $plans]);
}

public function show(BudgetPlan $plan){
public function show(BudgetPlan $plan)
{
return view('budget-plan.show');
}
}
5 changes: 2 additions & 3 deletions app/Http/Controllers/Dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class Dev extends Controller
{
function groups()
public function groups()
{
$groups = \Auth::user()?->getGroups();

return view('components.dump', ['dump' => $groups]);
}
}
14 changes: 5 additions & 9 deletions app/Http/Controllers/Legacy/DeleteExpenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\Legacy\Expenses;
use App\Models\Legacy\ExpensesReceipt;
use App\Models\Legacy\FileData;
use App\Models\Legacy\FileInfo;
use App\Models\Legacy\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DeleteExpenses extends Controller
Expand All @@ -22,18 +19,17 @@ public function __invoke(int $expense_id)
$userPerm =
\Auth::user()->getGroups()->contains('ref-finanzen-hv')
|| $project->creator->id === \Auth::user()->id
|| explode(";", $expense->created)[1] === \Auth::user()->username
;
|| explode(';', $expense->created)[1] === \Auth::user()->username;
// authorize state
$deletableState = !in_array(explode(";", $expense->state)[0], ['instructed','booked'], true);
$deletableState = ! in_array(explode(';', $expense->state)[0], ['instructed', 'booked'], true);

if($userPerm === false || $deletableState === false){
if ($userPerm === false || $deletableState === false) {
abort(403);
}
// to make sure to delete everything and not only parts
\DB::beginTransaction();
$reciepts = $expense->receipts;
$reciepts->each(function (ExpensesReceipt $receipt){
$reciepts->each(function (ExpensesReceipt $receipt) {
// delete all posts
$receipt->posts()->delete();
// delete all files db entries (storage later)
Expand All @@ -50,7 +46,7 @@ public function __invoke(int $expense_id)
$expense->delete();

// clean up storage if DB is successfully cleaned
DB::afterCommit(function () use ($expense_id){
DB::afterCommit(function () use ($expense_id) {
\Storage::deleteDirectory("auslagen/{$expense_id}/");
});
\DB::commit();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Legacy/DeleteProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __invoke(int $project_id)
|| $project->creator->id === \Auth::user()->id;
$dataPerm = $project->expenses()->count() === 0;

if($userPerm === false || $dataPerm === false){
if ($userPerm === false || $dataPerm === false) {
abort(403);
}

Expand Down
15 changes: 8 additions & 7 deletions app/Http/Controllers/Legacy/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ class ExportController extends Controller
{
public function budgetPlan(int $id, string $filetype)
{
$writerType = match ($filetype){
"xlsx", "xls" => Excel::XLSX,
"ods" => Excel::ODS,
$writerType = match ($filetype) {
'xlsx', 'xls' => Excel::XLSX,
'ods' => Excel::ODS,
};
$plan = LegacyBudgetPlan::findOrFail($id);
$today = today()->format("Y-m-d");
$start = Carbon::make($plan->von)?->format("y-m");
$end = Carbon::make($plan->bis)?->format("y-m");
$fileName = "$today HHP $start" . ($end ? " bis $end" : '') . ".$filetype";
$today = today()->format('Y-m-d');
$start = Carbon::make($plan->von)?->format('y-m');
$end = Carbon::make($plan->bis)?->format('y-m');
$fileName = "$today HHP $start".($end ? " bis $end" : '').".$filetype";

return (new LegacyBudgetExport($plan))->download($fileName, $writerType);
}
}
39 changes: 24 additions & 15 deletions app/Http/Controllers/Legacy/LegacyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
use forms\projekte\auslagen\AuslagenHandler2;
use framework\DBConnector;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;

class LegacyController extends Controller
{
public function bootstrap() : void {
if (!defined('SYSBASE')) {
public function bootstrap(): void
{
if (! defined('SYSBASE')) {
define('SYSBASE', base_path('/legacy/'));
}
require_once SYSBASE . '/lib/inc.all.php';
require_once SYSBASE.'/lib/inc.all.php';
}

public function render(Request $request)
Expand All @@ -31,30 +32,35 @@ public function render(Request $request)
// if wanted by the unit test the content is delivered without the layout
return $output;
}

// otherwise with
return view('legacy.main', ['content' => $output]);
} catch (LegacyRedirectException $e) {
return $e->redirect;
}catch (LegacyJsonException $e){
} catch (LegacyJsonException $e) {
ob_get_clean();

return response()->json($e->content);
} catch (\Exception $exception){
} catch (\Exception $exception) {
// get rid of the already printed html
ob_get_clean();
throw $exception;
}
}

public function renderFile($auslagen_id, $hash){
public function renderFile($auslagen_id, $hash)
{
$db = DBConnector::getInstance()->dbFetchAll('fileinfo', where: ['hashname' => $hash, 'link' => $auslagen_id]);
$name = $db[0]['filename'] ?? 'error';
$path = "/auslagen/$auslagen_id/$hash/$name.pdf";

return view('components.inlineFile', ['src' => $path]);
}

public function belegePdf(int $project_id, int $auslagen_id, int $version, ?string $file_name = null){
public function belegePdf(int $project_id, int $auslagen_id, int $version, ?string $file_name = null)
{
// file was generated and requested by the iframe
if (!empty($file_name)){
if (! empty($file_name)) {
return \Storage::response(
"auslagen/$auslagen_id/belege-pdf-v$version.pdf",
$file_name
Expand All @@ -72,14 +78,16 @@ public function belegePdf(int $project_id, int $auslagen_id, int $version, ?stri
'project_id' => $project_id,
'auslagen_id' => $auslagen_id,
'version' => $version,
'file_name' => "Belege-IP$project_id-A$auslagen_id.pdf"
'file_name' => "Belege-IP$project_id-A$auslagen_id.pdf",
]);

return view('components.inlineFile', ['src' => $path]);
}

public function zahlungsanweisungPdf(int $project_id, int $auslagen_id, int $version, ?string $file_name = null){
public function zahlungsanweisungPdf(int $project_id, int $auslagen_id, int $version, ?string $file_name = null)
{
// file was generated and requested by the iframe call
if (!empty($file_name)){
if (! empty($file_name)) {
return \Storage::response(
"/auslagen/$auslagen_id/zahlungsanweisung-v$version.pdf",
$file_name
Expand All @@ -97,15 +105,16 @@ public function zahlungsanweisungPdf(int $project_id, int $auslagen_id, int $ver
'project_id' => $project_id,
'auslagen_id' => $auslagen_id,
'version' => $version,
'file_name' => "Zahlungsanweisung-IP$project_id-A$auslagen_id.pdf"
'file_name' => "Zahlungsanweisung-IP$project_id-A$auslagen_id.pdf",
]);

return view('components.inlineFile', ['src' => $path]);
}

public function deliverFile($auslagen_id, $fileHash, $fileName) : StreamedResponse
public function deliverFile($auslagen_id, $fileHash, $fileName): StreamedResponse
{
$path = "/auslagen/$auslagen_id/$fileHash.pdf";
if (\Storage::exists($path)){
if (\Storage::exists($path)) {
return \Storage::response($path, $fileName);
}
throw new FileNotFoundException("Datei $path konnte nicht gefunden werden");
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Middleware/LegacyMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Response;

class LegacyMiddleware
Expand All @@ -16,7 +15,7 @@ class LegacyMiddleware
*/
public function handle(Request $request, Closure $next, string $groupName): Response
{
if(\Auth::user()?->getGroups()->contains($groupName)){
if (\Auth::user()?->getGroups()->contains($groupName)) {
return $next($request);
}
//dump($groupName);
Expand Down
1 change: 0 additions & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class RedirectIfAuthenticated
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
Expand Down
Loading

0 comments on commit 9717f7a

Please sign in to comment.