Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": "^8.3",
"nesbot/carbon": "^3.0",
"saloonphp/saloon": "^4.0"
},
"require-dev": {
Expand Down
145 changes: 141 additions & 4 deletions src/Data/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,159 @@

namespace NieuwbouwOffice\PhpSdk\Data;

use Carbon\CarbonImmutable;
use NieuwbouwOffice\PhpSdk\Enums\ProjectStatus;

class Project
{
public function __construct(
public readonly string $uuid,
public readonly ?string $parent_uuid,
public readonly string $title,
public readonly string $created_at,
public readonly string $updated_at,
public readonly ?string $municipality,
public readonly ?string $municipality_domain,
public readonly ?string $city,
public readonly ?string $district,
public readonly ?string $neighborhood,
public readonly ?string $postal_code,
public readonly ?float $longitude,
public readonly ?float $latitude,
public readonly ?string $location_description,
public readonly ?string $location_description_html,
public readonly ?string $phase,
public readonly ?ProjectStatus $status,
public readonly ?string $reference_number,
public readonly ?string $description,
public readonly ?string $description_html,
public readonly ?string $html,
public readonly ?bool $has_purchase,
public readonly ?bool $has_rental,
public readonly ?int $purchase_count,
public readonly ?int $purchase_price_from,
public readonly ?int $purchase_price_to,
public readonly ?int $rental_count,
public readonly ?int $rental_price_from,
public readonly ?int $rental_price_to,
public readonly ?int $lot_area_from,
public readonly ?int $lot_area_to,
public readonly ?int $living_area_from,
public readonly ?int $living_area_to,
public readonly ?int $volume_from,
public readonly ?int $volume_to,
public readonly ?int $bedrooms_from,
public readonly ?int $bedrooms_to,
public readonly ?CarbonImmutable $development_date,
public readonly ?CarbonImmutable $presale_date,
public readonly ?CarbonImmutable $sale_date,
public readonly ?CarbonImmutable $construction_date,
public readonly ?CarbonImmutable $delivery_end_date,
public readonly ?int $realization_year,
public readonly ?int $realization_quarter,
public readonly ?int $presale_year,
public readonly ?int $presale_quarter,
public readonly ?int $sale_year,
public readonly ?int $sale_quarter,
public readonly ?int $delivery_start_year,
public readonly ?int $delivery_start_quarter,
public readonly ?int $delivery_end_year,
public readonly ?int $delivery_end_quarter,
public readonly ?int $construction_year,
public readonly ?int $construction_quarter,
public readonly ?string $warranty_institute,
public readonly ?string $warranty_institute_plan_number,
public readonly ?string $lead_party,
public readonly ?string $privacy_statement_url,
public readonly ?string $project_site_url,
public readonly ?string $site_url,
public readonly ?int $children_count,
public readonly CarbonImmutable $created_at,
public readonly CarbonImmutable $updated_at,
) {}

public static function fromResponse(array $data): self
{
return new self(
uuid: $data['Project_UUId'],
parent_uuid: $data['Project_Parent_UUId'] ?? null,
title: $data['Project_Titel'],
created_at: $data['Project_Timestamp'],
updated_at: $data['Laatst_Bijgewerkt'] ?? $data['Project_Timestamp'],
municipality: $data['Gemeente'] ?? null,
municipality_domain: $data['Gemeente_Domein'] ?? null,
city: $data['Plaats'] ?? null,
district: $data['Project_Wijk'] ?? null,
neighborhood: $data['Project_Buurt'] ?? null,
postal_code: $data['Project_Postcode'] ?? null,
longitude: self::toFloat($data['Lng'] ?? null),
latitude: self::toFloat($data['Lat'] ?? null),
location_description: $data['Project_Locatie_Beschrijving'] ?? null,
location_description_html: $data['Project_Locatie_Beschrijving_HTML'] ?? null,
phase: $data['Project_Fase'] ?? null,
status: isset($data['Project_Status_Intern']) ? ProjectStatus::tryFrom($data['Project_Status_Intern']) : null,
reference_number: $data['Project_Referentienummer'] ?? null,
description: $data['Project_Beschrijving_Lang'] ?? null,
description_html: $data['Project_Beschrijving_HTML'] ?? null,
html: $data['Project_HTML'] ?? null,
has_purchase: self::toBool($data['Project_HasKoop'] ?? null),
has_rental: self::toBool($data['Project_HasHuur'] ?? null),
purchase_count: self::toInt($data['Project_Woning_Koop_Aantal'] ?? null),
purchase_price_from: self::toInt($data['Project_Woning_Koop_PrijsVan'] ?? null),
purchase_price_to: self::toInt($data['Project_Woning_Koop_PrijsTot'] ?? null),
rental_count: self::toInt($data['Project_Woning_Huur_Aantal'] ?? null),
rental_price_from: self::toInt($data['Project_Woning_Huur_PrijsVan'] ?? null),
rental_price_to: self::toInt($data['Project_Woning_Huur_PrijsTot'] ?? null),
lot_area_from: self::toInt($data['Project_Woning_KavelOppVan'] ?? null),
lot_area_to: self::toInt($data['Project_Woning_KavelOppTot'] ?? null),
living_area_from: self::toInt($data['Project_Woning_WoonOppVan'] ?? null),
living_area_to: self::toInt($data['Project_Woning_WoonOppTot'] ?? null),
volume_from: self::toInt($data['Project_Woning_InhoudVan'] ?? null),
volume_to: self::toInt($data['Project_Woning_InhoudTot'] ?? null),
bedrooms_from: self::toInt($data['Project_Woning_SlaapkamersVan'] ?? null),
bedrooms_to: self::toInt($data['Project_Woning_SlaapkamersTot'] ?? null),
development_date: self::toCarbon($data['Project_Ontwikkeling_Datum'] ?? null),
presale_date: self::toCarbon($data['Project_Voorverkoop_Datum'] ?? null),
sale_date: self::toCarbon($data['Project_Verkoop_Datum'] ?? null),
construction_date: self::toCarbon($data['Project_Bouw_Datum'] ?? null),
delivery_end_date: self::toCarbon($data['Project_Oplevering_Eind_Datum'] ?? null),
realization_year: self::toInt($data['Project_Realisatie_Jaar'] ?? null),
realization_quarter: self::toInt($data['Project_Realisatie_Kwartaal'] ?? null),
presale_year: self::toInt($data['Project_Voorverkoop_Jaar'] ?? null),
presale_quarter: self::toInt($data['Project_Voorverkoop_Kwartaal'] ?? null),
sale_year: self::toInt($data['Project_Verkoop_Jaar'] ?? null),
sale_quarter: self::toInt($data['Project_Verkoop_Kwartaal'] ?? null),
delivery_start_year: self::toInt($data['Project_Oplevering_Start_Jaar'] ?? null),
delivery_start_quarter: self::toInt($data['Project_Oplevering_Start_Kwartaal'] ?? null),
delivery_end_year: self::toInt($data['Project_Oplevering_Eind_Jaar'] ?? null),
delivery_end_quarter: self::toInt($data['Project_Oplevering_Eind_Kwartaal'] ?? null),
construction_year: self::toInt($data['Project_Bouw_Jaar'] ?? null),
construction_quarter: self::toInt($data['Project_Bouw_Kwartaal'] ?? null),
warranty_institute: $data['Garantie_Instituut'] ?? null,
warranty_institute_plan_number: $data['Plannummer_Garantie_Instituut'] ?? null,
lead_party: $data['Penvoerder'] ?? null,
privacy_statement_url: $data['Privacystatement_URL'] ?? null,
project_site_url: $data['Projectsite_URL'] ?? null,
site_url: $data['Site_URL'] ?? null,
children_count: self::toInt($data['AantalDochters'] ?? null),
created_at: CarbonImmutable::parse($data['Project_Timestamp']),
updated_at: CarbonImmutable::parse($data['Laatst_Bijgewerkt'] ?? $data['Project_Timestamp']),
);
}

private static function toInt(mixed $value): ?int
{
return $value === null ? null : (int) $value;
}

private static function toFloat(mixed $value): ?float
{
return $value === null ? null : (float) $value;
}

private static function toBool(mixed $value): ?bool
{
return $value === null ? null : (bool) (int) $value;
}

private static function toCarbon(mixed $value): ?CarbonImmutable
{
return $value === null ? null : CarbonImmutable::parse($value);
}
}
16 changes: 16 additions & 0 deletions src/Enums/ProjectStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace NieuwbouwOffice\PhpSdk\Enums;

enum ProjectStatus: string
{
case Acquisition = 'Acquisitiefase';
case Development = 'Ontwikkelingsfase';
case ForSaleOrRent = 'In verkoop / verhuur';
case ForSaleOrRentUnderConstruction = 'In verkoop / verhuur, in aanbouw';
case ForSaleOrRentConstructionCompleted = 'In verkoop / verhuur, bouw afgerond';
case SoldOutConstructionCompleted = 'Project uitverkocht, bouw afgerond';
case Cancelled = 'Geannuleerd';
case PreSaleOrPreRent = 'Pre-sale / pre-rent';
case SoldOutUnderConstruction = 'Project uitverkocht, in aanbouw';
}
130 changes: 125 additions & 5 deletions tests/Data/ProjectTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,137 @@
<?php

use Carbon\CarbonImmutable;
use NieuwbouwOffice\PhpSdk\Data\Project;
use NieuwbouwOffice\PhpSdk\Enums\ProjectStatus;

it('exposes its properties as readonly public values', function () {
$createdAt = CarbonImmutable::parse('2026-01-01T00:00:00Z');
$updatedAt = CarbonImmutable::parse('2026-02-01T00:00:00Z');
$presaleDate = CarbonImmutable::parse('2025-12-11');

it('exposes the four properties as readonly public values', function () {
$project = new Project(
uuid: 'abc-123',
parent_uuid: 'parent-uuid',
title: 'Project ABC',
created_at: '2026-01-01T00:00:00Z',
updated_at: '2026-02-01T00:00:00Z',
municipality: 'Groningen',
municipality_domain: 'nieuwbouw-groningen.nl',
city: 'Groningen',
district: 'Centrum',
neighborhood: 'Binnenstad',
postal_code: '9711',
longitude: 6.53264602,
latitude: 53.20888251,
location_description: 'Description',
location_description_html: '<p>Description</p>',
phase: 'Actueel aanbod',
status: ProjectStatus::ForSaleOrRent,
reference_number: 'REF-1',
description: 'Long description',
description_html: '<p>Long</p>',
html: '<p>HTML</p>',
has_purchase: true,
has_rental: false,
purchase_count: 48,
purchase_price_from: 250000,
purchase_price_to: 500000,
rental_count: null,
rental_price_from: null,
rental_price_to: null,
lot_area_from: 100,
lot_area_to: 200,
living_area_from: 80,
living_area_to: 150,
volume_from: 250,
volume_to: 400,
bedrooms_from: 2,
bedrooms_to: 4,
development_date: null,
presale_date: $presaleDate,
sale_date: null,
construction_date: null,
delivery_end_date: null,
realization_year: null,
realization_quarter: null,
presale_year: 2025,
presale_quarter: 4,
sale_year: null,
sale_quarter: null,
delivery_start_year: null,
delivery_start_quarter: null,
delivery_end_year: null,
delivery_end_quarter: null,
construction_year: null,
construction_quarter: null,
warranty_institute: 'SWK',
warranty_institute_plan_number: null,
lead_party: null,
privacy_statement_url: null,
project_site_url: 'https://wonenindesuikerzijde.nl/',
site_url: 'https://wonenindesuikerzijde.nl/',
children_count: 4,
created_at: $createdAt,
updated_at: $updatedAt,
);

expect($project->uuid)->toBe('abc-123')
->and($project->parent_uuid)->toBe('parent-uuid')
->and($project->title)->toBe('Project ABC')
->and($project->created_at)->toBe('2026-01-01T00:00:00Z')
->and($project->updated_at)->toBe('2026-02-01T00:00:00Z');
->and($project->municipality)->toBe('Groningen')
->and($project->municipality_domain)->toBe('nieuwbouw-groningen.nl')
->and($project->city)->toBe('Groningen')
->and($project->district)->toBe('Centrum')
->and($project->neighborhood)->toBe('Binnenstad')
->and($project->postal_code)->toBe('9711')
->and($project->longitude)->toBe(6.53264602)
->and($project->latitude)->toBe(53.20888251)
->and($project->location_description)->toBe('Description')
->and($project->location_description_html)->toBe('<p>Description</p>')
->and($project->phase)->toBe('Actueel aanbod')
->and($project->status)->toBe(ProjectStatus::ForSaleOrRent)
->and($project->reference_number)->toBe('REF-1')
->and($project->description)->toBe('Long description')
->and($project->description_html)->toBe('<p>Long</p>')
->and($project->html)->toBe('<p>HTML</p>')
->and($project->has_purchase)->toBeTrue()
->and($project->has_rental)->toBeFalse()
->and($project->purchase_count)->toBe(48)
->and($project->purchase_price_from)->toBe(250000)
->and($project->purchase_price_to)->toBe(500000)
->and($project->rental_count)->toBeNull()
->and($project->rental_price_from)->toBeNull()
->and($project->rental_price_to)->toBeNull()
->and($project->lot_area_from)->toBe(100)
->and($project->lot_area_to)->toBe(200)
->and($project->living_area_from)->toBe(80)
->and($project->living_area_to)->toBe(150)
->and($project->volume_from)->toBe(250)
->and($project->volume_to)->toBe(400)
->and($project->bedrooms_from)->toBe(2)
->and($project->bedrooms_to)->toBe(4)
->and($project->development_date)->toBeNull()
->and($project->presale_date)->toBe($presaleDate)
->and($project->sale_date)->toBeNull()
->and($project->construction_date)->toBeNull()
->and($project->delivery_end_date)->toBeNull()
->and($project->realization_year)->toBeNull()
->and($project->realization_quarter)->toBeNull()
->and($project->presale_year)->toBe(2025)
->and($project->presale_quarter)->toBe(4)
->and($project->sale_year)->toBeNull()
->and($project->sale_quarter)->toBeNull()
->and($project->delivery_start_year)->toBeNull()
->and($project->delivery_start_quarter)->toBeNull()
->and($project->delivery_end_year)->toBeNull()
->and($project->delivery_end_quarter)->toBeNull()
->and($project->construction_year)->toBeNull()
->and($project->construction_quarter)->toBeNull()
->and($project->warranty_institute)->toBe('SWK')
->and($project->warranty_institute_plan_number)->toBeNull()
->and($project->lead_party)->toBeNull()
->and($project->privacy_statement_url)->toBeNull()
->and($project->project_site_url)->toBe('https://wonenindesuikerzijde.nl/')
->and($project->site_url)->toBe('https://wonenindesuikerzijde.nl/')
->and($project->children_count)->toBe(4)
->and($project->created_at)->toBe($createdAt)
->and($project->updated_at)->toBe($updatedAt);
});
Loading
Loading