Skip to content

Commit 5885628

Browse files
committed
fix: rector
1 parent bcfa4a6 commit 5885628

19 files changed

+137
-56
lines changed

app/Console/Commands/ConvertLegacyBudgetPlans.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ protected function convertPlan(LegacyBudgetPlan $legacyPlan, string $organizatio
147147
'organization' => $organization,
148148
'fiscal_year_id' => $fiscalYear->id,
149149
'state' => $state,
150-
'resolution_date' => $legacyPlan->von,
150+
'resolution_date' => null, // Legacy doesn't have this
151151
'approval_date' => null, // Legacy doesn't have this
152-
'parent_plan' => null,
153152
]);
154153

155154
// Force the ID to match the legacy plan
@@ -300,7 +299,7 @@ protected function getOrCreateFiscalYear(LegacyBudgetPlan $legacyPlan, bool $dry
300299
// Create a new fiscal year
301300
$fiscalYear = new FiscalYear([
302301
'start_date' => $legacyPlan->von,
303-
'end_date' => $legacyPlan->bis,
302+
'end_date' => $legacyPlan->bis ?? $legacyPlan->von->addYear()->subDay(),
304303
]);
305304

306305
if (! $dryRun) {
@@ -310,7 +309,7 @@ protected function getOrCreateFiscalYear(LegacyBudgetPlan $legacyPlan, bool $dry
310309
$fiscalYear->id = 9999;
311310
}
312311

313-
$this->line(" ✓ Created Fiscal Year: {$legacyPlan->von} to {$legacyPlan->bis}");
312+
$this->line(" ✓ Created Fiscal Year: {$fiscalYear->start_date} to {$fiscalYear->end_date}");
314313
}
315314

316315
return $fiscalYear;

app/Livewire/ChatPanel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function render()
3434
public function save()
3535
{
3636

37-
$cleanContent = $this->validate(['content' => ['required', 'min:1', new FluxEditorRule()]])['content'];
37+
$cleanContent = $this->validate(['content' => ['required', 'min:1', new FluxEditorRule]])['content'];
3838

3939
ChatMessage::create([
4040
'text' => $cleanContent,

app/Livewire/ProjectOverview.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use App\Models\Legacy\Project;
88
use App\Services\Auth\AuthService;
99
use Illuminate\Database\Eloquent\Collection;
10-
use Illuminate\Support\Facades\Auth;
1110
use Livewire\Attributes\Computed;
1211
use Livewire\Attributes\Url;
1312
use Livewire\Component;
@@ -49,7 +48,7 @@ public function userCommittees(): array
4948
public function projectsByCommittee(): Collection
5049
{
5150
$budgetPlan = $this->currentBudgetPlan();
52-
if (!$budgetPlan) {
51+
if (! $budgetPlan) {
5352
return [];
5453
}
5554

@@ -91,7 +90,7 @@ public function projectsByCommittee(): Collection
9190
$projects = $query->orderBy('org')->orderBy('id', 'desc')->get();
9291

9392
// Group by committee
94-
return $projects->groupBy(fn($project) => $project->org ?: '');
93+
return $projects->groupBy(fn ($project) => $project->org ?: '');
9594
}
9695

9796
#[Computed]

app/Models/BudgetItem.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,74 @@
2424
* @method static Builder|BudgetItem query()
2525
*
2626
* @mixin Eloquent
27+
*
28+
* @property int $id
29+
* @property int $budget_plan_id
30+
* @property string|null $short_name
31+
* @property string|null $name
32+
* @property \Cknow\Money\Money $value
33+
* @property \App\Models\Enums\BudgetType $budget_type
34+
* @property bool $is_group
35+
* @property string $description
36+
* @property int|null $position
37+
* @property int|null $parent_id
38+
* @property \Illuminate\Support\Carbon|null $created_at
39+
* @property \Illuminate\Support\Carbon|null $updated_at
40+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $children
41+
* @property-read int|null $children_count
42+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, BudgetItem> $orderedChildren
43+
* @property-read int|null $ordered_children_count
44+
* @property-read \App\Models\BudgetItem|null $parent
45+
* @property-read int $depth
46+
* @property-read string $path
47+
* @property-read string $position_path
48+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $ancestors The model's recursive parents.
49+
* @property-read int|null $ancestors_count
50+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $ancestorsAndSelf The model's recursive parents and itself.
51+
* @property-read int|null $ancestors_and_self_count
52+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $bloodline The model's ancestors, descendants and itself.
53+
* @property-read int|null $bloodline_count
54+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $childrenAndSelf The model's direct children and itself.
55+
* @property-read int|null $children_and_self_count
56+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $descendants The model's recursive children.
57+
* @property-read int|null $descendants_count
58+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $descendantsAndSelf The model's recursive children and itself.
59+
* @property-read int|null $descendants_and_self_count
60+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $parentAndSelf The model's direct parent and itself.
61+
* @property-read int|null $parent_and_self_count
62+
* @property-read \App\Models\BudgetItem|null $rootAncestor The model's topmost parent.
63+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $siblings The parent's other children.
64+
* @property-read int|null $siblings_count
65+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $siblingsAndSelf All the parent's children.
66+
* @property-read int|null $siblings_and_self_count
67+
*
68+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, static> all($columns = ['*'])
69+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem breadthFirst()
70+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem depthFirst()
71+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem doesntHaveChildren()
72+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, static> get($columns = ['*'])
73+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem getExpressionGrammar()
74+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem hasChildren()
75+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem hasParent()
76+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem isLeaf()
77+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem isRoot()
78+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem tree($maxDepth = null)
79+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem treeOf(\Illuminate\Database\Eloquent\Model|callable $constraint, $maxDepth = null)
80+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereBudgetPlanId($value)
81+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereBudgetType($value)
82+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereCreatedAt($value)
83+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereDepth($operator, $value = null)
84+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereDescription($value)
85+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereId($value)
86+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereIsGroup($value)
87+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereName($value)
88+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereParentId($value)
89+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem wherePosition($value)
90+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereShortName($value)
91+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereUpdatedAt($value)
92+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem whereValue($value)
93+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem withGlobalScopes(array $scopes)
94+
* @method static \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<static>|BudgetItem withRelationshipExpression($direction, callable $constraint, $initialDepth, $from = null, $maxDepth = null)
2795
*/
2896
class BudgetItem extends Model
2997
{

app/Models/BudgetPlan.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Illuminate\Database\Eloquent\Builder;
1111
use Illuminate\Database\Eloquent\Factories\HasFactory;
1212
use Illuminate\Database\Eloquent\Model;
13+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
14+
use Illuminate\Database\Eloquent\Relations\HasMany;
1315

1416
/**
1517
* App\Models\BudgetPlan
@@ -33,6 +35,22 @@
3335
* @method static Builder|BudgetPlan query()
3436
*
3537
* @mixin Eloquent
38+
*
39+
* @property string|null $organization
40+
* @property int|null $fiscal_year_id
41+
* @property-read \App\Models\FiscalYear|null $fiscalYear
42+
* @property-read \Staudenmeir\LaravelAdjacencyList\Eloquent\Collection<int, \App\Models\BudgetItem> $rootBudgetItems
43+
* @property-read int|null $root_budget_items_count
44+
*
45+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereApprovalDate($value)
46+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereCreatedAt($value)
47+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereFiscalYearId($value)
48+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereId($value)
49+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereOrganization($value)
50+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereParentPlanId($value)
51+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereResolutionDate($value)
52+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereState($value)
53+
* @method static \Illuminate\Database\Eloquent\Builder<static>|BudgetPlan whereUpdatedAt($value)
3654
*/
3755
class BudgetPlan extends Model
3856
{
@@ -60,7 +78,7 @@ protected function casts(): array
6078
];
6179
}
6280

63-
public function budgetItems(): \Illuminate\Database\Eloquent\Relations\HasMany
81+
public function budgetItems(): HasMany
6482
{
6583
return $this->hasMany(BudgetItem::class);
6684
}
@@ -78,12 +96,12 @@ public function budgetItemsTree(BudgetType $budgetType)
7896
return BudgetItem::treeOf($constraint)->orderBy('position_path')->get();
7997
}
8098

81-
public function rootBudgetItems(): Builder|\Illuminate\Database\Eloquent\Relations\HasMany|BudgetPlan
99+
public function rootBudgetItems(): Builder|HasMany|BudgetPlan
82100
{
83101
return $this->hasMany(BudgetItem::class)->whereNull('parent_id');
84102
}
85103

86-
public function fiscalYear(): \Illuminate\Database\Eloquent\Relations\BelongsTo
104+
public function fiscalYear(): BelongsTo
87105
{
88106
return $this->belongsTo(FiscalYear::class);
89107
}

app/Models/Legacy/LegacyBudgetPlan.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ public static function latest(): \Eloquent|static
6060
return self::orderBy('id', 'desc')->first();
6161
}
6262

63-
public static function findByDate(Carbon $date): static
63+
public static function findByDate(?Carbon $date = null): static
6464
{
65+
$date ??= \Illuminate\Support\Facades\Date::now();
66+
6567
return self::query()->where('von', '<=', $date)
6668
->where(fn ($query) => $query->where('bis', '>=', $date)
6769
->orWhereNull('bis'))

app/Policies/BudgetPlanPolicy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ class BudgetPlanPolicy
1212

1313
public function viewAny(User $user): bool
1414
{
15-
return false;
15+
return true;
1616
}
1717

1818
public function view(User $user, BudgetPlan $budgetPlan): bool
1919
{
20-
return false;
20+
return true;
2121
}
2222

2323
public function create(User $user): bool
2424
{
25-
return false;
25+
return $user->getGroups()->contains('ref-finanzen-hv');
2626
}
2727

2828
public function update(User $user, BudgetPlan $budgetPlan): bool
2929
{
30-
return false;
30+
return $user->getGroups()->contains('ref-finanzen-hv');
3131
}
3232

3333
public function delete(User $user, BudgetPlan $budgetPlan): bool

app/Rules/ExactlyOneZeroMoneyRule.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
namespace App\Rules;
44

5-
use Cknow\Money\Rules\Money;
65
use Closure;
76
use Illuminate\Contracts\Validation\DataAwareRule;
87
use Illuminate\Contracts\Validation\ValidationRule;
98
use Illuminate\Support\Collection;
109
use Illuminate\Support\Str;
1110

12-
class ExactlyOneZeroMoneyRule implements ValidationRule, DataAwareRule
11+
class ExactlyOneZeroMoneyRule implements DataAwareRule, ValidationRule
1312
{
14-
1513
private array $data = [];
1614

1715
public function __construct(
@@ -28,21 +26,18 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
2826
// pairs every attribute field with the other field, pair[0] has the actual field, pair[1] can have *'s
2927
$otherAccessors = Str::of($attribute)->explode('.')
3028
->zip(Str::of($this->otherField)->explode('.'))
31-
->map(fn (Collection $pair) => $pair[1] === '*' ? $pair[0] : $pair[1])
32-
;
33-
//dump($otherAccessors);
29+
->map(fn (Collection $pair) => $pair[1] === '*' ? $pair[0] : $pair[1]);
30+
// dump($otherAccessors);
3431
$otherMoney = $this->data;
3532
while (($idx = $otherAccessors->shift()) !== null) {
36-
//dump($otherMoney, $idx, $otherAccessors);
33+
// dump($otherMoney, $idx, $otherAccessors);
3734
$otherMoney = $otherMoney[$idx];
3835
}
39-
//dd($otherMoney);
40-
$oneIsZero = (($value->getAmount() === "0") xor ($otherMoney->getAmount() === "0"));
41-
//dd($value, $otherMoney, ($value->getAmount() === "0"),($otherMoney->getAmount() === "0"), $oneIsZero);
42-
if (!$oneIsZero) {
36+
// dd($otherMoney);
37+
$oneIsZero = (($value->getAmount() === '0') xor ($otherMoney->getAmount() === '0'));
38+
// dd($value, $otherMoney, ($value->getAmount() === "0"),($otherMoney->getAmount() === "0"), $oneIsZero);
39+
if (! $oneIsZero) {
4340
$fail(__('errors.one-money-has-to-be-zero'));
4441
}
4542
}
46-
47-
4843
}

app/Rules/FluxEditorRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FluxEditorRule implements ValidationRule
1616
public function validate(string $attribute, mixed $value, Closure $fail): void
1717
{
1818
$cleanContent = strip_tags((string) $value, '<p><s><br><strong><em><ul><ol><li><a><h1><h2><h3>');
19-
if($cleanContent !== $value) {
19+
if ($cleanContent !== $value) {
2020
$fail(__('errors.flux-editor-malicious-html'));
2121
}
2222
}

app/States/Project/Applied.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
namespace App\States\Project;
44

5-
use App\Rules\ExactlyOneZeroMoneyRule;
6-
use App\Rules\FluxEditorRule;
7-
85
class Applied extends ProjectState
96
{
10-
117
public static string $name = 'wip';
128

139
#[\Override]
@@ -24,7 +20,8 @@ public function color(): string
2420
}
2521

2622
#[\Override]
27-
public function rules() : array{
23+
public function rules(): array
24+
{
2825
return parent::rules();
2926
}
3027
}

0 commit comments

Comments
 (0)