From 1c4182d9d88bb4471f86b08329f1b68a5290872b Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 17 Apr 2020 20:58:27 +0200 Subject: apply psr 12 part 2 --- app/class/Item.php | 111 ++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 57 deletions(-) (limited to 'app/class/Item.php') diff --git a/app/class/Item.php b/app/class/Item.php index 10d35d7..8a8f2d6 100644 --- a/app/class/Item.php +++ b/app/class/Item.php @@ -12,21 +12,21 @@ abstract class Item public function hydrate($datas = []) { - $error = 0; + $error = 0; foreach ($datas as $key => $value) { $method = 'set' . $key; if (method_exists($this, $method)) { - if($this->$method($value) === false) { - $error ++; - } + if ($this->$method($value) === false) { + $error++; + } } - } - if ($error > 0) { - return false; - } else { - return true; - } + } + if ($error > 0) { + return false; + } else { + return true; + } } @@ -40,54 +40,51 @@ abstract class Item } - /** - * Return any asked vars and their values of an object as associative array - * - * @param array $vars list of vars - * @return array Associative array `$var => $value` - */ - public function drylist(array $vars) : array - { - $array = []; - foreach ($vars as $var) { - if (property_exists($this, $var)) - $array[$var] = $this->$var; - } - return $array; + /** + * Return any asked vars and their values of an object as associative array + * + * @param array $vars list of vars + * @return array Associative array `$var => $value` + */ + public function drylist(array $vars): array + { + $array = []; + foreach ($vars as $var) { + if (property_exists($this, $var)) { + $array[$var] = $this->$var; + } + } + return $array; } - /** - * Tool for accessing different view of the same DateTimeImmutable var - * - * @param string $property DateTimeImmutable var to access - * @param string $option - * - * @return mixed string or false if propriety does not exist - */ - protected function datetransform(string $property, string $option = 'date') - { - if(property_exists($this, $property)) { - if ($option == 'string') { - return $this->$property->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->$property; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->$property->diff($now)); - } elseif ($option == 'pdate') { - return $this->$property->format('Y-m-d'); - } elseif ($option == 'ptime') { - return $this->$property->format('H:i'); - } elseif ($option = 'dmy') { - return $this->$property->format('d/m/Y'); - } - } else { - return false; - } - } - + /** + * Tool for accessing different view of the same DateTimeImmutable var + * + * @param string $property DateTimeImmutable var to access + * @param string $option + * + * @return mixed string or false if propriety does not exist + */ + protected function datetransform(string $property, string $option = 'date') + { + if (property_exists($this, $property)) { + if ($option == 'string') { + return $this->$property->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->$property; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->$property->diff($now)); + } elseif ($option == 'pdate') { + return $this->$property->format('Y-m-d'); + } elseif ($option == 'ptime') { + return $this->$property->format('H:i'); + } elseif ($option = 'dmy') { + return $this->$property->format('d/m/Y'); + } + } else { + return false; + } + } } - - -?> \ No newline at end of file -- cgit v1.2.3