Created
August 24, 2016 18:59
-
-
Save phansys/42deea38ddcbc1d14b82654d92e8d7e0 to your computer and use it in GitHub Desktop.
Don't use `else/elseif` after `throw` or `return`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function writeProperty($zval, $property, $value) | |
{ | |
if (!is_object($zval[self::VALUE])) { | |
throw new NoSuchPropertyException(sprintf('Cannot write property "%s" to an array. Maybe you should write the property path as "[%s]" instead?', $property, $property)); | |
} | |
$object = $zval[self::VALUE]; | |
$access = $this->getWriteAccessInfo(get_class($object), $property, $value); | |
if (self::ACCESS_TYPE_METHOD === $access[self::ACCESS_TYPE]) { | |
$object->{$access[self::ACCESS_NAME]}($value); | |
} elseif (self::ACCESS_TYPE_PROPERTY === $access[self::ACCESS_TYPE]) { | |
$object->{$access[self::ACCESS_NAME]} = $value; | |
} elseif (self::ACCESS_TYPE_ADDER_AND_REMOVER === $access[self::ACCESS_TYPE]) { | |
$this->writeCollection($zval, $property, $value, $access[self::ACCESS_ADDER], $access[self::ACCESS_REMOVER]); | |
} elseif (!$access[self::ACCESS_HAS_PROPERTY] && property_exists($object, $property)) { | |
// Needed to support \stdClass instances. We need to explicitly | |
// exclude $access[self::ACCESS_HAS_PROPERTY], otherwise if | |
// a *protected* property was found on the class, property_exists() | |
// returns true, consequently the following line will result in a | |
// fatal error. | |
$object->$property = $value; | |
} elseif (self::ACCESS_TYPE_NOT_FOUND === $access[self::ACCESS_TYPE]) { | |
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s".', $property)); | |
} | |
if (self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE]) { | |
$object->{$access[self::ACCESS_NAME]}($value); | |
} else { | |
throw new NoSuchPropertyException($access[self::ACCESS_NAME]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment