Skip to content

Commit a1b7833

Browse files
authored
Merge pull request #1715 from dbarzin/coderabbitai/docstrings/7da4b61
📝 Add docstrings to `dev`
2 parents 7da4b61 + 43fa3cf commit a1b7833

File tree

8 files changed

+95
-14
lines changed

8 files changed

+95
-14
lines changed

app/Http/Controllers/Admin/SubnetworkController.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ public function store(StoreSubnetworkRequest $request)
3232
return redirect()->route('admin.subnetworks.index');
3333
}
3434

35+
/**
36+
* Display the form to create a new Subnetwork and prepare selection lists for the view.
37+
*
38+
* Prepares ordered lists for gateways, vlans, networks, subnetworks and distinct non-null
39+
* values for ip_allocation_type, responsible_exp, dmz, wifi, and zone. Aborts with HTTP 403
40+
* if the current user is not authorized to create subnetworks.
41+
*
42+
* @return \Illuminate\View\View The create view populated with the prepared lists:
43+
* `gateways`, `vlans`, `networks`, `subnetworks`,
44+
* `ip_allocation_type_list`, `responsible_exp_list`,
45+
* `dmz_list`, `wifi_list`, and `zone_list`.
46+
*/
3547
public function create()
3648
{
3749
abort_if(Gate::denies('subnetwork_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');
@@ -65,6 +77,15 @@ public function create()
6577
);
6678
}
6779

80+
/**
81+
* Display the edit form for a given subnetwork.
82+
*
83+
* Loads the `connected_subnets` and `gateway` relationships on the provided model
84+
* and prepares lists used to populate select inputs in the edit view.
85+
*
86+
* @param \App\Models\Subnetwork $subnetwork The Subnetwork model to edit.
87+
* @return \Illuminate\View\View The edit view populated with the subnetwork and selection lists.
88+
*/
6889
public function edit(Subnetwork $subnetwork)
6990
{
7091
abort_if(Gate::denies('subnetwork_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');
@@ -132,4 +153,4 @@ public function massDestroy(MassDestroySubnetworkRequest $request)
132153

133154
return response(null, Response::HTTP_NO_CONTENT);
134155
}
135-
}
156+
}

app/Models/NetworkSwitch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function physicalSwitches(): BelongsToMany
5252
/**
5353
* Get VLANs associated with this network switch, ordered by name.
5454
*
55-
* @return BelongsToMany<Vlan, $this> A many-to-many relation for the related `Vlan` models, ordered by the `name` attribute.
55+
* @return BelongsToMany<Vlan, $this> The many-to-many relation instance for the related `Vlan` models.
5656
*/
5757
public function vlans(): BelongsToMany
5858
{

app/Models/Subnetwork.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,36 @@ public function gateway(): BelongsTo
8080
return $this->belongsTo(Gateway::class, 'gateway_id');
8181
}
8282

83-
/** @return BelongsTo<Vlan, $this> */
83+
/**
84+
* Get the Vlan that this subnetwork is associated with.
85+
*
86+
* @return BelongsTo<Vlan, $this> Relationship to the Vlan model.
87+
*/
8488
public function vlan(): BelongsTo
8589
{
8690
return $this->belongsTo(Vlan::class, 'vlan_id');
8791
}
8892

89-
/** @return BelongsTo<Subnetwork, $this> */
93+
/**
94+
* Get the parent subnetwork that this subnetwork belongs to.
95+
*
96+
* @return BelongsTo<Subnetwork, $this> Relation to the parent Subnetwork model.
97+
*/
9098
public function subnetwork(): BelongsTo
9199
{
92100
return $this->belongsTo(Subnetwork::class, 'subnetwork_id');
93101
}
94102

103+
/**
104+
* Produce a human-readable IP range for this subnetwork's CIDR address.
105+
*
106+
* Returns the inclusive range represented by the model's `address` property:
107+
* - For IPv4 CIDRs returns "start - end".
108+
* - For IPv6 CIDRs returns "first -> last".
109+
* - Returns `null` when `address` is null and "N/A" when `address` is missing a prefix or not a valid IP/CIDR.
110+
*
111+
* @return string|null The IP range string, `null` if no address is set, or `"N/A"` for invalid/unparsable addresses.
112+
*/
95113
public function ipRange(): ?string
96114
{
97115
// no address
@@ -228,4 +246,4 @@ public function contains(string $ip): bool
228246

229247
return false;
230248
}
231-
}
249+
}

app/Models/Vlan.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ public function physicalRouters(): BelongsToMany
5050
}
5151

5252
/**
53-
* Get the network switches associated with this VLAN, ordered by name.
53+
* Network switches associated with this VLAN, ordered by name.
5454
*
55-
* @return BelongsToMany<NetworkSwitch, $this> Relation for NetworkSwitch models related to this Vlan, ordered by `name`.
55+
* @return BelongsToMany<NetworkSwitch, $this> Many-to-many relation yielding NetworkSwitch models ordered by `name`.
5656
*/
5757
public function networkSwitches(): BelongsToMany
5858
{
5959
return $this->belongsToMany(NetworkSwitch::class)->orderBy('name');
6060
}
6161

6262
/**
63-
* Get subnetworks belonging to this VLAN ordered by name.
63+
* Retrieve subnetworks that belong to this VLAN, ordered by `name`.
6464
*
6565
* @return HasMany<Subnetwork, $this> Subnetwork models associated with this VLAN, ordered by name.
6666
*/

database/migrations/2025_10_17_073218_add_cluster_logical_server.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
*/
2525
public $withinTransaction = false;
2626

27+
/**
28+
* Move cluster association from logical_servers into a pivot table.
29+
*
30+
* Creates the cluster_logical_server pivot table with a composite primary key and foreign keys,
31+
* backfills it from existing logical_servers.cluster_id values, then removes the foreign key
32+
* (and on non-SQLite drivers the cluster_id column) from logical_servers.
33+
*/
2734
public function up(): void
2835
{
2936

@@ -111,4 +118,4 @@ public function down(): void
111118
// 4) Suppression de la table pivot
112119
Schema::dropIfExists('cluster_logical_server');
113120
}
114-
};
121+
};

database/migrations/2025_10_18_174616_add_cluster_physical_server.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
// SQLite ne gère pas les DDL en transaction -> off
1111
public $withinTransaction = false;
1212

13+
/ **
14+
* Create the cluster_physical_server pivot table, migrate existing cluster associations into it,
15+
* and remove the legacy `cluster_id` column and its related constraints/indexes from physical_servers.
16+
*
17+
* The migration performs three main actions:
18+
* 1. Create the pivot table `cluster_physical_server` with a composite primary key (cluster_id, physical_server_id),
19+
* an index on `physical_server_id`, and cascading foreign keys to `clusters.id` and `physical_servers.id`.
20+
* 2. Backfill the pivot from existing `physical_servers.cluster_id`, inserting (cluster_id, physical_server_id) pairs.
21+
* 3. If `physical_servers.cluster_id` exists, drop its foreign key(s) and related indexes (including defensive attempts
22+
* for common/custom index names and a SQLite-specific purge of indexes containing "cluster_id"), then drop the column.
23+
*/
1324
public function up(): void
1425
{
1526
// 1) Table pivot
@@ -101,6 +112,11 @@ public function up(): void
101112
}
102113
}
103114

115+
/**
116+
* Restores the physical_servers.cluster_id column, repopulates it from the pivot, re-adds the foreign key, and removes the pivot table.
117+
*
118+
* If missing, adds a nullable `cluster_id` column and index on `physical_servers`; sets `cluster_id` to the minimum associated cluster for each physical server based on `cluster_physical_server`; recreates the foreign key to `clusters(id)` with `ON DELETE CASCADE`; and drops the `cluster_physical_server` pivot table.
119+
*/
104120
public function down(): void
105121
{
106122
// 1) Recréer la colonne (nullable) + index
@@ -133,4 +149,4 @@ public function down(): void
133149
// 4) Drop de la table pivot
134150
Schema::dropIfExists('cluster_physical_server');
135151
}
136-
};
152+
};

database/migrations/2025_10_18_183453_add_cluster_router.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
// DDL non transactionnel pour SQLite & co
1111
public $withinTransaction = false;
1212

13+
/**
14+
* Apply migration: create the cluster_router pivot, migrate existing router->cluster relations into it, and remove the routers.cluster_id column and its constraints/indexes.
15+
*
16+
* Creates the cluster_router pivot table with foreign keys to clusters and routers, copies non-null routers.cluster_id values into the pivot (in batches), and then safely removes the cluster_id foreign key, related indexes and the column from the routers table (including defensive handling for legacy constraint/index names and SQLite).
17+
*/
1318
public function up(): void
1419
{
1520
// 1) Table pivot
@@ -98,6 +103,13 @@ public function up(): void
98103
}
99104
}
100105

106+
/**
107+
* Reverts the migration by restoring the routers.cluster_id column and removing the cluster_router pivot.
108+
*
109+
* Restores a nullable unsigned integer `cluster_id` on `routers` (adds an index), populates it from `cluster_router`
110+
* using the minimum `cluster_id` per `router_id`, recreates the foreign key to `clusters.id` with ON DELETE CASCADE,
111+
* and then drops the `cluster_router` table.
112+
*/
101113
public function down(): void
102114
{
103115
// 1) Recréer la colonne (nullable) + index (laisser Laravel nommer)
@@ -130,4 +142,4 @@ public function down(): void
130142
// 4) Drop de la table pivot
131143
Schema::dropIfExists('cluster_router');
132144
}
133-
};
145+
};

database/migrations/2025_11_10_090632_add_subnetwork_link.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
return new class extends Migration
88
{
99
/**
10-
* Run the migrations.
10+
* Add a nullable unsigned `subnetwork_id` column to the `subnetworks` table and create its index and foreign key.
11+
*
12+
* The new `subnetwork_id` column is placed after `network_id`, indexed, and constrained to `subnetworks.id` with
13+
* `ON DELETE SET NULL` behavior.
1114
*/
1215
public function up(): void
1316
{
@@ -24,7 +27,11 @@ public function up(): void
2427
}
2528

2629
/**
27-
* Reverse the migrations.
30+
* Reverts the migration by removing the `subnetwork_id` column and its associated index and foreign key from the `subnetworks` table.
31+
*
32+
* If the `subnetwork_id` column does not exist, the method returns without making changes. On SQLite, foreign key and index removal are skipped and only the column is dropped.
33+
*
34+
* @return void
2835
*/
2936
public function down(): void
3037
{
@@ -40,4 +47,4 @@ public function down(): void
4047
$table->dropColumn('subnetwork_id');
4148
});
4249
}
43-
};
50+
};

0 commit comments

Comments
 (0)