Skip to content
Open
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
4 changes: 2 additions & 2 deletions component/Abstract/Value/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Phant\DataStructure\Abstract\Value;

abstract class Boolean
abstract readonly class Boolean
{
public function __construct(
public readonly bool $value
public bool $value
) {
}
}
4 changes: 2 additions & 2 deletions component/Abstract/Value/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Phant\DataStructure\Abstract\Value;

abstract class Decimal
abstract readonly class Decimal
{
public function __construct(
public readonly float $value
public float $value
) {
}
}
4 changes: 2 additions & 2 deletions component/Abstract/Value/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Phant\DataStructure\Abstract\Value;

abstract class Integer
abstract readonly class Integer
{
public function __construct(
public readonly int $value
public int $value
) {
}
}
4 changes: 2 additions & 2 deletions component/Abstract/Value/Varchar.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Phant\Error\NotCompliant;

abstract class Varchar
abstract readonly class Varchar
{
public const PATTERN = null;

public function __construct(
public readonly string $value
public string $value
) {
if (defined(get_class($this) . '::PATTERN') && static::PATTERN && !preg_match(static::PATTERN, $value)) {
throw new NotCompliant('Value : ' . $value);
Expand Down
4 changes: 1 addition & 3 deletions component/Color/Hexadecimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Phant\DataStructure\Color;

use Phant\Error\NotCompliant;

class Hexadecimal extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Hexadecimal extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^#[0-9a-fA-F]{3}$|#[0-9a-fA-F]{6}$|#[0-9a-fA-F]{8}$/';
}
79 changes: 79 additions & 0 deletions component/Company/Euid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Phant\DataStructure\Company;

use Phant\DataStructure\Company\Fr\Siren;
use Phant\Error\NotCompliant;

readonly class Euid extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^(\D{2})(\w+)(\.)(\w+)$/';
private const COUNTRY_CODES = ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'];


public function __construct(
string $euid,
bool $check = true
) {
parent::__construct($euid);

$parts = $this->extractParts();

if (!$parts->countryCode || !in_array($parts->countryCode, self::COUNTRY_CODES)) {
throw new NotCompliant('Not compliant country code');
}

if ($check) {
match ($parts->countryCode) {
'FR' => new Siren($parts->companyCode),
default => null,
};
}
}

public function getFormatted(
bool $nonBreakingSpace = true
): string {
$parts = $this->extractParts();

$euid = implode(' ', [
$parts->countryCode,
$parts->registryCode,
$parts->separator,
self::formatCompanyCode($parts->companyCode),
]);

if ($nonBreakingSpace) {
$euid = str_replace(' ', "\xC2\xA0", $euid); // non breaking space
}

return $euid;
}

public function extractParts(
): object {
preg_match('/^(\D{2})(\w+)(\.)(\w+)$/', $this->value, $matches);

return (object) [
'countryCode' => $matches[1] ?? null,
'registryCode' => $matches[2] ?? null,
'separator' => $matches[3] ?? null,
'companyCode' => $matches[4] ?? null,
];
}

private static function formatCompanyCode(
string $companyCode
): string {
return match (strlen($companyCode)) {
5 => preg_replace('/^(\d{2})(\d{3})$/', '$1 $2', $companyCode),
6 => preg_replace('/^(\d{3})(\d{3})$/', '$1 $2', $companyCode),
7 => preg_replace('/^(\d{3})(\d{4})$/', '$1 $2', $companyCode),
8 => preg_replace('/^(\d{2})(\d{3})(\d{3})$/', '$1 $2 $3', $companyCode),
9 => preg_replace('/^(\d{3})(\d{3})(\d{3})$/', '$1 $2 $3', $companyCode),
default => $companyCode,
};
}
}
2 changes: 1 addition & 1 deletion component/Company/Fr/CodeActivite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Phant\DataStructure\Company\Fr;

class CodeActivite extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class CodeActivite extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^\d{2}\.?\d{1,2}?\w{1}?$/';

Expand Down
8 changes: 4 additions & 4 deletions component/Company/Fr/Siren.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Phant\Error\NotCompliant;

class Siren extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Siren extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^\d{9}$/';

Expand Down Expand Up @@ -39,12 +39,12 @@ public static function luhnCheck(
}

public function getFormatted(
bool $espaceInsecable = true
bool $nonBreakingSpace = true
): string {
$siren = $this->value;
$siren = preg_replace('/^(\d{3})(\d{3})(\d{3})$/', '$1 $2 $3', $siren);
if ($espaceInsecable) {
$siren = str_replace(' ', "\xC2\xA0", $siren); // Espace insécable
if ($nonBreakingSpace) {
$siren = str_replace(' ', "\xC2\xA0", $siren); // non breaking space
}

return $siren;
Expand Down
8 changes: 4 additions & 4 deletions component/Company/Fr/Siret.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Phant\DataStructure\Company\Fr\Siren;
use Phant\Error\NotCompliant;

class Siret extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Siret extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^\d{14}$/';
public const SIREN_LA_POSTE = '356000000';
Expand All @@ -31,12 +31,12 @@ public function getSiren(
}

public function getFormatted(
bool $espaceInsecable = true
bool $nonBreakingSpace = true
): string {
$siret = $this->value;
$siret = preg_replace('/^(\d{3})(\d{3})(\d{3})(\d{5})$/', '$1 $2 $3 $4', $siret);
if ($espaceInsecable) {
$siret = str_replace(' ', "\xC2\xA0", $siret); // Espace insécable
if ($nonBreakingSpace) {
$siret = str_replace(' ', "\xC2\xA0", $siret); // non breaking space
}

return $siret;
Expand Down
2 changes: 1 addition & 1 deletion component/Company/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Phant\DataStructure\Company;

class Name extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Name extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^.{1,}$/';

Expand Down
2 changes: 1 addition & 1 deletion component/Geography/Fr/CodeCommune.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Phant\DataStructure\Geography\Fr;

class CodeCommune extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class CodeCommune extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^[0-9][0-9AB][0-9]{3}$/';

Expand Down
2 changes: 1 addition & 1 deletion component/Geography/Fr/CodePostal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Phant\DataStructure\Geography\Fr;

class CodePostal extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class CodePostal extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^\d{5}$/';

Expand Down
2 changes: 1 addition & 1 deletion component/Geography/Fr/NumeroDepartement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Phant\DataStructure\Geography\Fr;

class NumeroDepartement extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class NumeroDepartement extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/^(9[7-8][0-9])|([0-9]{2})|(2[AB])$/';

Expand Down
6 changes: 3 additions & 3 deletions component/Geography/GpsCoordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Phant\Error\NotCompliant;

class GpsCoordinates
readonly class GpsCoordinates
{
// Format : WGS84 (https://en.wikipedia.org/wiki/World_Geodetic_System)
final public function __construct(
public readonly float $latitude,
public readonly float $longitude
public float $latitude,
public float $longitude
) {
if ($latitude > 90 || $latitude < -90 || $longitude > 180 || $longitude < -180) {
throw new NotCompliant('GPS coordinates: ' . $latitude . ';' . $longitude);
Expand Down
2 changes: 1 addition & 1 deletion component/Id/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Ramsey\Uuid\Uuid as UuidBuilder;
use Ramsey\Uuid\Exception\InvalidUuidStringException;

class Uuid extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Uuid extends \Phant\DataStructure\Abstract\Value\Varchar
{
public const PATTERN = '/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/';

Expand Down
6 changes: 3 additions & 3 deletions component/Key/Ssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Phant\Error\NotCompliant;

final class Ssl
final readonly class Ssl
{
public function __construct(
public readonly string $private,
public readonly string $public
public string $private,
public string $public
) {
}

Expand Down
14 changes: 7 additions & 7 deletions component/Money/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Phant\DataStructure\Money;

class Price
readonly class Price
{
public function __construct(
public readonly float $amount,
public readonly ?Currency $currency,
public readonly ?string $unit
public float $amount,
public ?Currency $currency,
public ?string $unit
) {
}

public function getFormatted(
bool $espaceInsecable = true
bool $nonBreakingSpace = true
): string {
$price = number_format($this->amount, 2, ',', ' ');

Expand All @@ -26,8 +26,8 @@ public function getFormatted(
$price .= '/' . $this->unit;
}

if ($espaceInsecable) {
$price = str_replace(' ', "\xC2\xA0", $price); // Espace insécable
if ($nonBreakingSpace) {
$price = str_replace(' ', "\xC2\xA0", $price); // non breaking space
}

return $price;
Expand Down
6 changes: 3 additions & 3 deletions component/Number/Grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Phant\Error\NotCompliant;

class Grade
readonly class Grade
{
public function __construct(
public readonly int $position,
public readonly int $scale
public int $position,
public int $scale
) {
if ($position < 0) {
throw new NotCompliant('Note : ' . $position);
Expand Down
2 changes: 1 addition & 1 deletion component/Number/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Phant\DataStructure\Number;

class Rate extends \Phant\DataStructure\Abstract\Value\Decimal
readonly class Rate extends \Phant\DataStructure\Abstract\Value\Decimal
{
public function __toString(
) {
Expand Down
2 changes: 1 addition & 1 deletion component/Person/Birthday.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace Phant\DataStructure\Person;

class Birthday extends \Phant\DataStructure\Time\Date
readonly class Birthday extends \Phant\DataStructure\Time\Date
{
}
2 changes: 1 addition & 1 deletion component/Person/Firstname.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Phant\Error\NotCompliant;

class Firstname extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Firstname extends \Phant\DataStructure\Abstract\Value\Varchar
{
public function __construct(
string $firstname
Expand Down
2 changes: 1 addition & 1 deletion component/Person/Lastname.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Phant\Error\NotCompliant;

class Lastname extends \Phant\DataStructure\Abstract\Value\Varchar
readonly class Lastname extends \Phant\DataStructure\Abstract\Value\Varchar
{
public function __construct(
string $lastname
Expand Down
8 changes: 4 additions & 4 deletions component/Time/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Phant\Error\NotCompliant;

class Date
readonly class Date
{
public readonly int $time;
public readonly string $date;
public readonly string $format;
public int $time;
public string $date;
public string $format;
Comment on lines +9 to +13
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is declared as readonly, but properties 'time', 'date', and 'format' need to be assigned in the constructor body (lines 33-35 which are outside the diff region). This is incompatible with readonly classes in PHP 8.2+ where properties can only be initialized via promoted constructor parameters or at declaration. Consider removing the readonly keyword from the class declaration or refactoring the initialization logic.

Copilot uses AI. Check for mistakes.

public function __construct(
int|string $date,
Expand Down
Loading