Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
16 / 18 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| PlanHubspotConfig | |
88.89% |
16 / 18 |
|
50.00% |
2 / 4 |
4.02 | |
0.00% |
0 / 1 |
| plan | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| scopeForPlan | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPropertyMappings | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| newFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Models; |
| 4 | |
| 5 | use Database\Factories\Http\Models\PlanHubspotConfigFactory; |
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 7 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
| 8 | |
| 9 | /** |
| 10 | * PlanHubspotConfig model for HubSpot CRM property mappings. |
| 11 | * |
| 12 | * Represents a 1:1 relationship with Plans, containing all HubSpot-specific |
| 13 | * property names used for CRM synchronization. This separation keeps HubSpot |
| 14 | * configuration isolated from core plan data. |
| 15 | * |
| 16 | * @property string $_id The config ID |
| 17 | * @property string $plan_id The plan ID (reference to plans._id, unique) |
| 18 | * @property string|null $name Display name in HubSpot (e.g., "Freemium", "Sales Pro") |
| 19 | * @property string|null $last_product Last product name in HubSpot |
| 20 | * @property string|null $cancel_subscription_date HubSpot property name for cancel date |
| 21 | * @property string|null $payment_status HubSpot property name for payment status |
| 22 | * @property string|null $subscription_annual_recurring_revenue HubSpot property name for ARR |
| 23 | * @property string|null $subscription_churn_date HubSpot property name for churn date |
| 24 | * @property string|null $subscription_expiration_date HubSpot property name for expiration date |
| 25 | * @property string|null $subscription_frequency HubSpot property name for billing frequency |
| 26 | * @property string|null $subscription_monthly_recurring_revenue HubSpot property name for MRR |
| 27 | * @property string|null $subscription_plan_type HubSpot property name for plan type |
| 28 | * @property string|null $subscription_start_date HubSpot property name for start date |
| 29 | * @property string|null $subscription_status HubSpot property name for subscription status |
| 30 | * @property string|null $subscription_status_updated_on HubSpot property name for status update timestamp |
| 31 | * @property string|null $user_type HubSpot property name for user type |
| 32 | * @property \Carbon\Carbon|null $created_at |
| 33 | * @property \Carbon\Carbon|null $updated_at |
| 34 | * @property-read Plans|null $plan |
| 35 | */ |
| 36 | class PlanHubspotConfig extends Moloquent |
| 37 | { |
| 38 | use HasFactory; |
| 39 | |
| 40 | /** |
| 41 | * The collection associated with the model. |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | protected $collection = 'plan_hubspot_configs'; |
| 46 | |
| 47 | /** |
| 48 | * The attributes that are mass assignable. |
| 49 | * |
| 50 | * @var array<string> |
| 51 | */ |
| 52 | protected $fillable = [ |
| 53 | 'plan_id', |
| 54 | 'name', |
| 55 | 'last_product', |
| 56 | 'cancel_subscription_date', |
| 57 | 'payment_status', |
| 58 | 'subscription_annual_recurring_revenue', |
| 59 | 'subscription_churn_date', |
| 60 | 'subscription_expiration_date', |
| 61 | 'subscription_frequency', |
| 62 | 'subscription_monthly_recurring_revenue', |
| 63 | 'subscription_plan_type', |
| 64 | 'subscription_start_date', |
| 65 | 'subscription_status', |
| 66 | 'subscription_status_updated_on', |
| 67 | 'user_type', |
| 68 | ]; |
| 69 | |
| 70 | /** |
| 71 | * The attributes that should be cast. |
| 72 | * |
| 73 | * @var array<string, string> |
| 74 | */ |
| 75 | protected $casts = []; |
| 76 | |
| 77 | /** |
| 78 | * Get the plan that this HubSpot config belongs to. |
| 79 | * |
| 80 | * @return BelongsTo<Plans, PlanHubspotConfig> |
| 81 | */ |
| 82 | public function plan(): BelongsTo |
| 83 | { |
| 84 | return $this->belongsTo(Plans::class, 'plan_id'); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Scope a query to filter by plan ID. |
| 89 | * |
| 90 | * @param \Illuminate\Database\Eloquent\Builder<PlanHubspotConfig> $query |
| 91 | * @param string $planId The plan ID to filter by |
| 92 | * @return \Illuminate\Database\Eloquent\Builder<PlanHubspotConfig> |
| 93 | */ |
| 94 | public function scopeForPlan($query, string $planId) |
| 95 | { |
| 96 | return $query->where('plan_id', $planId); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get the HubSpot property mappings as an associative array. |
| 101 | * |
| 102 | * Returns all non-null HubSpot property names for use in CRM sync operations. |
| 103 | * The keys are generic property names, values are the HubSpot-specific property names. |
| 104 | * |
| 105 | * @return array<string, string> Property mappings (only non-null values) |
| 106 | */ |
| 107 | public function getPropertyMappings(): array |
| 108 | { |
| 109 | $properties = [ |
| 110 | 'cancel_subscription_date' => $this->cancel_subscription_date, |
| 111 | 'payment_status' => $this->payment_status, |
| 112 | 'subscription_annual_recurring_revenue' => $this->subscription_annual_recurring_revenue, |
| 113 | 'subscription_churn_date' => $this->subscription_churn_date, |
| 114 | 'subscription_expiration_date' => $this->subscription_expiration_date, |
| 115 | 'subscription_frequency' => $this->subscription_frequency, |
| 116 | 'subscription_monthly_recurring_revenue' => $this->subscription_monthly_recurring_revenue, |
| 117 | 'subscription_plan_type' => $this->subscription_plan_type, |
| 118 | 'subscription_start_date' => $this->subscription_start_date, |
| 119 | 'subscription_status' => $this->subscription_status, |
| 120 | 'subscription_status_updated_on' => $this->subscription_status_updated_on, |
| 121 | 'user_type' => $this->user_type, |
| 122 | ]; |
| 123 | |
| 124 | return array_filter($properties, fn ($value) => $value !== null); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Create a new factory instance for the model. |
| 129 | * |
| 130 | * @return PlanHubspotConfigFactory |
| 131 | */ |
| 132 | protected static function newFactory() |
| 133 | { |
| 134 | return PlanHubspotConfigFactory::new(); |
| 135 | } |
| 136 | } |