wip: booking process, refactoring
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Utility;
|
||||
|
||||
class DateCodeUtility
|
||||
{
|
||||
/**
|
||||
* Sanitizes the travel code by removing dashes and slashes, and converting to uppercase.
|
||||
*
|
||||
* @param string $travelCode the travel code to sanitize
|
||||
*
|
||||
* @return string the sanitized travel code
|
||||
*/
|
||||
public function sanitize(string $travelCode): string
|
||||
{
|
||||
return str_replace(['-', '/'], '', strtoupper($travelCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base code (without the date part) from the travel code.
|
||||
*
|
||||
* @param string $travelCode the travel code
|
||||
*
|
||||
* @return string the base code in uppercase
|
||||
*/
|
||||
public function getBaseCode(string $travelCode): string
|
||||
{
|
||||
return strtoupper(substr($travelCode, 0, -6));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the date from the travel code and returns it as a DateTimeImmutable object.
|
||||
*
|
||||
* @param string $travelCode the travel code containing the date
|
||||
*
|
||||
* @return \DateTimeImmutable the extracted date, or null if invalid
|
||||
*/
|
||||
public function getDate(string $travelCode): \DateTimeImmutable
|
||||
{
|
||||
$datePart = substr($travelCode, -6);
|
||||
|
||||
return \DateTimeImmutable::createFromFormat('dmy', $datePart);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Utility;
|
||||
|
||||
class TravelCodeUtility
|
||||
{
|
||||
public function sanitize(string $travelCode): string
|
||||
{
|
||||
return str_replace(['-', '/'], '', strtoupper($travelCode));
|
||||
}
|
||||
|
||||
public function getBaseCode(string $travelCode): string
|
||||
{
|
||||
return strtoupper(substr($travelCode, 0, -6));
|
||||
}
|
||||
|
||||
public function getDate(string $travelCode): \DateTimeImmutable
|
||||
{
|
||||
$datePart = substr($travelCode, -6);
|
||||
|
||||
return \DateTimeImmutable::createFromFormat('dmy', $datePart);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user