Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
65.38% covered (warning)
65.38%
17 / 26
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlanComparisonDTO
65.38% covered (warning)
65.38%
17 / 26
66.67% covered (warning)
66.67%
2 / 3
3.37
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 empty
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\DTO;
4
5/**
6 * Data Transfer Object for plan comparison response.
7 *
8 * Encapsulates all data needed for the plan comparison endpoint response,
9 * providing type safety and structure for comparing features across multiple plans.
10 *
11 * @property array<int, array{id: string, title: string, identifier: string, currency: string, interval: string, unit_amount: int|string}> $plans List of plans being compared
12 * @property array<int, array{key: string, name: string, description: string|null, value_type: string, category: string, display_order: int}> $features List of features in the comparison
13 * @property array<string, array{feature_key: string, feature_name: string, category: string, value_type: string, is_common: bool, values: array<string, array{raw: mixed, display: string}>}> $comparisonMatrix Feature comparison matrix keyed by feature key
14 * @property array<int, array{feature_key: string, feature_name: string, category: string, values: array<string, mixed>}> $differences Features that differ across plans
15 * @property array<string> $commonFeatures Feature keys that are the same across all plans
16 * @property array<string, array{has_config: bool, properties_count: int, name: string|null}> $hubspotStatus HubSpot configuration status per plan
17 * @property array{total_plans: int, total_features: int, common_features_count: int, different_features_count: int, common_percentage: float, categories_covered: array<string>} $summary Summary statistics
18 */
19class PlanComparisonDTO
20{
21    /**
22     * @param  array<int, array{id: string, title: string, identifier: string, currency: string, interval: string, unit_amount: int|string}>  $plans
23     * @param  array<int, array{key: string, name: string, description: string|null, value_type: string, category: string, display_order: int}>  $features
24     * @param  array<string, array{feature_key: string, feature_name: string, category: string, value_type: string, is_common: bool, values: array<string, array{raw: mixed, display: string}>}>  $comparisonMatrix
25     * @param  array<int, array{feature_key: string, feature_name: string, category: string, values: array<string, mixed>}>  $differences
26     * @param  array<string>  $commonFeatures
27     * @param  array<string, array{has_config: bool, properties_count: int, name: string|null}>  $hubspotStatus
28     * @param  array{total_plans: int, total_features: int, common_features_count: int, different_features_count: int, common_percentage: float, categories_covered: array<string>}  $summary
29     */
30    public function __construct(
31        public readonly array $plans,
32        public readonly array $features,
33        public readonly array $comparisonMatrix,
34        public readonly array $differences,
35        public readonly array $commonFeatures,
36        public readonly array $hubspotStatus,
37        public readonly array $summary
38    ) {}
39
40    /**
41     * Convert the DTO to an array.
42     *
43     * @return array<string, mixed>
44     */
45    public function toArray(): array
46    {
47        return [
48            'plans' => $this->plans,
49            'features' => $this->features,
50            'comparison_matrix' => $this->comparisonMatrix,
51            'differences' => $this->differences,
52            'common_features' => $this->commonFeatures,
53            'hubspot_status' => $this->hubspotStatus,
54            'summary' => $this->summary,
55        ];
56    }
57
58    /**
59     * Create an empty DTO with no plans or features.
60     */
61    public static function empty(): self
62    {
63        return new self(
64            plans: [],
65            features: [],
66            comparisonMatrix: [],
67            differences: [],
68            commonFeatures: [],
69            hubspotStatus: [],
70            summary: [
71                'total_plans' => 0,
72                'total_features' => 0,
73                'common_features_count' => 0,
74                'different_features_count' => 0,
75                'common_percentage' => 0.0,
76                'categories_covered' => [],
77            ]
78        );
79    }
80}