Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]
  • Loading branch information
Dgame authored and StyleCIBot committed Jul 31, 2019
1 parent 34e0ed4 commit 8eadcdf
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 202 deletions.
192 changes: 96 additions & 96 deletions src/ObjectFacade.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

namespace Dgame\Object;

use Dgame\Variants\Variants;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
use function Dgame\Ensurance\enforce;

namespace Dgame\Object;

use function Dgame\Ensurance\enforce;
use Dgame\Variants\Variants;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;

/**
* Class ObjectFacade
* @package Dgame\Object
*/
class ObjectFacade
{
class ObjectFacade
{
/**
* @var object
*/
Expand All @@ -28,31 +28,31 @@ class ObjectFacade
*
* @param object $object
*/
public function __construct($object)
{
public function __construct($object)
{
enforce(is_object($object))->orThrow('That is not a valid object');

$this->object = $object;
$this->object = $object;
}

/**
* @return object
*/
final public function getObject()
{
return $this->object;
final public function getObject()
{
return $this->object;
}

/**
* @return ReflectionClass
*/
final public function getReflection(): ReflectionClass
{
if ($this->reflection === null) {
$this->reflection = new ReflectionClass($this->object);
final public function getReflection(): ReflectionClass
{
if ($this->reflection === null) {
$this->reflection = new ReflectionClass($this->object);
}

return $this->reflection;
return $this->reflection;
}

/**
Expand All @@ -61,15 +61,15 @@ final public function getReflection(): ReflectionClass
*
* @return bool
*/
final public function setValue(string $name, $value): bool
{
foreach (Variants::ofArguments($name)->withCamelSnakeCase() as $attribute) {
if ($this->setValueByProperty($attribute, $value) || $this->setValueByMethod($attribute, $value)) {
return true;
}
final public function setValue(string $name, $value): bool
{
foreach (Variants::ofArguments($name)->withCamelSnakeCase() as $attribute) {
if ($this->setValueByProperty($attribute, $value) || $this->setValueByMethod($attribute, $value)) {
return true;
}
}

return $this->tryMagicSet($name, $value);
return $this->tryMagicSet($name, $value);
}

/**
Expand All @@ -78,37 +78,37 @@ final public function setValue(string $name, $value): bool
*
* @return bool
*/
private function tryMagicSet(string $name, $value): bool
{
if ($this->hasMethod('__set')) {
private function tryMagicSet(string $name, $value): bool
{
if ($this->hasMethod('__set')) {
$this->invokeMethod('__set', $name, $value);

return true;
return true;
}

return false;
return false;
}

/**
* @param string $name
*
* @return mixed|null
*/
final public function getValue(string $name)
{
foreach (Variants::ofArguments($name)->withCamelSnakeCase() as $attribute) {
final public function getValue(string $name)
{
foreach (Variants::ofArguments($name)->withCamelSnakeCase() as $attribute) {
$property = $this->getPropertyByName($attribute);
if ($property !== null && $property->isPublic()) {
return $property->getValue($this->object);
if ($property !== null && $property->isPublic()) {
return $property->getValue($this->object);
}

$method = $this->getGetterMethod($name);
if ($method !== null && Validator::new($this)->isValidGetterMethod($method)) {
return $method->invoke($this->object);
}
if ($method !== null && Validator::new($this)->isValidGetterMethod($method)) {
return $method->invoke($this->object);
}
}

return $this->invokeMethod('__get', $name);
return $this->invokeMethod('__get', $name);
}

/**
Expand All @@ -117,16 +117,16 @@ final public function getValue(string $name)
*
* @return bool
*/
final public function setValueByProperty(string $name, $value): bool
{
final public function setValueByProperty(string $name, $value): bool
{
$property = $this->getPropertyByName($name);
if ($property !== null && $property->isPublic()) {
if ($property !== null && $property->isPublic()) {
$property->setValue($this->object, $value);

return true;
return true;
}

return false;
return false;
}

/**
Expand All @@ -135,66 +135,66 @@ final public function setValueByProperty(string $name, $value): bool
*
* @return bool
*/
final public function setValueByMethod(string $name, $value): bool
{
final public function setValueByMethod(string $name, $value): bool
{
$method = $this->getSetterMethod($name);
if ($method !== null && Validator::new($this)->isValidSetterMethod($method, $value)) {
if ($method !== null && Validator::new($this)->isValidSetterMethod($method, $value)) {
$method->invoke($this->object, $value);

return true;
return true;
}

return false;
return false;
}

/**
* @param string $name
*
* @return mixed|null
*/
final public function getValueByMethod(string $name)
{
final public function getValueByMethod(string $name)
{
$method = $this->getGetterMethod($name);
if ($method !== null && Validator::new($this)->isValidGetterMethod($method)) {
return $method->invoke($this->object);
if ($method !== null && Validator::new($this)->isValidGetterMethod($method)) {
return $method->invoke($this->object);
}

return null;
return null;
}

/**
* @param string $name
*
* @return mixed|null
*/
final public function getValueByProperty(string $name)
{
final public function getValueByProperty(string $name)
{
$property = $this->getPropertyByName($name);
if ($property !== null && $property->isPublic()) {
return $property->getValue($this->object);
if ($property !== null && $property->isPublic()) {
return $property->getValue($this->object);
}

return null;
return null;
}

/**
* @param string $name
*
* @return null|ReflectionMethod
*/
final public function getSetterMethod(string $name): ?ReflectionMethod
{
return $this->getMethodByName($name) ?? $this->getMethod($name, ['set', 'append']);
final public function getSetterMethod(string $name): ?ReflectionMethod
{
return $this->getMethodByName($name) ?? $this->getMethod($name, ['set', 'append']);
}

/**
* @param string $name
*
* @return null|ReflectionMethod
*/
final public function getGetterMethod(string $name): ?ReflectionMethod
{
return $this->getMethodByName($name) ?? $this->getMethod($name, ['get']);
final public function getGetterMethod(string $name): ?ReflectionMethod
{
return $this->getMethodByName($name) ?? $this->getMethod($name, ['get']);
}

/**
Expand All @@ -203,16 +203,16 @@ final public function getGetterMethod(string $name): ?ReflectionMethod
*
* @return null|ReflectionMethod
*/
final public function getMethod(string $name, array $prefixe): ?ReflectionMethod
{
foreach ($prefixe as $prefix) {
final public function getMethod(string $name, array $prefixe): ?ReflectionMethod
{
foreach ($prefixe as $prefix) {
$method = $this->getMethodByName($prefix . ucfirst($name));
if ($method !== null) {
return $method;
}
if ($method !== null) {
return $method;
}
}

return null;
return null;
}

/**
Expand All @@ -221,63 +221,63 @@ final public function getMethod(string $name, array $prefixe): ?ReflectionMethod
*
* @return mixed|null
*/
final public function invokeMethod(string $name, ...$args)
{
final public function invokeMethod(string $name, ...$args)
{
$method = $this->getMethodByName($name);
if ($method !== null && Validator::new($this)->areValidMethodArguments($method, ...$args)) {
return $method->invokeArgs($this->object, $args);
if ($method !== null && Validator::new($this)->areValidMethodArguments($method, ...$args)) {
return $method->invokeArgs($this->object, $args);
}

return null;
return null;
}

/**
* @param string $name
*
* @return null|ReflectionMethod
*/
final public function getMethodByName(string $name): ?ReflectionMethod
{
return $this->hasMethod($name) ? $this->getReflection()->getMethod($name) : null;
final public function getMethodByName(string $name): ?ReflectionMethod
{
return $this->hasMethod($name) ? $this->getReflection()->getMethod($name) : null;
}

/**
* @param string $name
*
* @return null|ReflectionProperty
*/
final public function getPropertyByName(string $name): ?ReflectionProperty
{
return $this->hasProperty($name) ? $this->getReflection()->getProperty($name) : null;
final public function getPropertyByName(string $name): ?ReflectionProperty
{
return $this->hasProperty($name) ? $this->getReflection()->getProperty($name) : null;
}

/**
* @param string $name
*
* @return bool
*/
final public function hasProperty(string $name): bool
{
return $this->getReflection()->hasProperty($name);
final public function hasProperty(string $name): bool
{
return $this->getReflection()->hasProperty($name);
}

/**
* @param string $name
*
* @return bool
*/
final public function isSet(string $name): bool
{
return $this->hasProperty($name) || $this->invokeMethod('__isset', $name) === true;
final public function isSet(string $name): bool
{
return $this->hasProperty($name) || $this->invokeMethod('__isset', $name) === true;
}

/**
* @param string $name
*
* @return bool
*/
final public function hasMethod(string $name): bool
{
return $this->getReflection()->hasMethod($name);
}
final public function hasMethod(string $name): bool
{
return $this->getReflection()->hasMethod($name);
}
}

0 comments on commit 8eadcdf

Please sign in to comment.