mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-13 07:18:39 +00:00
Fix too strict type definitions
This commit is contained in:
parent
e76606d0a3
commit
c8d938591a
|
|
@ -724,14 +724,15 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
* The reference is stored in the main model
|
* The reference is stored in the main model
|
||||||
*
|
*
|
||||||
* @param string $propertyName Property name to initialize
|
* @param string $propertyName Property name to initialize
|
||||||
* @param object $obj Object to create
|
* @param mixed $obj Object to create
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function createOwnsOne(string $propertyName, object $obj)
|
private static function createOwnsOne(string $propertyName, $obj)
|
||||||
{
|
{
|
||||||
|
if (is_object($obj)) {
|
||||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||||
$primaryKey = $mapper::getObjectId($obj);
|
$primaryKey = $mapper::getObjectId($obj);
|
||||||
|
|
||||||
|
|
@ -742,6 +743,9 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
return $primaryKey;
|
return $primaryKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create owns one
|
* Create owns one
|
||||||
*
|
*
|
||||||
|
|
@ -776,14 +780,15 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
* The reference is stored in the main model
|
* The reference is stored in the main model
|
||||||
*
|
*
|
||||||
* @param string $propertyName Property name to initialize
|
* @param string $propertyName Property name to initialize
|
||||||
* @param object $obj Object to create
|
* @param mixed $obj Object to create
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function createBelongsTo(string $propertyName, object $obj)
|
private static function createBelongsTo(string $propertyName, $obj)
|
||||||
{
|
{
|
||||||
|
if (is_object($obj)) {
|
||||||
/** @var string $mapper */
|
/** @var string $mapper */
|
||||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||||
$primaryKey = $mapper::getObjectId($obj);
|
$primaryKey = $mapper::getObjectId($obj);
|
||||||
|
|
@ -795,6 +800,9 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
return $primaryKey;
|
return $primaryKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create owns one
|
* Create owns one
|
||||||
*
|
*
|
||||||
|
|
@ -1069,20 +1077,24 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
* The reference is stored in the main model
|
* The reference is stored in the main model
|
||||||
*
|
*
|
||||||
* @param string $propertyName Property name to initialize
|
* @param string $propertyName Property name to initialize
|
||||||
* @param object $obj Object to update
|
* @param mixed $obj Object to update
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function updateBelongsTo(string $propertyName, object $obj)
|
private static function updateBelongsTo(string $propertyName, $obj)
|
||||||
{
|
{
|
||||||
|
if (is_object($obj)) {
|
||||||
/** @var string $mapper */
|
/** @var string $mapper */
|
||||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||||
|
|
||||||
return $mapper::update($obj);
|
return $mapper::update($obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update object in db.
|
* Update object in db.
|
||||||
*
|
*
|
||||||
|
|
@ -1269,14 +1281,15 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
* The reference is stored in the main model
|
* The reference is stored in the main model
|
||||||
*
|
*
|
||||||
* @param string $propertyName Property name to initialize
|
* @param string $propertyName Property name to initialize
|
||||||
* @param object $obj Object to delete
|
* @param mixed $obj Object to delete
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function deleteOwnsOne(string $propertyName, object $obj)
|
private static function deleteOwnsOne(string $propertyName, $obj)
|
||||||
{
|
{
|
||||||
|
if (is_object($obj)) {
|
||||||
/** @var string $mapper */
|
/** @var string $mapper */
|
||||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||||
|
|
||||||
|
|
@ -1284,26 +1297,33 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
return $mapper::delete($obj);
|
return $mapper::delete($obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete owns one
|
* Delete owns one
|
||||||
*
|
*
|
||||||
* The reference is stored in the main model
|
* The reference is stored in the main model
|
||||||
*
|
*
|
||||||
* @param string $propertyName Property name to initialize
|
* @param string $propertyName Property name to initialize
|
||||||
* @param object $obj Object to delete
|
* @param mixed $obj Object to delete
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function deleteBelongsTo(string $propertyName, object $obj)
|
private static function deleteBelongsTo(string $propertyName, $obj)
|
||||||
{
|
{
|
||||||
|
if (is_object($obj)) {
|
||||||
/** @var string $mapper */
|
/** @var string $mapper */
|
||||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||||
|
|
||||||
return $mapper::delete($obj);
|
return $mapper::delete($obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete object in db.
|
* Delete object in db.
|
||||||
*
|
*
|
||||||
|
|
@ -2694,14 +2714,14 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
/**
|
/**
|
||||||
* Test if object is null object
|
* Test if object is null object
|
||||||
*
|
*
|
||||||
* @param object $obj Object to check
|
* @param mixed $obj Object to check
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function isNullObject(object $obj) : bool
|
private static function isNullObject($obj) : bool
|
||||||
{
|
{
|
||||||
return strpos(get_class($obj), '\Null') !== false;
|
return \is_object($obj) && \strpos(\get_class($obj), '\Null') !== false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ final class TestUtils
|
||||||
/**
|
/**
|
||||||
* Set private object member
|
* Set private object member
|
||||||
*
|
*
|
||||||
* @param object $obj Object to modify
|
* @param object|string $obj Object to modify
|
||||||
* @param string $name Member name to modify
|
* @param string $name Member name to modify
|
||||||
* @param mixed $value Value to set
|
* @param mixed $value Value to set
|
||||||
*
|
*
|
||||||
|
|
@ -48,9 +48,9 @@ final class TestUtils
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function setMember(object $obj, string $name, $value) : bool
|
public static function setMember($obj, string $name, $value) : bool
|
||||||
{
|
{
|
||||||
$reflectionClass = new \ReflectionClass(\get_class($obj));
|
$reflectionClass = new \ReflectionClass(\is_string($obj) ? $obj : \get_class($obj));
|
||||||
|
|
||||||
if (!$reflectionClass->hasProperty($name)) {
|
if (!$reflectionClass->hasProperty($name)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -62,7 +62,11 @@ final class TestUtils
|
||||||
$reflectionProperty->setAccessible(true);
|
$reflectionProperty->setAccessible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\is_string($obj)) {
|
||||||
|
$reflectionProperty->setValue($value);
|
||||||
|
} elseif (\is_object($obj)) {
|
||||||
$reflectionProperty->setValue($obj, $value);
|
$reflectionProperty->setValue($obj, $value);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$accessible) {
|
if (!$accessible) {
|
||||||
$reflectionProperty->setAccessible(false);
|
$reflectionProperty->setAccessible(false);
|
||||||
|
|
@ -74,16 +78,16 @@ final class TestUtils
|
||||||
/**
|
/**
|
||||||
* Get private object member
|
* Get private object member
|
||||||
*
|
*
|
||||||
* @param object $obj Object to read
|
* @param object|string $obj Object to read
|
||||||
* @param string $name Member name to read
|
* @param string $name Member name to read
|
||||||
*
|
*
|
||||||
* @return mixed Returns the member variable value
|
* @return mixed Returns the member variable value
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function getMember(object $obj, string $name)
|
public static function getMember($obj, string $name)
|
||||||
{
|
{
|
||||||
$reflectionClass = new \ReflectionClass(\get_class($obj));
|
$reflectionClass = new \ReflectionClass(\is_string($obj) ? $obj : \get_class($obj));
|
||||||
|
|
||||||
if (!$reflectionClass->hasProperty($name)) {
|
if (!$reflectionClass->hasProperty($name)) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -95,7 +99,12 @@ final class TestUtils
|
||||||
$reflectionProperty->setAccessible(true);
|
$reflectionProperty->setAccessible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$value = null;
|
||||||
|
if (\is_string($obj)) {
|
||||||
|
$value = $reflectionProperty->getValue();
|
||||||
|
} elseif (\is_object($obj)) {
|
||||||
$value = $reflectionProperty->getValue($obj);
|
$value = $reflectionProperty->getValue($obj);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$accessible) {
|
if (!$accessible) {
|
||||||
$reflectionProperty->setAccessible(false);
|
$reflectionProperty->setAccessible(false);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user