Skip to content

Commit 1e49bc2

Browse files
committed
Update ReflectArray.php
1 parent 024d293 commit 1e49bc2

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed
Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,92 @@
11
<?php
22
namespace Ubiquity\devtools\utils\arrays;
3+
34
use Ubiquity\utils\base\UString;
45

5-
class ReflectArray extends BaseArray{
6+
class ReflectArray extends BaseArray {
7+
68
private $objects;
9+
710
private $properties;
811

9-
public function parse(){
10-
$object=current($this->objects);
11-
if(!isset($object) || !$object){
12-
return [['Nothing to display']];
12+
public function parse() {
13+
$object = current($this->objects);
14+
if (! isset($object) || ! $object) {
15+
return [
16+
[
17+
'Nothing to display'
18+
]
19+
];
1320
}
14-
if(!is_array($this->properties)){
15-
$this->properties=$this->getProperties($object);
21+
if (! is_array($this->properties)) {
22+
$this->properties = $this->getProperties($object);
1623
}
17-
$result=[$this->properties];
18-
$r=new \ReflectionClass($object);
24+
$result = [
25+
$this->properties
26+
];
27+
$r = new \ReflectionClass($object);
1928

20-
foreach ($this->objects as $object){
21-
if(is_array($object)){
22-
$result[]=$object;
23-
}elseif(is_object($object)){
24-
$row=[];
25-
foreach ($this->properties as $prop){
26-
if($r->hasProperty($prop)){
27-
$property=$r->getProperty($prop);
29+
foreach ($this->objects as $object) {
30+
if (is_array($object)) {
31+
$result[] = $object;
32+
} elseif (is_object($object)) {
33+
$row = [];
34+
foreach ($this->properties as $prop) {
35+
if ($r->hasProperty($prop)) {
36+
$property = $r->getProperty($prop);
2837
$property->setAccessible(true);
29-
$row[]=$this->parseValue($property->getValue($object));
30-
}else{
31-
$this->messages[$prop]="Property {$prop} does not exists!";
32-
$row[]='';
38+
$row[] = $this->parseValue($property->getValue($object));
39+
} else {
40+
$this->messages[$prop] = "Property {$prop} does not exists!";
41+
$row[] = '';
3342
}
3443
}
35-
$result[]=$row;
44+
$result[] = $row;
3645
}
3746
}
3847
return $result;
3948
}
4049

41-
private function parseValue($value){
42-
$result="-";
43-
if(is_array($value)){
50+
private function parseValue($value) {
51+
$result = "-";
52+
if (is_array($value)) {
4453
return $this->parseArray($value);
45-
}elseif(UString::isValid($value)){
46-
$result=var_export($value,true);
47-
}else{
48-
$result=$value;
54+
} elseif (UString::isValid($value)) {
55+
$result = var_export($value, true);
56+
} elseif (is_callable($value)) {
57+
$result = '(x)=>{}';
58+
} else {
59+
$result = $value;
4960
}
5061
return $result;
5162
}
5263

53-
private function getProperties($object){
54-
$result=[];
55-
if(is_array($object)){
64+
private function getProperties($object) {
65+
$result = [];
66+
if (is_array($object)) {
5667
return array_keys($object);
5768
}
58-
$reflect=new \ReflectionClass($object);
59-
$properties=$reflect->getProperties();
60-
foreach ($properties as $prop){
61-
$result[]=$prop->getName();
69+
$reflect = new \ReflectionClass($object);
70+
$properties = $reflect->getProperties();
71+
foreach ($properties as $prop) {
72+
$result[] = $prop->getName();
6273
}
6374
return $result;
6475
}
6576

6677
/**
78+
*
6779
* @param mixed $objects
6880
*/
6981
public function setObjects($objects) {
7082
$this->objects = $objects;
7183
}
7284

7385
/**
74-
* @param multitype:NULL $properties
86+
*
87+
* @param multitype:NULL $properties
7588
*/
7689
public function setProperties($properties) {
7790
$this->properties = $properties;
7891
}
79-
8092
}

0 commit comments

Comments
 (0)