-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDepartment.php
More file actions
37 lines (28 loc) · 747 Bytes
/
Copy pathDepartment.php
File metadata and controls
37 lines (28 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace App\Structural\Composite;
use SplObjectStorage;
final class Department implements BudgetedComposite
{
private SplObjectStorage $dependencies;
public function __construct(private string $name)
{
$this->dependencies = new SplObjectStorage();
}
public function calculateBudget(): int
{
$total = 0;
foreach ($this->getDependent() as $dependent) {
$total += $dependent->calculateBudget();
}
return $total;
}
public function getDependent(): SplObjectStorage
{
return $this->dependencies;
}
public function addDependent(Budgeted $item): void
{
$this->dependencies->attach($item);
}
}