Skip to content

Commit

Permalink
refactor: use property promotion in models
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Mar 13, 2024
1 parent 8d4ba0b commit 0d9c9a0
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 385 deletions.
16 changes: 5 additions & 11 deletions src/Models/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

class Area
{
public int $id;

public AreaType $type;

public string $name;

public function __construct(int $id, AreaType $type, string $name)
{
$this->id = $id;
$this->type = $type;
$this->name = $name;
public function __construct(
public int $id,
public AreaType $type,
public string $name
) {
}
}
12 changes: 4 additions & 8 deletions src/Models/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

class Attachment
{
public string $name;

public string $url;

public function __construct(string $name, string $url)
{
$this->name = $name;
$this->url = $url;
public function __construct(
public string $name,
public string $url
) {
}
}
52 changes: 14 additions & 38 deletions src/Models/Detour.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,21 @@

class Detour
{
public string $id;

public bool $external;

public Geometry $geometry;

public string $name;

public Direction $direction;

public ?TransportMode $transportMode;

/**
* @var \Swis\Melvin\Enums\VehicleType[]
*/
public array $vehicleTypes;

/**
* @var \Swis\Melvin\Enums\BoatType[]
*/
public array $boatTypes;

public function __construct(
string $id,
bool $external,
Geometry $geometry,
string $name,
Direction $direction,
?TransportMode $transportMode,
array $vehicleTypes,
array $boatTypes
public string $id,
public bool $external,
public Geometry $geometry,
public string $name,
public Direction $direction,
public ?TransportMode $transportMode,
/**
* @var \Swis\Melvin\Enums\VehicleType[]
*/
public array $vehicleTypes,
/**
* @var \Swis\Melvin\Enums\BoatType[]
*/
public array $boatTypes
) {
$this->id = $id;
$this->external = $external;
$this->geometry = $geometry;
$this->name = $name;
$this->direction = $direction;
$this->transportMode = $transportMode;
$this->vehicleTypes = $vehicleTypes;
$this->boatTypes = $boatTypes;
}
}
16 changes: 5 additions & 11 deletions src/Models/LaneInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@

class LaneInformation
{
public int $numberOfLanesRestricted;

public int $numberOfOperationalLanes;

public int $originalNumberOfLanes;

public function __construct(int $numberOfLanesRestricted, int $numberOfOperationalLanes, int $originalNumberOfLanes)
{
$this->numberOfLanesRestricted = $numberOfLanesRestricted;
$this->numberOfOperationalLanes = $numberOfOperationalLanes;
$this->originalNumberOfLanes = $originalNumberOfLanes;
public function __construct(
public int $numberOfLanesRestricted,
public int $numberOfOperationalLanes,
public int $originalNumberOfLanes
) {
}
}
20 changes: 6 additions & 14 deletions src/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@

class Location
{
public string $city;

public string $road;

public string $district;

public string $comment;

public function __construct(string $city, string $road, string $district, string $comment)
{
$this->city = $city;
$this->road = $road;
$this->district = $district;
$this->comment = $comment;
public function __construct(
public string $city,
public string $road,
public string $district,
public string $comment
) {
}
}
50 changes: 10 additions & 40 deletions src/Models/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,17 @@

class Period
{
public int $id;

public string $name;

public \DateTime $startDate;

public ?\DateTime $endDate;

public bool $repeating;

public ?Week $repeatingAt;

public ?PeriodStatus $status;

public ?bool $overrunning;

public int $order;

public ?int $parentId;

public function __construct(
int $id,
string $name,
\DateTime $startDate,
?\DateTime $endDate,
bool $repeating,
?Week $repeatingAt,
?PeriodStatus $status,
?bool $overrunning,
int $order,
?int $parentId
public int $id,
public string $name,
public \DateTime $startDate,
public ?\DateTime $endDate,
public bool $repeating,
public ?Week $repeatingAt,
public ?PeriodStatus $status,
public ?bool $overrunning,
public int $order,
public ?int $parentId
) {
$this->id = $id;
$this->name = $name;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->repeating = $repeating;
$this->repeatingAt = $repeatingAt;
$this->status = $status;
$this->overrunning = $overrunning;
$this->order = $order;
$this->parentId = $parentId;
}
}
20 changes: 6 additions & 14 deletions src/Models/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@

class Person
{
public string $firstName;

public string $prefix;

public string $lastName;

public PersonType $type;

public function __construct(string $firstName, string $prefix, string $lastName, PersonType $type)
{
$this->firstName = $firstName;
$this->prefix = $prefix;
$this->lastName = $lastName;
$this->type = $type;
public function __construct(
public string $firstName,
public string $prefix,
public string $lastName,
public PersonType $type
) {
}
}
87 changes: 21 additions & 66 deletions src/Models/Restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,28 @@

class Restriction
{
public string $id;

public bool $external;

public ?Geometry $geometry;

public string $name;

public Direction $direction;

public ?TransportMode $transportMode;

public RestrictionType $restrictionType;

/**
* @var \Swis\Melvin\Enums\VehicleType[]
*/
public array $vehicleTypes;

public ?RestrictionExtraInfo $emergencyServices;

public ?RestrictionExtraInfo $publicTransport;

public ?int $maximumSpeed;

public ?LaneInformation $laneInformation;

public ?VehicleInformation $vehicleInformation;

/**
* @var \Swis\Melvin\Enums\RoadManagementType[]
*/
public ?array $roadManagementTypes;

public ?RoadManagementType $roadManagementType;

public function __construct(
string $id,
bool $external,
?Geometry $geometry,
string $name,
Direction $direction,
?TransportMode $transportMode,
RestrictionType $restrictionType,
array $vehicleTypes,
?RestrictionExtraInfo $emergencyServices,
?RestrictionExtraInfo $publicTransport,
?int $maximumSpeed,
?LaneInformation $laneInformation,
?VehicleInformation $vehicleInformation,
?array $roadManagementTypes,
?RoadManagementType $roadManagementType
public string $id,
public bool $external,
public ?Geometry $geometry,
public string $name,
public Direction $direction,
public ?TransportMode $transportMode,
public RestrictionType $restrictionType,
/**
* @var \Swis\Melvin\Enums\VehicleType[]
*/
public array $vehicleTypes,
public ?RestrictionExtraInfo $emergencyServices,
public ?RestrictionExtraInfo $publicTransport,
public ?int $maximumSpeed,
public ?LaneInformation $laneInformation,
public ?VehicleInformation $vehicleInformation,
/**
* @var \Swis\Melvin\Enums\RoadManagementType[]
*/
public ?array $roadManagementTypes,
public ?RoadManagementType $roadManagementType
) {
$this->id = $id;
$this->external = $external;
$this->geometry = $geometry;
$this->name = $name;
$this->direction = $direction;
$this->transportMode = $transportMode;
$this->restrictionType = $restrictionType;
$this->vehicleTypes = $vehicleTypes;
$this->emergencyServices = $emergencyServices;
$this->publicTransport = $publicTransport;
$this->maximumSpeed = $maximumSpeed;
$this->laneInformation = $laneInformation;
$this->vehicleInformation = $vehicleInformation;
$this->roadManagementTypes = $roadManagementTypes;
$this->roadManagementType = $roadManagementType;
}
}
12 changes: 4 additions & 8 deletions src/Models/RestrictionExtraInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

class RestrictionExtraInfo
{
public ?bool $passageAllowed;

public string $description;

public function __construct(?bool $passageAllowed, string $description)
{
$this->passageAllowed = $passageAllowed;
$this->description = $description;
public function __construct(
public ?bool $passageAllowed,
public string $description
) {
}
}
16 changes: 5 additions & 11 deletions src/Models/RoadAuthority.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

class RoadAuthority
{
public int $id;

public ?RoadAuthorityType $type;

public string $name;

public function __construct(int $id, ?RoadAuthorityType $type, string $name)
{
$this->id = $id;
$this->type = $type;
$this->name = $name;
public function __construct(
public int $id,
public ?RoadAuthorityType $type,
public string $name
) {
}
}
Loading

0 comments on commit 0d9c9a0

Please sign in to comment.