@@ -37,7 +37,9 @@ |
||
| 37 | 37 | |
| 38 | 38 | private function nextNumericIndex() { |
| 39 | 39 | $numericKeys = array_filter(array_keys($this->rawValues()), 'is_numeric'); |
| 40 | - if (count($numericKeys) === 0) return 0; |
|
| 40 | + if (count($numericKeys) === 0) { |
|
| 41 | + return 0; |
|
| 42 | + } |
|
| 41 | 43 | return max($numericKeys) + 1; |
| 42 | 44 | } |
| 43 | 45 | } |
| 44 | 46 | \ No newline at end of file |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | $this->config = $config; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public function find($path, $default=null, $delimiter='.') { |
|
| 17 | + public function find($path, $default = null, $delimiter = '.') { |
|
| 18 | 18 | if ($this->pathStartsWithConfig($path, $delimiter)) |
| 19 | 19 | return $this->evalSubPath($path, $delimiter, $default); |
| 20 | 20 | |
| 21 | 21 | return $this->get($this->getFirstToken($path, $delimiter), $default); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - private function get($name, $default=null) { |
|
| 24 | + private function get($name, $default = null) { |
|
| 25 | 25 | return $this->config->get($name, $default); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | private function getFirstToken($path, $delimiter) { |
| 37 | - return $this->gettok($path, $delimiter,0); |
|
| 37 | + return $this->gettok($path, $delimiter, 0); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | private function evalSubPath($path, $delimiter, $default) { |
@@ -15,8 +15,9 @@ |
||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function find($path, $default=null, $delimiter='.') { |
| 18 | - if ($this->pathStartsWithConfig($path, $delimiter)) |
|
| 19 | - return $this->evalSubPath($path, $delimiter, $default); |
|
| 18 | + if ($this->pathStartsWithConfig($path, $delimiter)) { |
|
| 19 | + return $this->evalSubPath($path, $delimiter, $default); |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | return $this->get($this->getFirstToken($path, $delimiter), $default); |
| 22 | 23 | } |
@@ -58,8 +58,9 @@ |
||
| 58 | 58 | public function __isset($offset) { return $this->offsetExists($offset); } |
| 59 | 59 | |
| 60 | 60 | protected function requireOffset($offset) { |
| 61 | - if (!$this->offsetExists($offset)) |
|
| 62 | - throw new \OutOfBoundsException("offset '{$offset}' does not exist"); |
|
| 61 | + if (!$this->offsetExists($offset)) { |
|
| 62 | + throw new \OutOfBoundsException("offset '{$offset}' does not exist"); |
|
| 63 | + } |
|
| 63 | 64 | |
| 64 | 65 | return $this->values[$offset]; |
| 65 | 66 | } |
@@ -47,23 +47,23 @@ |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | # ArrayAccess |
| 50 | - public function offsetGet($offset) { return $this->requireOffset($offset); } |
|
| 51 | - public function offsetExists($offset) { return array_key_exists($offset, $this->values); } |
|
| 52 | - public function offsetSet($offset, $val) { $this->values[$offset] = $val; } |
|
| 53 | - public function offsetUnset($offset) { unset($this->values[$offset]); } |
|
| 50 | + public function offsetGet($offset) { return $this->requireOffset($offset); } |
|
| 51 | + public function offsetExists($offset) { return array_key_exists($offset, $this->values); } |
|
| 52 | + public function offsetSet($offset, $val) { $this->values[$offset] = $val; } |
|
| 53 | + public function offsetUnset($offset) { unset($this->values[$offset]); } |
|
| 54 | 54 | |
| 55 | 55 | # Iterator |
| 56 | - public function rewind() { return reset($this->values); } |
|
| 57 | - public function key() { return key($this->values); } |
|
| 58 | - public function current() { return current($this->values); } |
|
| 59 | - public function next() { return next($this->values); } |
|
| 60 | - public function valid() { return key($this->values) !== null; } |
|
| 56 | + public function rewind() { return reset($this->values); } |
|
| 57 | + public function key() { return key($this->values); } |
|
| 58 | + public function current() { return current($this->values); } |
|
| 59 | + public function next() { return next($this->values); } |
|
| 60 | + public function valid() { return key($this->values) !== null; } |
|
| 61 | 61 | |
| 62 | 62 | # Magic Property Access |
| 63 | - public function __set($offset, $value) { $this->offsetSet($offset, $value); } |
|
| 64 | - public function __unset($offset) { $this->offsetUnset($offset); } |
|
| 65 | - public function __get($offset) { return $this->offsetGet($offset); } |
|
| 66 | - public function __isset($offset) { return $this->offsetExists($offset); } |
|
| 63 | + public function __set($offset, $value) { $this->offsetSet($offset, $value); } |
|
| 64 | + public function __unset($offset) { $this->offsetUnset($offset); } |
|
| 65 | + public function __get($offset) { return $this->offsetGet($offset); } |
|
| 66 | + public function __isset($offset) { return $this->offsetExists($offset); } |
|
| 67 | 67 | |
| 68 | 68 | protected function requireOffset($offset) { |
| 69 | 69 | if (!$this->offsetExists($offset)) |
@@ -17,22 +17,25 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function isValid() { |
| 19 | 19 | foreach ($this->_fields as $field) { |
| 20 | - if (!$this->isFieldValid($field)) |
|
| 21 | - return false; |
|
| 20 | + if (!$this->isFieldValid($field)) { |
|
| 21 | + return false; |
|
| 22 | + } |
|
| 22 | 23 | } |
| 23 | 24 | return true; |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | 27 | public function validate() { |
| 27 | - if (!$this->isValid()) |
|
| 28 | - throw new InvalidConfigStateException($this); |
|
| 28 | + if (!$this->isValid()) { |
|
| 29 | + throw new InvalidConfigStateException($this); |
|
| 30 | + } |
|
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | public function validationMessages() { |
| 32 | 34 | $failures = []; |
| 33 | 35 | foreach ($this->_fields as $field) { |
| 34 | - if (!$this->isFieldValid($field)) |
|
| 35 | - $failures[$field->getName()] = $this->fieldValidationMessages($field); |
|
| 36 | + if (!$this->isFieldValid($field)) { |
|
| 37 | + $failures[$field->getName()] = $this->fieldValidationMessages($field); |
|
| 38 | + } |
|
| 36 | 39 | } |
| 37 | 40 | return $failures; |
| 38 | 41 | } |
@@ -24,12 +24,12 @@ |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public static function required($name) : Particle { |
| 27 | - $v = new Particle\Validator();; |
|
| 27 | + $v = new Particle\Validator(); ; |
|
| 28 | 28 | return new self($name, $v, $v->required($name)); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public static function optional($name) : Particle { |
| 32 | - $v = new Particle\Validator();; |
|
| 32 | + $v = new Particle\Validator(); ; |
|
| 33 | 33 | return new self($name, $v, $v->optional($name)); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -42,8 +42,9 @@ |
||
| 42 | 42 | $particleResult = $this->validator->validate([ |
| 43 | 43 | $this->name => $value |
| 44 | 44 | ]); |
| 45 | - if ($particleResult->isValid()) |
|
| 46 | - return new Validation\ValidResult(); |
|
| 45 | + if ($particleResult->isValid()) { |
|
| 46 | + return new Validation\ValidResult(); |
|
| 47 | + } |
|
| 47 | 48 | |
| 48 | 49 | return $this->invalidResult($particleResult); |
| 49 | 50 | } |
@@ -23,8 +23,9 @@ discard block |
||
| 23 | 23 | $this->validateNotNull($key); |
| 24 | 24 | $this->validateNotObjectOrHasToString($key); |
| 25 | 25 | |
| 26 | - if (is_numeric($key) || is_string($key)) |
|
| 27 | - return $key; |
|
| 26 | + if (is_numeric($key) || is_string($key)) { |
|
| 27 | + return $key; |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | return (string) $key; |
| 30 | 31 | } |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | * @throws InvalidTypeException |
| 35 | 36 | */ |
| 36 | 37 | private function validateNotNull($key) { |
| 37 | - if (is_null($key)) |
|
| 38 | - throw new InvalidTypeException('Can not use null for a key'); |
|
| 38 | + if (is_null($key)) { |
|
| 39 | + throw new InvalidTypeException('Can not use null for a key'); |
|
| 40 | + } |
|
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | /** |
@@ -43,7 +45,8 @@ discard block |
||
| 43 | 45 | * @throws InvalidTypeException |
| 44 | 46 | */ |
| 45 | 47 | private function validateNotObjectOrHasToString($key) { |
| 46 | - if (is_object($key) && !method_exists($key, '__toString')) |
|
| 47 | - throw new InvalidTypeException('Object keys must implement __toString'); |
|
| 48 | + if (is_object($key) && !method_exists($key, '__toString')) { |
|
| 49 | + throw new InvalidTypeException('Object keys must implement __toString'); |
|
| 50 | + } |
|
| 48 | 51 | } |
| 49 | 52 | } |
| 50 | 53 | \ No newline at end of file |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @see ../docs/config/README.md |
| 11 | 11 | */ |
| 12 | 12 | abstract class Config extends Registry { |
| 13 | - private $locked = false; |
|
| 13 | + private $locked = false; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Config constructor. |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | public function toArray() { |
| 53 | 53 | return array_map( |
| 54 | - function ($value) { |
|
| 54 | + function($value) { |
|
| 55 | 55 | // $value may be another Config object, if so then we toArray() it also. |
| 56 | 56 | return $this->hasToArray($value) ? $value->toArray() : $value; |
| 57 | 57 | }, |
@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function import(array $data) { |
| 29 | - foreach ($data as $key=>$value) $this->offsetSet($key, $value); |
|
| 29 | + foreach ($data as $key=>$value) { |
|
| 30 | + $this->offsetSet($key, $value); |
|
| 31 | + } |
|
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | // override this to have a base config |
@@ -82,7 +84,9 @@ discard block |
||
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | protected function settableValue($value) { |
| 85 | - if (is_array($value)) return $this->subConfig($value); |
|
| 87 | + if (is_array($value)) { |
|
| 88 | + return $this->subConfig($value); |
|
| 89 | + } |
|
| 86 | 90 | return $value; |
| 87 | 91 | } |
| 88 | 92 | |
@@ -116,7 +120,8 @@ discard block |
||
| 116 | 120 | * @throws CanNotMutateException |
| 117 | 121 | */ |
| 118 | 122 | private function blockIfLocked() { |
| 119 | - if ($this->isLocked()) |
|
| 120 | - throw new CanNotMutateException(); |
|
| 123 | + if ($this->isLocked()) { |
|
| 124 | + throw new CanNotMutateException(); |
|
| 125 | + } |
|
| 121 | 126 | } |
| 122 | 127 | } |
| 123 | 128 | \ No newline at end of file |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | * @throws Exception |
| 15 | 15 | */ |
| 16 | 16 | public function __construct($fqcn, $description = null) { |
| 17 | - if (!$this->isValidClassName($fqcn)) |
|
| 18 | - throw new Exception("Invalid Regex pattern: {$fqcn}"); |
|
| 17 | + if (!$this->isValidClassName($fqcn)) { |
|
| 18 | + throw new Exception("Invalid Regex pattern: {$fqcn}"); |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | 21 | $this->fqcn = $fqcn; |
| 21 | 22 | $this->description = $description ?? "Must be an instance of {$fqcn}"; |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | * @throws Exception |
| 15 | 15 | */ |
| 16 | 16 | public function __construct($pattern, $description = null) { |
| 17 | - if (!$this->isValidRegexPattern($pattern)) |
|
| 18 | - throw new Exception("Invalid Regex pattern: {$pattern}"); |
|
| 17 | + if (!$this->isValidRegexPattern($pattern)) { |
|
| 18 | + throw new Exception("Invalid Regex pattern: {$pattern}"); |
|
| 19 | + } |
|
| 19 | 20 | $this->pattern = $pattern; |
| 20 | 21 | $this->message = $description; |
| 21 | 22 | } |