mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-13 01:51:50 +01:00
Minor refactoring
This commit is contained in:
@@ -322,8 +322,8 @@ class Reflection
|
|||||||
$values = [];
|
$values = [];
|
||||||
$objects = Arrays::makeArray($objects);
|
$objects = Arrays::makeArray($objects);
|
||||||
|
|
||||||
foreach ($objects as $entity) {
|
foreach ($objects as $object) {
|
||||||
$value = self::getPropertyValue($entity, $property, $force);
|
$value = self::getPropertyValue($object, $property, $force);
|
||||||
|
|
||||||
if (null !== $value) {
|
if (null !== $value) {
|
||||||
$values[] = $value;
|
$values[] = $value;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class F
|
|||||||
private $accountBalance;
|
private $accountBalance;
|
||||||
private $city;
|
private $city;
|
||||||
private $country;
|
private $country;
|
||||||
private $gInstance;
|
private $g;
|
||||||
|
|
||||||
public function __construct($accountBalance, $city, $country, $username, $firstName = 'John', $lastName = 'Scott')
|
public function __construct($accountBalance, $city, $country, $username, $firstName = 'John', $lastName = 'Scott')
|
||||||
{
|
{
|
||||||
@@ -29,7 +29,7 @@ class F
|
|||||||
$this->city = $city;
|
$this->city = $city;
|
||||||
$this->country = $country;
|
$this->country = $country;
|
||||||
$this->username = $username;
|
$this->username = $username;
|
||||||
$this->gInstance = new G($firstName, $lastName);
|
$this->g = new G($firstName, $lastName);
|
||||||
|
|
||||||
// Called to avoid "Unused private method getAccountBalance" warning only
|
// Called to avoid "Unused private method getAccountBalance" warning only
|
||||||
$this->getAccountBalance();
|
$this->getAccountBalance();
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
public function testGetPropertyValueFromChain()
|
public function testGetPropertyValueFromChain()
|
||||||
{
|
{
|
||||||
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
||||||
self::assertEquals('John', Reflection::getPropertyValue($f, 'gInstance.firstName'));
|
self::assertEquals('John', Reflection::getPropertyValue($f, 'g.firstName'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueWithPublicGetter()
|
public function testGetPropertyValueWithPublicGetter()
|
||||||
@@ -381,8 +381,8 @@ class ReflectionTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
||||||
|
|
||||||
self::assertEquals(['John'], Reflection::getPropertyValues($f, 'gInstance.firstName'));
|
self::assertEquals(['John'], Reflection::getPropertyValues($f, 'g.firstName'));
|
||||||
self::assertEquals(['John'], Reflection::getPropertyValues($f, 'gInstance.firstName', true));
|
self::assertEquals(['John'], Reflection::getPropertyValues($f, 'g.firstName', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesFromChainAndMultipleObjects()
|
public function testGetPropertyValuesFromChainAndMultipleObjects()
|
||||||
@@ -399,13 +399,13 @@ class ReflectionTest extends BaseTestCase
|
|||||||
new F(3000, 'Tokyo', 'Japan', 'john.scott', 'Peter', 'Brown'),
|
new F(3000, 'Tokyo', 'Japan', 'john.scott', 'Peter', 'Brown'),
|
||||||
];
|
];
|
||||||
|
|
||||||
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'gInstance.firstName'));
|
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'g.firstName'));
|
||||||
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'gInstance.firstName', true));
|
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'g.firstName', true));
|
||||||
|
|
||||||
$collection = new Collection($objects);
|
$collection = new Collection($objects);
|
||||||
|
|
||||||
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'gInstance.firstName'));
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'g.firstName'));
|
||||||
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'gInstance.firstName', true));
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'g.firstName', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMaxNumberConstantUsingClassWithoutConstants()
|
public function testGetMaxNumberConstantUsingClassWithoutConstants()
|
||||||
@@ -730,7 +730,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
'UnKnown'
|
'UnKnown'
|
||||||
),
|
),
|
||||||
[
|
[
|
||||||
'gInstance' => new G(),
|
'g' => new G(),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user