Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP74: Deprecated unparenthesed ternary #160

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 83 additions & 83 deletions src/Mouf/Reflection/MoufReflectionProperty.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/*
* This file is part of the Mouf core package.
*
* (c) 2012 David Negrier <david@mouf-php.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
/*
* This file is part of the Mouf core package.
*
* (c) 2012 David Negrier <david@mouf-php.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Mouf\Reflection;

use Mouf\MoufPropertyDescriptor;
use Mouf\MoufPropertyDescriptor;

/**
* Extended Reflection class for class properties that allows usage of annotations.
Expand Down Expand Up @@ -154,57 +154,57 @@ public function equals($compare)
* getDeclaringClass fixing the problem with traits
* (non-PHPdoc)
* @see ReflectionProperty::getDeclaringClass()
*/
*/
function getDeclaringClass() {
if ($this->declaringClass) {
return $this->declaringClass;
}

// Let's scan all traits
$trait = $this->deepScanTraitsForProperty($this->refClass->getTraits());
if ($this->declaringClass) {
return $this->declaringClass;
}
// Let's scan all traits
$trait = $this->deepScanTraitsForProperty($this->refClass->getTraits());
if ($trait != null) {
$this->declaringClass = $trait;
return $trait;
$this->declaringClass = $trait;
return $trait;
}

if ($this->refClass->getParentClass()) {
$declaringClass = null;
if ($this->refClass->getParentClass()->hasProperty($this->getName())) {
$declaringClass = $this->refClass->getParentClass()->getProperty($this->getName())->getDeclaringClass();
}
if ($declaringClass != null) {
return $declaringClass;
}
}
if ($this->refClass->hasProperty($this->getName())) {
return $this->refClass;
if ($declaringClass != null) {
return $declaringClass;
}
}
if ($this->refClass->hasProperty($this->getName())) {
return $this->refClass;
}
return null;

// The property is not part of the traits, let's find in which parent it is part of.
/*$this->declaringClass = $this->getDeclaringClassWithoutTraits();
return $this->declaringClass;*/
}

/**
* Recursive method called to detect a method into a nested array of traits.
*
* @param $traits ReflectionClass[]
* @return ReflectionClass|null
*/
private function deepScanTraitsForProperty(array $traits) {
foreach ($traits as $trait) {
// If the trait has a property, it's a win!
$result = $this->deepScanTraitsForProperty($trait->getTraits(), $this->getName());
if ($result != null) {
return $result;
} else {
if ($trait->hasProperty($this->getName())) {
return $trait;
}
}
}
return null;
return $this->declaringClass;*/
}
/**
* Recursive method called to detect a method into a nested array of traits.
*
* @param $traits ReflectionClass[]
* @return ReflectionClass|null
*/
private function deepScanTraitsForProperty(array $traits) {
foreach ($traits as $trait) {
// If the trait has a property, it's a win!
$result = $this->deepScanTraitsForProperty($trait->getTraits(), $this->getName());
if ($result != null) {
return $result;
} else {
if ($trait->hasProperty($this->getName())) {
return $trait;
}
}
}
return null;
}

/**
Expand Down Expand Up @@ -271,7 +271,7 @@ public function toXml(\SimpleXMLElement $root) {
$node->appendChild($no->createCDATASection($this->getDocComment()));


$propertyNode->addAttribute("modifier", $this->isPrivate() ? 'private' : $this->isProtected() ? "protected" : "public");
$propertyNode->addAttribute("modifier", $this->isPrivate() ? 'private' : ($this->isProtected() ? "protected" : "public"));
$propertyNode->addAttribute("is_static", $this->isStatic() ? "true" : "false");


Expand All @@ -286,46 +286,46 @@ public function toXml(\SimpleXMLElement $root) {
}
}


/**
* Returns a PHP array representing the property.
*
* @return array
*/
public function toJson() {
$result = array();
$result['name'] = $this->getName();
$result['comment'] = $this->getMoufPhpDocComment()->getJsonArray();

/*$properties = $this->getAnnotations("Property");
if (!empty($properties)) {
/**
* Returns a PHP array representing the property.
*
* @return array
*/
public function toJson() {
$result = array();
$result['name'] = $this->getName();
$result['comment'] = $this->getMoufPhpDocComment()->getJsonArray();
/*$properties = $this->getAnnotations("Property");
if (!empty($properties)) {
$result['moufProperty'] = true;*/

try {
try {
$result['default'] = $this->getDefault();

// TODO: is there a need to instanciate a MoufPropertyDescriptor?
$moufPropertyDescriptor = new MoufPropertyDescriptor($this);
$types = $moufPropertyDescriptor->getTypes();
$result['types'] = $types->toJson();

if ($types->getWarningMessage()) {
$result['classinerror'] = $types->getWarningMessage();
// TODO: is there a need to instanciate a MoufPropertyDescriptor?
$moufPropertyDescriptor = new MoufPropertyDescriptor($this);
$types = $moufPropertyDescriptor->getTypes();
$result['types'] = $types->toJson();
if ($types->getWarningMessage()) {
$result['classinerror'] = $types->getWarningMessage();
}

} catch (\Exception $e) {
$result['classinerror'] = $e->getMessage();
}
/*if ($moufPropertyDescriptor->isAssociativeArray()) {
$result['keytype'] = $moufPropertyDescriptor->getKeyType();
}
if ($moufPropertyDescriptor->isArray()) {
$result['subtype'] = $moufPropertyDescriptor->getSubType();
}*/
//}

return $result;
}
} catch (\Exception $e) {
$result['classinerror'] = $e->getMessage();
}
/*if ($moufPropertyDescriptor->isAssociativeArray()) {
$result['keytype'] = $moufPropertyDescriptor->getKeyType();
}
if ($moufPropertyDescriptor->isArray()) {
$result['subtype'] = $moufPropertyDescriptor->getSubType();
}*/
//}
return $result;
}

}
?>