Skip to content

Commit a14b09e

Browse files
authored
Merge pull request #18 from Oktey/php7.2/sizeof
Php7.2/sizeof
2 parents 6e2a2d6 + 84cdae9 commit a14b09e

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

Result/Result.php

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
/**
33
* Novutec Domain Tools
4-
*
4+
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -165,7 +165,7 @@ class Result extends AbstractResult
165165

166166
/**
167167
* Have contacts been parsed?
168-
*
168+
*
169169
* @var boolean
170170
* @access protected
171171
*/
@@ -214,7 +214,7 @@ public function addItem($target, $value, $append = false)
214214
if ($this->lastHandle !== strtolower($value)) {
215215
$this->lastId = - 1;
216216
}
217-
217+
218218
$this->lastHandle = strtolower($value);
219219
$this->lastId++;
220220
return;
@@ -229,7 +229,7 @@ public function addItem($target, $value, $append = false)
229229
// split target by :
230230
$targetArray = explode(':', $target);
231231
$element = &$this;
232-
232+
233233
// lookup target to determine where we should add the item
234234
foreach ($targetArray as $key => $type) {
235235
if ($targetArray[0] === 'contacts' && $key === 1 && sizeof($targetArray) === 2) {
@@ -246,7 +246,7 @@ public function addItem($target, $value, $append = false)
246246
if ($this->lastHandle !== $networkContactKey) {
247247
$this->lastId = - 1;
248248
}
249-
249+
250250
$this->lastHandle = $networkContactKey;
251251
$this->lastId++;
252252
unset($this->network->contacts->{$networkContactKey}[$multiContactKey]);
@@ -266,14 +266,14 @@ public function addItem($target, $value, $append = false)
266266
}
267267
}
268268
}
269-
269+
270270
if (! isset($this->contacts->{$this->lastHandle}[$this->lastId])) {
271271
if (null === $this->lastHandle) {
272272
continue;
273273
}
274274
$this->contacts->{$this->lastHandle}[$this->lastId] = new Contact();
275275
}
276-
276+
277277
$this->contacts->{$this->lastHandle}[$this->lastId]->$type = $value;
278278
} else {
279279
// if last element of target is reached we need to add value
@@ -285,14 +285,14 @@ public function addItem($target, $value, $append = false)
285285
}
286286
break;
287287
}
288-
288+
289289
if (! isset($element->$type)) {
290290
switch ($targetArray[0]) {
291291
case 'contacts':
292292
if (empty($element->$type)) {
293293
$element->$type = array();
294294
}
295-
295+
296296
array_push($element->$type, new Contact());
297297
break;
298298
case 'registrar':
@@ -302,7 +302,7 @@ public function addItem($target, $value, $append = false)
302302
$element->$type = new \stdClass();
303303
}
304304
}
305-
305+
306306
$element = &$element->$type;
307307
}
308308
}
@@ -320,15 +320,15 @@ public function addItem($target, $value, $append = false)
320320

321321
/**
322322
* Resets the result properties to empty
323-
*
323+
*
324324
* @return void
325325
*/
326326
public function reset()
327327
{
328328
foreach ($this as $key => $value) {
329329
$this->$key = null;
330330
}
331-
331+
332332
// need to set contacts to stdClass otherwise it will not working to
333333
// add items again
334334
$this->contacts = new \stdClass();
@@ -337,7 +337,7 @@ public function reset()
337337

338338
/**
339339
* Convert properties to json
340-
*
340+
*
341341
* @return string
342342
*/
343343
public function toJson()
@@ -347,27 +347,27 @@ public function toJson()
347347

348348
/**
349349
* Convert properties to array
350-
*
350+
*
351351
* @return array
352352
*/
353353
public function toArray()
354354
{
355355
$output = get_object_vars($this);
356356
$contacts = array();
357357
$network = array();
358-
358+
359359
// lookup all contact handles and convert to array
360360
foreach ($this->contacts as $type => $handle) {
361361
foreach ($handle as $number => $object) {
362362
$contacts[$type][$number] = $object->toArray();
363363
}
364364
}
365365
$output['contacts'] = $contacts;
366-
366+
367367
if (! empty($this->registrar)) {
368368
$output['registrar'] = $this->registrar->toArray();
369369
}
370-
370+
371371
if (! empty($this->network)) {
372372
// lookup network for all properties
373373
foreach ($this->network as $type => $value) {
@@ -384,7 +384,7 @@ public function toArray()
384384
}
385385
$output['network'] = $network;
386386
}
387-
387+
388388
return $output;
389389
}
390390

@@ -407,32 +407,32 @@ public function toXml()
407407
{
408408
$xml = new \SimpleXMLElement(
409409
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><whois></whois>');
410-
410+
411411
$output = get_object_vars($this);
412-
412+
413413
// lookup all object variables
414414
foreach ($output as $name => $var) {
415415
// if variable is an array add it to xml
416416
if (is_array($var)) {
417417
$child = $xml->addChild($name);
418-
418+
419419
foreach ($var as $firstKey => $firstValue) {
420420
$child->addChild('item', trim(htmlspecialchars($firstValue)));
421421
}
422422
} elseif (is_object($var)) {
423423
// if variable is an object we need to convert it to array
424424
$child = $xml->addChild($name);
425-
425+
426426
// if it is not a stdClass object we have the toArray() method
427427
if (! $var instanceof \stdClass) {
428428
$firstArray = $var->toArray();
429-
429+
430430
foreach ($firstArray as $firstKey => $firstValue) {
431431
if (! is_array($firstValue)) {
432432
$child->addChild($firstKey, trim(htmlspecialchars($firstValue)));
433433
} else {
434434
$secondChild = $child->addChild($firstKey);
435-
435+
436436
foreach ($firstValue as $secondKey => $secondString) {
437437
$secondChild->addChild('item', trim(htmlspecialchars($secondString)));
438438
}
@@ -441,31 +441,31 @@ public function toXml()
441441
} else {
442442
// if it is an stdClass object we need to convert it
443443
// manually
444-
444+
445445
// lookup all properties of stdClass and convert it
446446
foreach ($var as $firstKey => $firstValue) {
447447
if (! $firstValue instanceof \stdClass && ! is_array($firstValue) &&
448448
! is_string($firstValue)) {
449449
$secondChild = $child->addChild($firstKey);
450-
450+
451451
$firstArray = $firstValue->toArray();
452-
452+
453453
foreach ($firstArray as $secondKey => $secondValue) {
454454
$secondChild->addChild($secondKey, trim(htmlspecialchars($secondValue)));
455455
}
456456
} elseif (is_array($firstValue)) {
457457
$secondChild = $child->addChild($firstKey);
458-
458+
459459
foreach ($firstValue as $secondKey => $secondValue) {
460460
$secondArray = $secondValue->toArray();
461461
$thirdChild = $secondChild->addChild('item');
462-
462+
463463
foreach ($secondArray as $thirdKey => $thirdValue) {
464464
if (! is_array($thirdValue)) {
465465
$thirdChild->addChild($thirdKey, trim(htmlspecialchars($thirdValue)));
466466
} else {
467467
$fourthChild = $thirdChild->addChild($thirdKey);
468-
468+
469469
foreach ($thirdValue as $fourthKey => $fourthValue) {
470470
$fourthChild->addChild('item', trim(htmlspecialchars($fourthValue)));
471471
}
@@ -481,47 +481,47 @@ public function toXml()
481481
$xml->addChild($name, trim($var));
482482
}
483483
}
484-
484+
485485
return $xml->asXML();
486486
}
487487

488488
/**
489489
* cleanUp method will be called before output
490-
*
490+
*
491491
* @return void
492492
*/
493493
public function cleanUp($config, $dateformat)
494494
{
495495
// add WHOIS server to output
496496
$this->addItem('whoisserver', ($config['adapter'] === 'http') ? $config['server'] .
497497
str_replace('%domain%', $this->name, $config['format']) : $config['server']);
498-
498+
499499
// remove helper vars from result
500500
if (isset($this->lastId)) {
501501
unset($this->lastId);
502502
}
503-
503+
504504
if (isset($this->lastHandle)) {
505505
unset($this->lastHandle);
506506
}
507-
508-
if (isset($this->network->contacts) && sizeof($this->network->contacts) === 1) {
507+
508+
if (isset($this->network->contacts) && !empty($this->network->contacts)) {
509509
$this->network = null;
510510
}
511-
511+
512512
// format dates
513513
$this->template[$this->whoisserver] = $config['template'];
514514
$this->changed = $this->formatDate($dateformat, $this->changed);
515515
$this->created = $this->formatDate($dateformat, $this->created);
516516
$this->expires = $this->formatDate($dateformat, $this->expires);
517-
517+
518518
foreach ($this->contacts as $contactType => $contactArray) {
519519
foreach ($contactArray as $contactObject) {
520520
$contactObject->created = $this->formatDate($dateformat, $contactObject->created);
521521
$contactObject->changed = $this->formatDate($dateformat, $contactObject->changed);
522522
}
523523
}
524-
524+
525525
// check if contacts have been parsed
526526
if (sizeof(get_object_vars($this->contacts)) > 0) {
527527
$this->addItem('parsedContacts', true);
@@ -550,4 +550,4 @@ private function formatDate($dateformat, $date)
550550

551551
return (strlen($timestamp) ? strftime($dateformat, $timestamp) : $date);
552552
}
553-
}
553+
}

0 commit comments

Comments
 (0)