Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
e09ea26a3c | |||
ebfd42a88e | |||
054e6a7cdc |
@@ -16,11 +16,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.4",
|
"php": "^8.4",
|
||||||
"ext-mbstring": "*"
|
"ext-mbstring": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": ">=11.5.6"
|
"phpunit/phpunit": "^12.0.4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
538
composer.lock
generated
538
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -314,18 +314,18 @@ final class ClassMapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Получает значение по умолчанию для разных типов данных.
|
* Возвращает значение по умолчанию для типа $typeName.
|
||||||
*
|
*
|
||||||
* @param string $typeName Имя типа данных.
|
* @param string $typeName Тип
|
||||||
*
|
*
|
||||||
* @return mixed|null Результат.
|
* @return mixed Значение по умолчанию
|
||||||
*/
|
*/
|
||||||
public static function GetDefaults (string $typeName): mixed
|
public static function GetDefaults (string $typeName): mixed
|
||||||
{
|
{
|
||||||
return match ($typeName) {
|
return match (strtolower($typeName)) {
|
||||||
'int' => 0,
|
'int', 'integer' => 0,
|
||||||
'float' => 0.0,
|
'float', 'double' => 0.0,
|
||||||
'bool' => false,
|
'bool', 'boolean' => false,
|
||||||
'string' => '',
|
'string' => '',
|
||||||
'array' => [],
|
'array' => [],
|
||||||
'object' => new stdClass(),
|
'object' => new stdClass(),
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
namespace goodboyalex\php_components_pack\tests\classes;
|
namespace goodboyalex\php_components_pack\tests\classes;
|
||||||
|
|
||||||
use goodboyalex\php_components_pack\classes\ClassMapper;
|
use goodboyalex\php_components_pack\classes\ClassMapper;
|
||||||
|
use goodboyalex\php_components_pack\tests\data\A;
|
||||||
|
use goodboyalex\php_components_pack\tests\data\B;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ClassMapperTest extends TestCase
|
class ClassMapperTest extends TestCase
|
||||||
@@ -11,12 +13,10 @@ class ClassMapperTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->PrepareForTest();
|
$this->PrepareForTest();
|
||||||
|
|
||||||
$a = new \goodboyalex\php_components_pack\tests\data\A();
|
$a = new A('a', 2, true);
|
||||||
$a->a = 'a';
|
|
||||||
$a->b = 2;
|
|
||||||
$a->c = true;
|
|
||||||
|
|
||||||
$b = new B();
|
$b = new B();
|
||||||
|
|
||||||
ClassMapper::MapClass($a, $b);
|
ClassMapper::MapClass($a, $b);
|
||||||
|
|
||||||
$this->assertEquals('a', $b->a);
|
$this->assertEquals('a', $b->a);
|
||||||
|
@@ -1,10 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace goodboyalex\php_components_pack\tests\classes;
|
namespace goodboyalex\php_components_pack\tests\data;
|
||||||
|
|
||||||
class B
|
class B
|
||||||
{
|
{
|
||||||
public string $a;
|
public string $a;
|
||||||
public int $b;
|
public int $b;
|
||||||
public string $d;
|
public string $d;
|
||||||
|
|
||||||
|
public function __construct (string $a = "", int $b = 0, string $d = "")
|
||||||
|
{
|
||||||
|
$this->a = $a;
|
||||||
|
$this->b = $b;
|
||||||
|
$this->d = $d;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user