diff --git a/src/DataTable.php b/src/DataTable.php index be5e69b..79dbd3e 100644 --- a/src/DataTable.php +++ b/src/DataTable.php @@ -96,8 +96,7 @@ class DataTable extends SetterGetter */ public function __construct($data = null) { - if(isset($data)) - { + if (isset($data)) { $this->loadData($data); } $this->init(); @@ -111,17 +110,12 @@ public function __construct($data = null) */ public function loadData($data) { - if($data != null) - { - if($data instanceof MagicObject) - { + if ($data != null) { + if ($data instanceof MagicObject) { $values = $data->value(); - try - { + try { $this->_tableInfo = $data->tableInfo(); - } - catch(Exception $e) - { + } catch (Exception $e) { $this->_tableInfo = null; } foreach ($values as $key => $value) { @@ -129,8 +123,7 @@ public function loadData($data) $this->set($key2, $value); $this->_labels[$key2] = $data->label($key2); } - } - else if (is_array($data) || is_object($data)) { + } elseif (is_array($data) || is_object($data)) { foreach ($data as $key => $value) { $key2 = PicoStringUtil::camelize(str_replace("-", "_", $key)); $this->set($key2, $value); @@ -151,8 +144,7 @@ public function loadData($data) public function addLanguage($code, $reference, $use = false) { $this->_lableLanguage[$code] = new PicoLanguage($reference); - if($use) - { + if ($use) { $this->selectLanguage($code); } return $this; @@ -166,12 +158,10 @@ public function addLanguage($code, $reference, $use = false) */ public function removeLanguage($code) { - if(isset($this->_lableLanguage[$code])) - { + if (isset($this->_lableLanguage[$code])) { unset($this->_lableLanguage[$code]); } - if(!empty($this->_lableLanguage)) - { + if (!empty($this->_lableLanguage)) { $keys = array_keys($this->_lableLanguage); $this->selectLanguage($keys[0]); } @@ -203,17 +193,15 @@ private function init() $classList = $reflexClass->parseKeyValueAsObject($reflexClass->getFirstParameter(self::CLASS_LIST)); $prefLanguage = $reflexClass->parseKeyValueAsObject($reflexClass->getFirstParameter(self::ANNOTATION_LANGUAGE)); $defaultColumnName = $reflexClass->parseKeyValueAsObject($reflexClass->getFirstParameter(self::ANNOTATION_DEFAULT_COLUMN_LABEL)); - if($defaultColumnName->issetContent()) - { + + if ($defaultColumnName->issetContent()) { $this->_defaultColumnName = $defaultColumnName->getContent(); } - if($classList->issetContent()) - { + if ($classList->issetContent()) { $this->_classList = explode(" ", preg_replace('/\s+/', " ", $classList->getContent())); $this->_classList = array_unique($this->_classList); } - if($prefLanguage->issetContent()) - { + if ($prefLanguage->issetContent()) { $this->_currentLanguage = $prefLanguage->getContent(); } $this->_tableIdentity = $reflexClass->parseKeyValueAsObject($reflexClass->getFirstParameter(self::ANNOTATION_TABLE)); @@ -232,28 +220,25 @@ protected function propertyList($reflectSelf = false, $asArrayProps = false) $reflectionClass = $reflectSelf ? self::class : get_called_class(); $class = new ReflectionClass($reflectionClass); - // filter only the calling class properties - // skip parent properties + // Filter only the calling class properties + // Skip parent properties $properties = array_filter( $class->getProperties(), - function($property) use($class) { + function ($property) use ($class) { return $property->getDeclaringClass()->getName() == $class->getName(); } ); - if($asArrayProps) - { + + if ($asArrayProps) { $result = array(); $index = 0; foreach ($properties as $key) { $prop = $key->name; $result[$index] = $prop; - $index++; } return $result; - } - else - { + } else { return $properties; } } @@ -269,11 +254,9 @@ function($property) use($class) { */ private function annotationContent($reflexProp, $parameters, $annotation, $attribute) { - if($parameters->get($annotation) != null) - { + if ($parameters->get($annotation) != null) { $attrs = $reflexProp->parseKeyValueAsObject($parameters->get($annotation)); - if($attrs->get($attribute) != null) - { + if ($attrs->get($attribute) != null) { return $attrs->get($attribute); } } @@ -292,25 +275,17 @@ private function annotationContent($reflexProp, $parameters, $annotation, $attri private function label($reflexProp, $parameters, $key, $defaultLabel) { $label = $defaultLabel; - if(stripos($this->_defaultColumnName, "->")) - { + if (stripos($this->_defaultColumnName, "->")) { $cn = explode("->", $this->_defaultColumnName); $lbl = $this->annotationContent($reflexProp, $parameters, trim($cn[0]), trim($cn[1])); $label = PicoStringUtil::selectNotNull($lbl, $defaultLabel); - - } - else if($this->_defaultColumnName == self::ANNOTATION_LANGUAGE) - { - if(isset($this->_lableLanguage) && isset($this->_lableLanguage[$this->_currentLanguage])) - { + } elseif ($this->_defaultColumnName == self::ANNOTATION_LANGUAGE) { + if (isset($this->_lableLanguage) && isset($this->_lableLanguage[$this->_currentLanguage])) { $label = $this->_lableLanguage[$this->_currentLanguage]->isset($key) ? $this->_lableLanguage[$this->_currentLanguage]->get($key) : $defaultLabel; - } - else - { + } else { $lbl = $this->annotationContent($reflexProp, $parameters, "Label", "content"); $label = PicoStringUtil::selectNotNull($lbl, $defaultLabel); } - } return $label; } @@ -326,22 +301,18 @@ private function label($reflexProp, $parameters, $key, $defaultLabel) */ private function appendByProp($doc, $tbody, $props, $className) { - foreach($props as $prop) - { + foreach ($props as $prop) { $key = $prop->name; $label = $key; $value = $this->get($key); - if(is_scalar($value)) - { + if (is_scalar($value)) { $tr = $tbody->appendChild($doc->createElement(self::TAG_TR)); $reflexProp = new PicoAnnotationParser($className, $key, PicoAnnotationParser::PROPERTY); - if($reflexProp != null) - { + if ($reflexProp != null) { $parameters = $reflexProp->getParametersAsObject(); - if($parameters->issetLabel()) - { + if ($parameters->issetLabel()) { $label = $this->label($reflexProp, $parameters, $key, $label); } } @@ -367,10 +338,8 @@ private function appendByProp($doc, $tbody, $props, $className) */ private function appendByValues($doc, $tbody, $values) { - foreach($values as $propertyName=>$value) - { - if(is_scalar($value)) - { + foreach ($values as $propertyName => $value) { + if (is_scalar($value)) { $tr = $tbody->appendChild($doc->createElement(self::TAG_TR)); $label = $this->getLabel($propertyName); @@ -394,22 +363,15 @@ private function appendByValues($doc, $tbody, $values) private function getLabel($propertyName) { $label = ""; - if(isset($this->_lableLanguage[$this->_currentLanguage])) - { + if (isset($this->_lableLanguage[$this->_currentLanguage])) { $language = $this->_lableLanguage[$this->_currentLanguage]; - $label = $language->get($propertyName); - - } - else - { - if(isset($this->_labels[$propertyName])) - { + } else { + if (isset($this->_labels[$propertyName])) { $label = $this->_labels[$propertyName]; } } - if(empty($label)) - { + if (empty($label)) { $label = PicoStringUtil::camelToTitle($propertyName); } return $label; @@ -423,10 +385,9 @@ private function getLabel($propertyName) */ public function addClass($className) { - if(PicoTableUtil::isValidClassName($className)) - { + if (PicoTableUtil::isValidClassName($className)) { $this->_classList[] = $className; - // fix duplicated class + // Fix duplicated class $this->_classList = array_unique($this->_classList); } return $this; @@ -440,17 +401,10 @@ public function addClass($className) */ public function removeClass($className) { - if(PicoTableUtil::isValidClassName($className)) - { - $tmp = array(); - foreach($this->_classList as $cls) - { - if($cls != $className) - { - $tmp[] = $cls; - } - } - $this->_classList = $tmp; + if (PicoTableUtil::isValidClassName($className)) { + $this->_classList = array_filter($this->_classList, function ($cls) use ($className) { + return $cls != $className; + }); } return $this; } @@ -488,16 +442,13 @@ public function __toString() $doc->formatOutput = true; $props = $this->propertyList(); - if(!empty($props)) - { + if (!empty($props)) { $this->appendByProp($doc, $tbody, $props, $className); - } - else - { + } else { $values = $this->value(); $this->appendByValues($doc, $tbody, $values); } - return $doc->saveHTML(); + return $doc->saveHTML(); } /** @@ -509,4 +460,4 @@ public function getTableInfo() { return $this->_tableInfo; } -} \ No newline at end of file +} diff --git a/src/SecretObject.php b/src/SecretObject.php index 6ba1080..326723d 100644 --- a/src/SecretObject.php +++ b/src/SecretObject.php @@ -225,6 +225,7 @@ private function secureKey() * @param array $params Parameters for the method. * @return mixed|null The result of the method call or null if not applicable. */ + public function __call($method, $params) // NOSONAR { if (strncasecmp($method, "isset", 5) === 0) { diff --git a/src/SetterGetter.php b/src/SetterGetter.php index d6d162d..a1341e8 100644 --- a/src/SetterGetter.php +++ b/src/SetterGetter.php @@ -297,6 +297,7 @@ function($property) use($class) * @param array $params Parameters passed to the method. * @return mixed|null The result of the method call or null if the method does not return a value. */ + public function __call($method, $params) //NOSONAR { if (strncasecmp($method, "isset", 5) === 0)