Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Project
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isClosed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getHoursVariance
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Projects\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Domain entity representing a Project in the project management system.
13 *
14 * @package App\Modules\Projects\Domain\Model
15 */
16final readonly class Project
17{
18    /**
19     * @param int         $id              Unique identifier of the project.
20     * @param string      $name            Project title or name.
21     * @param string      $type            Project type classification.
22     * @param string      $status          Current execution status.
23     * @param string      $priority        Priority level.
24     * @param string|null $startDate       Planned starting date.
25     * @param string|null $targetEndDate   Planned deadline or target completion date.
26     * @param string|null $actualEndDate   Actual project closing date.
27     * @param float       $estimatedBudget Planned monetary budget.
28     * @param float       $progress        Completion percentage (0.00 to 100.00).
29     * @param float       $estimatedHours  Total estimated work time in hours.
30     * @param float       $actualHours     Total actual hours logged by contributors.
31     * @param string      $color           Visual color token for Gantt chart representation.
32     */
33    public function __construct(
34        public int $id,
35        public string $name,
36        public string $type = 'implementation',
37        public string $status = 'planned',
38        public string $priority = 'normal',
39        public ?string $startDate = null,
40        public ?string $targetEndDate = null,
41        public ?string $actualEndDate = null,
42        public float $estimatedBudget = 0.0,
43        public float $progress = 0.0,
44        public float $estimatedHours = 0.0,
45        public float $actualHours = 0.0,
46        public string $color = 'primary',
47    ) {
48    }
49
50    /**
51     * Checks whether the project is closed (completed or cancelled).
52     *
53     * @return bool True if closed, false otherwise.
54     */
55    public function isClosed(): bool
56    {
57        return $this->status === 'completed' || $this->status === 'cancelled';
58    }
59
60    /**
61     * Calculates the hours variance between estimated and actual work time.
62     *
63     * @return float Positive value means under budget, negative means over budget.
64     */
65    public function getHoursVariance(): float
66    {
67        return $this->estimatedHours - $this->actualHours;
68    }
69}