From d3d008788264549c460f3ed3d640d4a12df3f41e Mon Sep 17 00:00:00 2001 From: Steeve Andrian Salim Date: Tue, 29 May 2018 14:54:12 +0700 Subject: [PATCH] Optimize Codes --- .../Datastructures/SplServiceRegistry.php | 15 ++- src/Containers/SplClosureContainer.php | 31 ++--- src/Containers/SplServiceContainer.php | 71 +++++----- src/Datastructures/SplArrayObject.php | 31 ++--- src/Datastructures/SplArrayQueue.php | 19 +-- src/Datastructures/SplArrayStack.php | 19 +-- src/Datastructures/SplArrayStorage.php | 103 +++++++------- .../Traits/ArrayConversionTrait.php | 55 ++++---- .../Traits/ArrayFunctionsTrait.php | 57 ++++---- .../Abstracts/AbstractException.php | 41 +++--- src/Exceptions/Error/ArithmeticError.php | 1 + src/Exceptions/Error/AssertionError.php | 1 + src/Exceptions/Error/DivisionByZeroError.php | 1 + src/Exceptions/Error/ParseError.php | 1 + src/Exceptions/Error/TypeError.php | 1 + src/Exceptions/ErrorException.php | 13 +- .../BadDependencyCallException.php | 1 + .../BadMethodCallException.php | 1 + .../BadPhpExtensionCallException.php | 1 + .../Logic/BadFunctionCallException.php | 1 + src/Exceptions/Logic/DomainException.php | 1 + .../Logic/InvalidArgumentException.php | 1 + src/Exceptions/Logic/LengthException.php | 1 + src/Exceptions/Logic/OutOfRangeException.php | 1 + src/Exceptions/LogicException.php | 1 + .../Runtime/ConnectionException.php | 1 + .../Runtime/FileNotFoundException.php | 1 + .../Runtime/OutOfBoundsException.php | 1 + src/Exceptions/Runtime/OverflowException.php | 1 + src/Exceptions/Runtime/RangeException.php | 1 + src/Exceptions/Runtime/UnderflowException.php | 1 + .../Runtime/UnexpectedValueException.php | 1 + src/Exceptions/RuntimeException.php | 1 + src/Info/SplClassInfo.php | 27 ++-- src/Info/SplDirectoryInfo.php | 127 +++++++++--------- src/Info/SplFileInfo.php | 19 +-- src/Info/SplNamespaceInfo.php | 37 ++--- src/Interfaces/SplArrayInterface.php | 3 +- src/Iterators/ArrayIterator.php | 63 ++++----- .../Collectors/ConfigCollectorTrait.php | 35 ++--- src/Traits/Collectors/ErrorCollectorTrait.php | 55 ++++---- .../FileExtensionCollectorTrait.php | 17 +-- .../Collectors/FilePathCollectorTrait.php | 33 ++--- src/Traits/OptionsSetterTrait.php | 13 +- src/autoload.php | 20 +-- 45 files changed, 485 insertions(+), 441 deletions(-) diff --git a/src/Containers/Datastructures/SplServiceRegistry.php b/src/Containers/Datastructures/SplServiceRegistry.php index 8faf0ab..d9c8ffd 100644 --- a/src/Containers/Datastructures/SplServiceRegistry.php +++ b/src/Containers/Datastructures/SplServiceRegistry.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Containers\Datastructures; @@ -30,25 +31,25 @@ class SplServiceRegistry extends SplClassInfo */ private $instance; - public function __construct( $service ) + public function __construct($service) { - if ( is_object( $service ) ) { + if (is_object($service)) { $this->instance = $service; - $service = get_class( $service ); + $service = get_class($service); } - parent::__construct( $service ); + parent::__construct($service); } public function getClassName() { - return get_class_name( $this->name ); + return get_class_name($this->name); } public function &getInstance() { - if ( empty( $this->instance ) ) { - $this->instance = $this->newInstance( func_get_args() ); + if (empty($this->instance)) { + $this->instance = $this->newInstance(func_get_args()); } return $this->instance; diff --git a/src/Containers/SplClosureContainer.php b/src/Containers/SplClosureContainer.php index e14afce..a2ba300 100644 --- a/src/Containers/SplClosureContainer.php +++ b/src/Containers/SplClosureContainer.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Containers; @@ -40,7 +41,7 @@ class SplClosureContainer implements \Countable, ContainerInterface * @param string $offset * @param \Closure $closure */ - public function attach( $offset, \Closure $closure ) + public function attach($offset, \Closure $closure) { $this->closures[ $offset ] = $closure; } @@ -57,9 +58,9 @@ public function attach( $offset, \Closure $closure ) * * @return bool */ - public function __isset( $offset ) + public function __isset($offset) { - return $this->has( $offset ); + return $this->has($offset); } // ------------------------------------------------------------------------ @@ -73,9 +74,9 @@ public function __isset( $offset ) * * @return bool */ - public function has( $offset ) + public function has($offset) { - return (bool)isset( $this->closures[ $offset ] ); + return (bool)isset($this->closures[ $offset ]); } // ------------------------------------------------------------------------ @@ -88,9 +89,9 @@ public function has( $offset ) * * @param string $offset */ - public function __unset( $offset ) + public function __unset($offset) { - $this->detach( $offset ); + $this->detach($offset); } // ------------------------------------------------------------------------ @@ -102,10 +103,10 @@ public function __unset( $offset ) * * @param string $offset */ - public function detach( $offset ) + public function detach($offset) { - if ( isset( $this->closures[ $offset ] ) ) { - unset( $this->closures[ $offset ] ); + if (isset($this->closures[ $offset ])) { + unset($this->closures[ $offset ]); } } @@ -122,9 +123,9 @@ public function detach( $offset ) * * @return mixed Returns FALSE when calling the closure is failed. */ - public function __call( $offset, array $arguments = [] ) + public function __call($offset, array $arguments = []) { - return $this->get( $offset, $arguments ); + return $this->get($offset, $arguments); } // ------------------------------------------------------------------------ @@ -139,9 +140,9 @@ public function __call( $offset, array $arguments = [] ) * * @return mixed Returns FALSE when calling the closure is failed. */ - public function get( $offset, array $arguments = [] ) + public function get($offset, array $arguments = []) { - return isset( $this->closures[ $offset ] ) ? call_user_func_array( + return isset($this->closures[ $offset ]) ? call_user_func_array( $this->closures[ $offset ], $arguments ) : false; @@ -163,6 +164,6 @@ public function get( $offset, array $arguments = [] ) */ public function count() { - return count( $this->closures ); + return count($this->closures); } } \ No newline at end of file diff --git a/src/Containers/SplServiceContainer.php b/src/Containers/SplServiceContainer.php index f4cd6b3..6676472 100644 --- a/src/Containers/SplServiceContainer.php +++ b/src/Containers/SplServiceContainer.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Containers; @@ -41,7 +42,7 @@ class SplServiceContainer implements \Countable, ContainerInterface * @param string $offset * @param SplServiceRegistry $service */ - public function attach( $offset, SplServiceRegistry $service ) + public function attach($offset, SplServiceRegistry $service) { $this->services[ $offset ] = $service; } @@ -56,9 +57,9 @@ public function attach( $offset, SplServiceRegistry $service ) * * @param string $offset */ - public function __unset( $offset ) + public function __unset($offset) { - $this->detach( $offset ); + $this->detach($offset); } // ------------------------------------------------------------------------ @@ -70,10 +71,10 @@ public function __unset( $offset ) * * @param string $offset */ - public function detach( $offset ) + public function detach($offset) { - if ( isset( $this->services[ $offset ] ) ) { - unset( $this->services[ $offset ] ); + if (isset($this->services[ $offset ])) { + unset($this->services[ $offset ]); } } @@ -89,9 +90,9 @@ public function detach( $offset ) * * @return bool */ - public function __isset( $offset ) + public function __isset($offset) { - return $this->has( $offset ); + return $this->has($offset); } // ------------------------------------------------------------------------ @@ -105,9 +106,9 @@ public function __isset( $offset ) * * @return bool */ - public function has( $offset ) + public function has($offset) { - return (bool)isset( $this->services[ $offset ] ); + return (bool)isset($this->services[ $offset ]); } // ------------------------------------------------------------------------ @@ -122,9 +123,9 @@ public function has( $offset ) * * @return bool */ - public function &__get( $offset ) + public function &__get($offset) { - $get[ $offset ] = $this->get( $offset ); + $get[ $offset ] = $this->get($offset); return $get[ $offset ]; } @@ -141,50 +142,50 @@ public function &__get( $offset ) * * @return mixed Returns FALSE when calling the service is failed. */ - public function &get( $offset, array $arguments = [] ) + public function &get($offset, array $arguments = []) { $get[ $offset ] = false; - if ( $this->has( $offset ) ) { + if ($this->has($offset)) { $service = $this->services[ $offset ]; - if ( $service instanceof SplServiceRegistry ) { - if ( empty( $arguments ) ) { + if ($service instanceof SplServiceRegistry) { + if (empty($arguments)) { return $service->getInstance(); } else { - $newServiceInstance = $service->newInstanceArgs( $arguments ); + $newServiceInstance = $service->newInstanceArgs($arguments); - if ( $DocComment = $service->getDocComment() ) { - preg_match_all( '/@inject\s(.*)/', $DocComment, $matches ); + if ($DocComment = $service->getDocComment()) { + preg_match_all('/@inject\s(.*)/', $DocComment, $matches); - if ( count( $matches[ 1 ] ) ) { - foreach ( $matches[ 1 ] as $className ) { - $className = trim( $className, '\\' ); - $className = trim( $className ); + if (count($matches[ 1 ])) { + foreach ($matches[ 1 ] as $className) { + $className = trim($className, '\\'); + $className = trim($className); - $map = strtolower( get_class_name( $className ) ); + $map = strtolower(get_class_name($className)); - if ( isset( $this->map[ $className ] ) ) { + if (isset($this->map[ $className ])) { $map = $this->map[ $className ]; } $variable = $map; - $object =& $this->get( $map ); + $object =& $this->get($map); - preg_match_all( '/[$](.*)\s(.*)/', trim( $className ), $classMatches ); + preg_match_all('/[$](.*)\s(.*)/', trim($className), $classMatches); - if ( count( $classMatches[ 1 ] ) ) { + if (count($classMatches[ 1 ])) { $variable = $classMatches[ 1 ][ 0 ]; } - $setterMethod = ucwords( str_replace( [ '-', '_' ], ' ', $variable ) ); - $setterMethod = str_replace( ' ', '', $setterMethod ); + $setterMethod = ucwords(str_replace(['-', '_'], ' ', $variable)); + $setterMethod = str_replace(' ', '', $setterMethod); $setterMethod = 'set' . $setterMethod; - if ( method_exists( $newServiceInstance, $setterMethod ) ) { - $newServiceInstance->{$setterMethod}( $object ); - } elseif ( method_exists( $newServiceInstance, '__set' ) ) { - $newServiceInstance->__set( $variable, $object ); + if (method_exists($newServiceInstance, $setterMethod)) { + $newServiceInstance->{$setterMethod}($object); + } elseif (method_exists($newServiceInstance, '__set')) { + $newServiceInstance->__set($variable, $object); } else { $newServiceInstance->{$variable} =& $object; } @@ -216,6 +217,6 @@ public function &get( $offset, array $arguments = [] ) */ public function count() { - return count( $this->services ); + return count($this->services); } } \ No newline at end of file diff --git a/src/Datastructures/SplArrayObject.php b/src/Datastructures/SplArrayObject.php index 86e1319..c636ba5 100644 --- a/src/Datastructures/SplArrayObject.php +++ b/src/Datastructures/SplArrayObject.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Datastructures; @@ -36,9 +37,9 @@ class SplArrayObject extends \ArrayObject * * @return SplArrayObject Returns an SplArrayObject object on success. */ - public function __construct( array $array = [], $flag = \ArrayObject::ARRAY_AS_PROPS ) + public function __construct(array $array = [], $flag = \ArrayObject::ARRAY_AS_PROPS) { - parent::__construct( $array, $flag ); + parent::__construct($array, $flag); } // ------------------------------------------------------------------------ @@ -52,7 +53,7 @@ public function __construct( array $array = [], $flag = \ArrayObject::ARRAY_AS_P */ public function isEmpty() { - return ( $this->count() == 0 ? true : false ); + return ($this->count() == 0 ? true : false); } // ----------------------------------------------------------------------- @@ -66,20 +67,20 @@ public function isEmpty() * * @return mixed The value at the specified index or false. */ - public function __get( $offset ) + public function __get($offset) { - return $this->offsetGet( $offset ); + return $this->offsetGet($offset); } // ------------------------------------------------------------------------ - public function offsetGet( $offset ) + public function offsetGet($offset) { - if ( $this->offsetExists( $offset ) === false ) { + if ($this->offsetExists($offset) === false) { return false; } - return parent::offsetGet( $offset ); + return parent::offsetGet($offset); } // ------------------------------------------------------------------------ @@ -93,14 +94,14 @@ public function offsetGet( $offset ) */ public function exchangeOffset() { - if ( $this->count() > 0 ) { + if ($this->count() > 0) { $camelcaseStorage = []; - foreach ( $this->getArrayCopy() as $offset => $value ) { - $camelcaseStorage[ camelcase( $offset ) ] = $value; + foreach ($this->getArrayCopy() as $offset => $value) { + $camelcaseStorage[ camelcase($offset) ] = $value; } - $this->exchangeArray( $camelcaseStorage ); + $this->exchangeArray($camelcaseStorage); } return $this->getArrayCopy(); @@ -117,12 +118,12 @@ public function exchangeOffset() * * @return array The array merged copy of the resulting array */ - public function merge( array $values ) + public function merge(array $values) { $storage = $this->getArrayCopy(); - $storage = array_merge( $storage, $values ); + $storage = array_merge($storage, $values); - $this->exchangeArray( $storage ); + $this->exchangeArray($storage); return $storage; } diff --git a/src/Datastructures/SplArrayQueue.php b/src/Datastructures/SplArrayQueue.php index 23c9bab..ee72edf 100644 --- a/src/Datastructures/SplArrayQueue.php +++ b/src/Datastructures/SplArrayQueue.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Datastructures; @@ -31,11 +32,11 @@ class SplArrayQueue extends \SplQueue implements SplArrayInterface * * @param array $queue */ - public function __construct( array $queue = [] ) + public function __construct(array $queue = []) { - if ( count( $queue ) ) { - foreach ( $queue as $item ) { - $this->push( $item ); + if (count($queue)) { + foreach ($queue as $item) { + $this->push($item); } } } @@ -51,7 +52,7 @@ public function __construct( array $queue = [] ) */ public function current() { - if ( null === ( $current = parent::current() ) ) { + if (null === ($current = parent::current())) { $this->rewind(); } @@ -69,7 +70,7 @@ public function current() */ public function isEmpty() { - return ( $this->count() == 0 ? true : false ); + return ($this->count() == 0 ? true : false); } // ----------------------------------------------------------------------- @@ -85,9 +86,9 @@ public function isEmpty() * * @return bool */ - public function has( $needle, $strict = false ) + public function has($needle, $strict = false) { - return in_array( $needle, $this->getArrayCopy(), $strict ); + return in_array($needle, $this->getArrayCopy(), $strict); } // ----------------------------------------------------------------------- @@ -103,7 +104,7 @@ public function getArrayCopy() { $arrayCopy = []; - foreach ( $this as $key => $value ) { + foreach ($this as $key => $value) { $arrayCopy[ $key ] = $value; } diff --git a/src/Datastructures/SplArrayStack.php b/src/Datastructures/SplArrayStack.php index 96d50d9..dddb337 100644 --- a/src/Datastructures/SplArrayStack.php +++ b/src/Datastructures/SplArrayStack.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Datastructures; @@ -31,11 +32,11 @@ class SplArrayStack extends \SplStack implements SplArrayInterface * * @param array $stack */ - public function __construct( array $stack = [] ) + public function __construct(array $stack = []) { - if ( count( $stack ) ) { - foreach ( $stack as $item ) { - $this->push( $item ); + if (count($stack)) { + foreach ($stack as $item) { + $this->push($item); } } } @@ -51,7 +52,7 @@ public function __construct( array $stack = [] ) */ public function current() { - if ( null === ( $current = parent::current() ) ) { + if (null === ($current = parent::current())) { $this->rewind(); } @@ -69,7 +70,7 @@ public function current() */ public function isEmpty() { - return ( $this->count() == 0 ? true : false ); + return ($this->count() == 0 ? true : false); } // ----------------------------------------------------------------------- @@ -85,9 +86,9 @@ public function isEmpty() * * @return bool */ - public function has( $needle, $strict = false ) + public function has($needle, $strict = false) { - return in_array( $needle, $this->getArrayCopy(), $strict ); + return in_array($needle, $this->getArrayCopy(), $strict); } // ----------------------------------------------------------------------- @@ -103,7 +104,7 @@ public function getArrayCopy() { $arrayCopy = []; - foreach ( $this as $key => $value ) { + foreach ($this as $key => $value) { $arrayCopy[ $key ] = $value; } diff --git a/src/Datastructures/SplArrayStorage.php b/src/Datastructures/SplArrayStorage.php index bdc4aff..9faa103 100644 --- a/src/Datastructures/SplArrayStorage.php +++ b/src/Datastructures/SplArrayStorage.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Datastructures; @@ -48,9 +49,9 @@ class SplArrayStorage implements *

* The return value will be casted to boolean if non-boolean was returned. */ - public function __isset( $offset ) + public function __isset($offset) { - return isset( $this->storage[ $offset ] ); + return isset($this->storage[ $offset ]); } // ------------------------------------------------------------------------ @@ -66,9 +67,9 @@ public function __isset( $offset ) * * @return void */ - public function __unset( $offset ) + public function __unset($offset) { - unset( $this->storage[ $offset ] ); + unset($this->storage[ $offset ]); } // ------------------------------------------------------------------------ @@ -84,9 +85,9 @@ public function __unset( $offset ) * * @return mixed Can return all value types. */ - public function &__get( $offset ) + public function &__get($offset) { - return $this->offsetGet( $offset ); + return $this->offsetGet($offset); } // ------------------------------------------------------------------------ @@ -101,9 +102,9 @@ public function &__get( $offset ) * The value to set. *

*/ - public function __set( $offset, $value ) + public function __set($offset, $value) { - $this->offsetSet( $offset, $value ); + $this->offsetSet($offset, $value); } // ------------------------------------------------------------------------ @@ -122,9 +123,9 @@ public function __set( $offset, $value ) * @return mixed Can return all value types. * @since 5.0.0 */ - public function offsetGet( $offset ) + public function offsetGet($offset) { - if ( $this->offsetExists( $offset ) ) { + if ($this->offsetExists($offset)) { return $this->storage[ $offset ]; } else { $this->storage[ $offset ] = []; @@ -152,9 +153,9 @@ public function offsetGet( $offset ) * The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ - public function offsetExists( $offset ) + public function offsetExists($offset) { - return (bool)isset( $this->storage[ $offset ] ); + return (bool)isset($this->storage[ $offset ]); } // ------------------------------------------------------------------------ @@ -176,7 +177,7 @@ public function offsetExists( $offset ) * @return void * @since 5.0.0 */ - public function offsetSet( $offset, $value ) + public function offsetSet($offset, $value) { $this->storage[ $offset ] = $value; } @@ -197,10 +198,10 @@ public function offsetSet( $offset, $value ) * @return void * @since 5.0.0 */ - public function offsetUnset( $offset ) + public function offsetUnset($offset) { - if ( isset( $this->storage[ $offset ] ) ) { - unset( $this->storage[ $offset ] ); + if (isset($this->storage[ $offset ])) { + unset($this->storage[ $offset ]); } } @@ -216,19 +217,19 @@ public function offsetUnset( $offset ) * * @return mixed|null */ - public function offsetGetFilter( $offset, $filter = null ) + public function offsetGetFilter($offset, $filter = null) { - if ( $this->offsetExists( $offset ) ) { - $storage = $this->offsetGet( $offset ); - - if ( is_array( $storage ) AND is_array( $filter ) ) { - return filter_var_array( $offset, $filter ); - } elseif ( is_array( $storage ) AND isset( $filter ) ) { - foreach ( $storage as $key => $value ) { - $storage[ $key ] = filter_var( $value, $filter ); + if ($this->offsetExists($offset)) { + $storage = $this->offsetGet($offset); + + if (is_array($storage) AND is_array($filter)) { + return filter_var_array($offset, $filter); + } elseif (is_array($storage) AND isset($filter)) { + foreach ($storage as $key => $value) { + $storage[ $key ] = filter_var($value, $filter); } - } elseif ( isset( $filter ) ) { - return filter_var( $storage, $filter ); + } elseif (isset($filter)) { + return filter_var($storage, $filter); } return $storage; @@ -248,9 +249,9 @@ public function offsetGetFilter( $offset, $filter = null ) * * @return array The array merged copy of the resulting array */ - public function append( array $values ) + public function append(array $values) { - $this->storage = array_merge( $this->storage, $values ); + $this->storage = array_merge($this->storage, $values); } // ------------------------------------------------------------------------ @@ -264,12 +265,12 @@ public function append( array $values ) * * @return array The array merged copy of the resulting array */ - public function merge( array $values ) + public function merge(array $values) { $storage = $this->getArrayCopy(); - $storage = array_merge( $storage, $values ); + $storage = array_merge($storage, $values); - $this->exchangeArray( $storage ); + $this->exchangeArray($storage); return $storage; } @@ -304,7 +305,7 @@ public function getArrayCopy() * @return array the old array. * @since 5.1.0 */ - public function exchangeArray( array $values ) + public function exchangeArray(array $values) { $oldStorage = $this->storage; $this->storage = $values; @@ -326,9 +327,9 @@ public function exchangeArray( array $values ) * @return void * @since 5.2.0 */ - public function asort( $sortFlags = SORT_REGULAR ) + public function asort($sortFlags = SORT_REGULAR) { - asort( $this->storage, $sortFlags ); + asort($this->storage, $sortFlags); } // ------------------------------------------------------------------------ @@ -345,9 +346,9 @@ public function asort( $sortFlags = SORT_REGULAR ) * @return void * @since 5.2.0 */ - public function ksort( $sortFlags = SORT_REGULAR ) + public function ksort($sortFlags = SORT_REGULAR) { - ksort( $this->storage, $sortFlags ); + ksort($this->storage, $sortFlags); } // ------------------------------------------------------------------------ @@ -371,9 +372,9 @@ public function ksort( $sortFlags = SORT_REGULAR ) * @return void * @since 5.2.0 */ - public function uasort( $comparisonFunction ) + public function uasort($comparisonFunction) { - uasort( $this->storage, $comparisonFunction ); + uasort($this->storage, $comparisonFunction); } // ------------------------------------------------------------------------ @@ -400,9 +401,9 @@ public function uasort( $comparisonFunction ) * @return void * @since 5.2.0 */ - public function uksort( $comparisonFunction ) + public function uksort($comparisonFunction) { - uksort( $this->storage, $comparisonFunction ); + uksort($this->storage, $comparisonFunction); } // ------------------------------------------------------------------------ @@ -418,7 +419,7 @@ public function uksort( $comparisonFunction ) */ public function natsort() { - natsort( $this->storage ); + natsort($this->storage); } // ------------------------------------------------------------------------ @@ -434,7 +435,7 @@ public function natsort() */ public function natcasesort() { - natcasesort( $this->storage ); + natcasesort($this->storage); } // ------------------------------------------------------------------------ @@ -448,7 +449,7 @@ public function natcasesort() */ public function isEmpty() { - return (bool)empty( $this->storage ); + return (bool)empty($this->storage); } // ------------------------------------------------------------------------ @@ -464,9 +465,9 @@ public function isEmpty() * * @return bool */ - public function has( $needle, $strict = false ) + public function has($needle, $strict = false) { - return in_array( $needle, $this->getArrayCopy(), $strict ); + return in_array($needle, $this->getArrayCopy(), $strict); } // ------------------------------------------------------------------------ @@ -482,7 +483,7 @@ public function has( $needle, $strict = false ) */ public function serialize() { - return serialize( $this->storage ); + return serialize($this->storage); } // ------------------------------------------------------------------------ @@ -501,9 +502,9 @@ public function serialize() * @return void * @since 5.1.0 */ - public function unserialize( $serialized ) + public function unserialize($serialized) { - $this->storage = unserialize( $serialized ); + $this->storage = unserialize($serialized); } // ------------------------------------------------------------------------ @@ -522,7 +523,7 @@ public function unserialize( $serialized ) */ public function count() { - return count( $this->storage ); + return count($this->storage); } // ------------------------------------------------------------------------ @@ -556,6 +557,6 @@ public function jsonSerialize() */ public function getIterator() { - return new ArrayIterator( $this->storage ); + return new ArrayIterator($this->storage); } } \ No newline at end of file diff --git a/src/Datastructures/Traits/ArrayConversionTrait.php b/src/Datastructures/Traits/ArrayConversionTrait.php index b994a00..2c7b348 100644 --- a/src/Datastructures/Traits/ArrayConversionTrait.php +++ b/src/Datastructures/Traits/ArrayConversionTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Datastructures\Traits; @@ -34,9 +35,9 @@ trait ArrayConversionTrait * * @return SplArrayObject */ - public function __toObject( $depth = 0 ) + public function __toObject($depth = 0) { - return $this->___toObjectIterator( $this->getArrayCopy(), ( $depth == 0 ? 'ALL' : $depth ) ); + return $this->___toObjectIterator($this->getArrayCopy(), ($depth == 0 ? 'ALL' : $depth)); } // -------------------------------------------------------------------- @@ -52,31 +53,31 @@ public function __toObject( $depth = 0 ) * * @return SplArrayObject */ - private function ___toObjectIterator( $array, $depth = 'ALL', $counter = 0 ) + private function ___toObjectIterator($array, $depth = 'ALL', $counter = 0) { $object = new SplArrayObject(); - if ( $this->count() > 0 ) { - foreach ( $array as $key => $value ) { - if ( strlen( $key ) ) { - if ( is_array( $value ) ) { - if ( $depth == 'ALL' ) { - $object->offsetSet( $key, $this->___toObjectIterator( $value, $depth ) ); - } elseif ( is_numeric( $depth ) ) { - if ( $counter != $depth ) { - $object->offsetSet( $key, $this->___toObjectIterator( $value, $depth, $counter ) ); + if ($this->count() > 0) { + foreach ($array as $key => $value) { + if (strlen($key)) { + if (is_array($value)) { + if ($depth == 'ALL') { + $object->offsetSet($key, $this->___toObjectIterator($value, $depth)); + } elseif (is_numeric($depth)) { + if ($counter != $depth) { + $object->offsetSet($key, $this->___toObjectIterator($value, $depth, $counter)); } else { - $object->offsetSet( $key, $value ); + $object->offsetSet($key, $value); } - } elseif ( is_string( $depth ) && $key == $depth ) { - $object->offsetSet( $key, $value ); - } elseif ( is_array( $depth ) && in_array( $key, $depth ) ) { - $object->offsetSet( $key, $value ); + } elseif (is_string($depth) && $key == $depth) { + $object->offsetSet($key, $value); + } elseif (is_array($depth) && in_array($key, $depth)) { + $object->offsetSet($key, $value); } else { - $object->offsetSet( $key, $this->___toObjectIterator( $value, $depth ) ); + $object->offsetSet($key, $this->___toObjectIterator($value, $depth)); } } else { - $object->offsetSet( $key, $value ); + $object->offsetSet($key, $value); } } } @@ -96,7 +97,7 @@ private function ___toObjectIterator( $array, $depth = 'ALL', $counter = 0 ) */ public function __toString() { - if ( method_exists( $this, 'render' ) ) { + if (method_exists($this, 'render')) { return $this->render(); } @@ -115,11 +116,11 @@ public function __toString() * * @return string */ - public function __toJson( $options = JSON_PRETTY_PRINT, $depth = 512 ) + public function __toJson($options = JSON_PRETTY_PRINT, $depth = 512) { $depth = $depth == 0 ? 512 : $depth; - return call_user_func_array( 'json_encode', [ $this->getArrayCopy(), $options, $depth ] ); + return call_user_func_array('json_encode', [$this->getArrayCopy(), $options, $depth]); } // -------------------------------------------------------------------- @@ -135,7 +136,7 @@ public function __toJson( $options = JSON_PRETTY_PRINT, $depth = 512 ) */ public function __toSerialize() { - return serialize( $this->__toArray() ); + return serialize($this->__toArray()); } // -------------------------------------------------------------------- @@ -163,9 +164,9 @@ public function __toArray() * * @return string */ - public function implode( $glue = '' ) + public function implode($glue = '') { - return implode( $glue, $this->getArrayCopy() ); + return implode($glue, $this->getArrayCopy()); } // -------------------------------------------------------------------- @@ -179,8 +180,8 @@ public function implode( $glue = '' ) * * @return string */ - public function join( $glue = '' ) + public function join($glue = '') { - return join( $glue, $this->getArrayCopy() ); + return join($glue, $this->getArrayCopy()); } } \ No newline at end of file diff --git a/src/Datastructures/Traits/ArrayFunctionsTrait.php b/src/Datastructures/Traits/ArrayFunctionsTrait.php index 35a532e..afe7c78 100644 --- a/src/Datastructures/Traits/ArrayFunctionsTrait.php +++ b/src/Datastructures/Traits/ArrayFunctionsTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Datastructures\Traits; @@ -36,11 +37,11 @@ trait ArrayFunctionsTrait * * @return SplArrayObject */ - public function getCombine( array $keys ) + public function getCombine(array $keys) { - $arrayCombine = array_combine( $keys, $this->getArrayCopy() ); + $arrayCombine = array_combine($keys, $this->getArrayCopy()); - return new SplArrayObject( $arrayCombine ); + return new SplArrayObject($arrayCombine); } // ------------------------------------------------------------------------ @@ -57,13 +58,13 @@ public function getCombine( array $keys ) * * @return array Returns an array of all the keys of the array copy. */ - public function getKeys( $searchValue = null, $strict = false ) + public function getKeys($searchValue = null, $strict = false) { - if ( isset( $searchValue ) ) { - return array_keys( $this->getArrayCopy(), $searchValue, $strict ); + if (isset($searchValue)) { + return array_keys($this->getArrayCopy(), $searchValue, $strict); } - return array_keys( $this->getArrayCopy() ); + return array_keys($this->getArrayCopy()); } // ------------------------------------------------------------------------ @@ -79,7 +80,7 @@ public function getKeys( $searchValue = null, $strict = false ) */ public function getValues() { - return array_values( $this->getArrayCopy() ); + return array_values($this->getArrayCopy()); } // ------------------------------------------------------------------------ @@ -105,9 +106,9 @@ public function getValues() * * @return array Returns the slice. If the offset is larger than the size of the array then returns an empty array. */ - public function getSlice( $offset = 0, $length = null, $preserveKeys = false ) + public function getSlice($offset = 0, $length = null, $preserveKeys = false) { - return array_slice( $this->getArrayCopy(), $offset, $length, $preserveKeys ); + return array_slice($this->getArrayCopy(), $offset, $length, $preserveKeys); } // ------------------------------------------------------------------------ @@ -126,12 +127,12 @@ public function getSlice( $offset = 0, $length = null, $preserveKeys = false ) * * @return array Returns the slices. If the offset is larger than the size of the array then returns an empty array. */ - public function getSlices( array $lengths, $preserveKeys = false ) + public function getSlices(array $lengths, $preserveKeys = false) { $arraySlices = []; - foreach ( $lengths as $key => $length ) { - $arraySlices[ $key ] = array_slice( $this->getArrayCopy(), 0, $length, $preserveKeys ); + foreach ($lengths as $key => $length) { + $arraySlices[ $key ] = array_slice($this->getArrayCopy(), 0, $length, $preserveKeys); } return $arraySlices; @@ -153,9 +154,9 @@ public function getSlices( array $lengths, $preserveKeys = false ) * @return array Returns a multidimensional numerically indexed array, starting with zero, with each dimension * containing size elements. */ - public function getChunk( $size, $preserveKeys = false ) + public function getChunk($size, $preserveKeys = false) { - return array_chunk( $this->getArrayCopy(), $size, $preserveKeys ); + return array_chunk($this->getArrayCopy(), $size, $preserveKeys); } // ------------------------------------------------------------------------ @@ -174,13 +175,13 @@ public function getChunk( $size, $preserveKeys = false ) * @return array Returns a multidimensional numerically indexed array, starting with zero, with each dimension * containing size elements. */ - public function getChunks( array $sizes, $preserveKeys = false ) + public function getChunks(array $sizes, $preserveKeys = false) { $arrayChunks = []; $offset = 0; - foreach ( $sizes as $key => $limit ) { - $arrayChunks[ $key ] = array_slice( $this->getArrayCopy(), $offset, $limit, $preserveKeys ); + foreach ($sizes as $key => $limit) { + $arrayChunks[ $key ] = array_slice($this->getArrayCopy(), $offset, $limit, $preserveKeys); $offset = $limit; } @@ -201,7 +202,7 @@ public function getChunks( array $sizes, $preserveKeys = false ) public function getShuffle() { $arrayCopy = $this->getArrayCopy(); - shuffle( $arrayCopy ); + shuffle($arrayCopy); return $arrayCopy; } @@ -218,9 +219,9 @@ public function getShuffle() * * @return array Returns the reversed array. */ - public function getReverse( $preserveKey = false ) + public function getReverse($preserveKey = false) { - return array_reverse( $this->getArrayCopy(), $preserveKey ); + return array_reverse($this->getArrayCopy(), $preserveKey); } // ------------------------------------------------------------------------ @@ -241,9 +242,9 @@ public function getReverse( $preserveKey = false ) * * @return array Returns an array of values representing a single column from the input array. */ - public function getColumn( $columnKey, $indexKey = null ) + public function getColumn($columnKey, $indexKey = null) { - return array_column( $this->getArrayCopy(), $columnKey, $indexKey ); + return array_column($this->getArrayCopy(), $columnKey, $indexKey); } // ------------------------------------------------------------------------ @@ -259,7 +260,7 @@ public function getColumn( $columnKey, $indexKey = null ) */ public function getFlip() { - return array_flip( $this->getArrayCopy() ); + return array_flip($this->getArrayCopy()); } // ------------------------------------------------------------------------ @@ -277,9 +278,9 @@ public function getFlip() * * @return array Returns the filtered array. */ - public function filter( $callback, $flag = 0 ) + public function filter($callback, $flag = 0) { - return array_filter( $this->getArrayCopy(), $callback, $flag ); + return array_filter($this->getArrayCopy(), $callback, $flag); } // ------------------------------------------------------------------------ @@ -295,7 +296,7 @@ public function filter( $callback, $flag = 0 ) */ public function getSum() { - return array_sum( $this->getArrayCopy() ); + return array_sum($this->getArrayCopy()); } // ------------------------------------------------------------------------ @@ -311,6 +312,6 @@ public function getSum() */ public function getCountValues() { - return array_count_values( $this->getArrayCopy() ); + return array_count_values($this->getArrayCopy()); } } \ No newline at end of file diff --git a/src/Exceptions/Abstracts/AbstractException.php b/src/Exceptions/Abstracts/AbstractException.php index 493e90d..077b9f1 100644 --- a/src/Exceptions/Abstracts/AbstractException.php +++ b/src/Exceptions/Abstracts/AbstractException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Abstracts; @@ -54,34 +55,34 @@ abstract class AbstractException extends \Exception * @param array $context * @param \Exception|NULL $previous */ - public function __construct( $message, $code = 0, array $context = [], \Exception $previous = null ) + public function __construct($message, $code = 0, array $context = [], \Exception $previous = null) { - if ( class_exists( 'O2System\Kernel', false ) ) { - $classInfo = new SplClassInfo( $this ); - $classNameParts = explode( '\\', $classInfo->getClass() ); - $classParameter = strtolower( end( $classNameParts ) ); - $classLanguageDirectory = dirname( $classInfo->getFileInfo()->getRealPath() ) . DIRECTORY_SEPARATOR . 'Languages' . DIRECTORY_SEPARATOR; - - if ( false !== ( $exceptionKey = array_search( 'Exception', $classNameParts ) ) OR - false !== ( $exceptionKey = array_search( 'Exceptions', $classNameParts ) ) + if (class_exists('O2System\Kernel', false)) { + $classInfo = new SplClassInfo($this); + $classNameParts = explode('\\', $classInfo->getClass()); + $classParameter = strtolower(end($classNameParts)); + $classLanguageDirectory = dirname($classInfo->getFileInfo()->getRealPath()) . DIRECTORY_SEPARATOR . 'Languages' . DIRECTORY_SEPARATOR; + + if (false !== ($exceptionKey = array_search('Exception', $classNameParts)) OR + false !== ($exceptionKey = array_search('Exceptions', $classNameParts)) ) { - if ( isset( $classNameParts[ $exceptionKey - 1 ] ) ) { + if (isset($classNameParts[ $exceptionKey - 1 ])) { $classParameter = $classNameParts[ $exceptionKey - 1 ]; } } - $this->view = strtolower( $classParameter . '_' . $this->view ); - $languageFilename = strtolower( $classParameter ) . '_' . language()->getDefault() . '.ini'; - $languageKey = strtoupper( $classParameter . '_exception' ); - language()->loadFile( $classLanguageDirectory . $languageFilename ); + $this->view = strtolower($classParameter . '_' . $this->view); + $languageFilename = strtolower($classParameter) . '_' . language()->getDefault() . '.ini'; + $languageKey = strtoupper($classParameter . '_exception'); + language()->loadFile($classLanguageDirectory . $languageFilename); - $this->header = language()->getLine( 'E_HEADER_' . $languageKey ); - $this->description = language()->getLine( 'E_DESCRIPTION_' . $languageKey ); - $message = language()->getLine( $message, $context ); + $this->header = language()->getLine('E_HEADER_' . $languageKey); + $this->description = language()->getLine('E_DESCRIPTION_' . $languageKey); + $message = language()->getLine($message, $context); } - parent::__construct( $message, $code, $previous ); + parent::__construct($message, $code, $previous); } // ------------------------------------------------------------------------ @@ -121,8 +122,8 @@ public function getDescription() */ public function getChronology() { - if ( class_exists( 'O2System\Gear\Trace' ) ) { - return ( new \O2System\Gear\Trace( $this->getTrace() ) )->getChronology(); + if (class_exists('O2System\Gear\Trace')) { + return (new \O2System\Gear\Trace($this->getTrace()))->getChronology(); } return $this->getTrace(); diff --git a/src/Exceptions/Error/ArithmeticError.php b/src/Exceptions/Error/ArithmeticError.php index 818169d..f4577d2 100644 --- a/src/Exceptions/Error/ArithmeticError.php +++ b/src/Exceptions/Error/ArithmeticError.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic; diff --git a/src/Exceptions/Error/AssertionError.php b/src/Exceptions/Error/AssertionError.php index 63ab8d2..37bc419 100644 --- a/src/Exceptions/Error/AssertionError.php +++ b/src/Exceptions/Error/AssertionError.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Error; diff --git a/src/Exceptions/Error/DivisionByZeroError.php b/src/Exceptions/Error/DivisionByZeroError.php index 947a744..5ada590 100644 --- a/src/Exceptions/Error/DivisionByZeroError.php +++ b/src/Exceptions/Error/DivisionByZeroError.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Error; diff --git a/src/Exceptions/Error/ParseError.php b/src/Exceptions/Error/ParseError.php index e1693ec..10e990e 100644 --- a/src/Exceptions/Error/ParseError.php +++ b/src/Exceptions/Error/ParseError.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Error; diff --git a/src/Exceptions/Error/TypeError.php b/src/Exceptions/Error/TypeError.php index 950f076..b86e241 100644 --- a/src/Exceptions/Error/TypeError.php +++ b/src/Exceptions/Error/TypeError.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Error; diff --git a/src/Exceptions/ErrorException.php b/src/Exceptions/ErrorException.php index ba565ab..387264f 100644 --- a/src/Exceptions/ErrorException.php +++ b/src/Exceptions/ErrorException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions; @@ -58,15 +59,15 @@ public function __construct( $this->file = $filename; $this->line = $line; - if ( class_exists( 'O2System\Kernel',false ) ) { - if ( is_array( $context ) ) { - $message = language()->getLine( $message, $context ); + if (class_exists('O2System\Kernel', false)) { + if (is_array($context)) { + $message = language()->getLine($message, $context); } else { - $message = language()->getLine( $message ); + $message = language()->getLine($message); } } - parent::__construct( $message, 0, [] ); + parent::__construct($message, 0, []); } // ------------------------------------------------------------------------ @@ -94,7 +95,7 @@ public function getSeverity() */ public function getStringSeverity() { - switch ( $this->severity ) { + switch ($this->severity) { case E_ERROR: // 1 // return 'E_ERROR'; case E_WARNING: // 2 // diff --git a/src/Exceptions/Logic/BadFunctionCall/BadDependencyCallException.php b/src/Exceptions/Logic/BadFunctionCall/BadDependencyCallException.php index a2fe885..db94b6f 100644 --- a/src/Exceptions/Logic/BadFunctionCall/BadDependencyCallException.php +++ b/src/Exceptions/Logic/BadFunctionCall/BadDependencyCallException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic\BadFunctionCall; diff --git a/src/Exceptions/Logic/BadFunctionCall/BadMethodCallException.php b/src/Exceptions/Logic/BadFunctionCall/BadMethodCallException.php index 865a164..06c2805 100644 --- a/src/Exceptions/Logic/BadFunctionCall/BadMethodCallException.php +++ b/src/Exceptions/Logic/BadFunctionCall/BadMethodCallException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic\BadFunctionCall; diff --git a/src/Exceptions/Logic/BadFunctionCall/BadPhpExtensionCallException.php b/src/Exceptions/Logic/BadFunctionCall/BadPhpExtensionCallException.php index fceb1c5..b24beef 100644 --- a/src/Exceptions/Logic/BadFunctionCall/BadPhpExtensionCallException.php +++ b/src/Exceptions/Logic/BadFunctionCall/BadPhpExtensionCallException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic\BadFunctionCall; diff --git a/src/Exceptions/Logic/BadFunctionCallException.php b/src/Exceptions/Logic/BadFunctionCallException.php index be9ef6d..ca75ee7 100644 --- a/src/Exceptions/Logic/BadFunctionCallException.php +++ b/src/Exceptions/Logic/BadFunctionCallException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic; diff --git a/src/Exceptions/Logic/DomainException.php b/src/Exceptions/Logic/DomainException.php index f510483..863443d 100644 --- a/src/Exceptions/Logic/DomainException.php +++ b/src/Exceptions/Logic/DomainException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic; diff --git a/src/Exceptions/Logic/InvalidArgumentException.php b/src/Exceptions/Logic/InvalidArgumentException.php index b88c867..6eeb5c8 100644 --- a/src/Exceptions/Logic/InvalidArgumentException.php +++ b/src/Exceptions/Logic/InvalidArgumentException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic; diff --git a/src/Exceptions/Logic/LengthException.php b/src/Exceptions/Logic/LengthException.php index 105c6e6..de044d8 100644 --- a/src/Exceptions/Logic/LengthException.php +++ b/src/Exceptions/Logic/LengthException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic; diff --git a/src/Exceptions/Logic/OutOfRangeException.php b/src/Exceptions/Logic/OutOfRangeException.php index 1610efa..6a8da17 100644 --- a/src/Exceptions/Logic/OutOfRangeException.php +++ b/src/Exceptions/Logic/OutOfRangeException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Logic; diff --git a/src/Exceptions/LogicException.php b/src/Exceptions/LogicException.php index d8eef28..0db660b 100644 --- a/src/Exceptions/LogicException.php +++ b/src/Exceptions/LogicException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions; diff --git a/src/Exceptions/Runtime/ConnectionException.php b/src/Exceptions/Runtime/ConnectionException.php index 86d0b01..615140c 100644 --- a/src/Exceptions/Runtime/ConnectionException.php +++ b/src/Exceptions/Runtime/ConnectionException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/Runtime/FileNotFoundException.php b/src/Exceptions/Runtime/FileNotFoundException.php index 22cc4e3..3906ca7 100644 --- a/src/Exceptions/Runtime/FileNotFoundException.php +++ b/src/Exceptions/Runtime/FileNotFoundException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/Runtime/OutOfBoundsException.php b/src/Exceptions/Runtime/OutOfBoundsException.php index 47eb0c9..8910374 100644 --- a/src/Exceptions/Runtime/OutOfBoundsException.php +++ b/src/Exceptions/Runtime/OutOfBoundsException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/Runtime/OverflowException.php b/src/Exceptions/Runtime/OverflowException.php index fc29027..60ea921 100644 --- a/src/Exceptions/Runtime/OverflowException.php +++ b/src/Exceptions/Runtime/OverflowException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/Runtime/RangeException.php b/src/Exceptions/Runtime/RangeException.php index 2588932..1757c58 100644 --- a/src/Exceptions/Runtime/RangeException.php +++ b/src/Exceptions/Runtime/RangeException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/Runtime/UnderflowException.php b/src/Exceptions/Runtime/UnderflowException.php index 21934bc..ac206dd 100644 --- a/src/Exceptions/Runtime/UnderflowException.php +++ b/src/Exceptions/Runtime/UnderflowException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/Runtime/UnexpectedValueException.php b/src/Exceptions/Runtime/UnexpectedValueException.php index 10e205f..e7beae4 100644 --- a/src/Exceptions/Runtime/UnexpectedValueException.php +++ b/src/Exceptions/Runtime/UnexpectedValueException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions\Runtime; diff --git a/src/Exceptions/RuntimeException.php b/src/Exceptions/RuntimeException.php index 3f58859..ed52448 100644 --- a/src/Exceptions/RuntimeException.php +++ b/src/Exceptions/RuntimeException.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Exceptions; diff --git a/src/Info/SplClassInfo.php b/src/Info/SplClassInfo.php index b2b8315..94480db 100644 --- a/src/Info/SplClassInfo.php +++ b/src/Info/SplClassInfo.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Info; @@ -35,14 +36,14 @@ class SplClassInfo extends \ReflectionClass * * @param mixed $className */ - public function __construct( $className ) + public function __construct($className) { - if ( is_object( $className ) ) { - $className = get_class( $className ); + if (is_object($className)) { + $className = get_class($className); } - if ( class_exists( $className ) ) { - parent::__construct( $className ); + if (class_exists($className)) { + parent::__construct($className); } } @@ -71,9 +72,9 @@ public function getClass() */ public function getParameter() { - $parts = explode('\\', $this->name ); + $parts = explode('\\', $this->name); - return strtolower( end( $parts ) ); + return strtolower(end($parts)); } // ------------------------------------------------------------------------ @@ -87,11 +88,11 @@ public function getParameter() */ public function getNamespaceInfo() { - if ( empty( $this->name ) ) { - throw new \RuntimeException( 'Internal error: SplClassInfo failed to retrieve the reflection object' ); + if (empty($this->name)) { + throw new \RuntimeException('Internal error: SplClassInfo failed to retrieve the reflection object'); } - return new SplNamespaceInfo( $this->name, $this->getFileName() ); + return new SplNamespaceInfo($this->name, $this->getFileName()); } // ------------------------------------------------------------------------ @@ -105,10 +106,10 @@ public function getNamespaceInfo() */ public function getFileInfo() { - if ( empty( $this->name ) ) { - throw new \RuntimeException( 'Internal error: SplClassInfo failed to retrieve the reflection object' ); + if (empty($this->name)) { + throw new \RuntimeException('Internal error: SplClassInfo failed to retrieve the reflection object'); } - return new SplFileInfo( $this->getFileName() ); + return new SplFileInfo($this->getFileName()); } } \ No newline at end of file diff --git a/src/Info/SplDirectoryInfo.php b/src/Info/SplDirectoryInfo.php index 712a4e9..f9b60c9 100644 --- a/src/Info/SplDirectoryInfo.php +++ b/src/Info/SplDirectoryInfo.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Info; @@ -42,10 +43,10 @@ class SplDirectoryInfo * * @param string $dir Directory Path */ - public function __construct( $dir ) + public function __construct($dir) { - $this->pathName = str_replace( [ '\\', '/' ], DIRECTORY_SEPARATOR, realpath( $dir ) ) . DIRECTORY_SEPARATOR; - $this->dirName = pathinfo( $this->pathName, PATHINFO_FILENAME ); + $this->pathName = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, realpath($dir)) . DIRECTORY_SEPARATOR; + $this->dirName = pathinfo($this->pathName, PATHINFO_FILENAME); } // ------------------------------------------------------------------------ @@ -59,7 +60,7 @@ public function __construct( $dir ) */ public function isExists() { - return (bool)is_dir( $this->pathName ); + return (bool)is_dir($this->pathName); } // ------------------------------------------------------------------------ @@ -73,7 +74,7 @@ public function isExists() */ public function getParentPath() { - return dirname( $this->pathName ); + return dirname($this->pathName); } // ------------------------------------------------------------------------ @@ -87,7 +88,7 @@ public function getParentPath() */ public function getParentRealPath() { - return dirname( $this->pathName ) . DIRECTORY_SEPARATOR; + return dirname($this->pathName) . DIRECTORY_SEPARATOR; } // ------------------------------------------------------------------------ @@ -101,14 +102,14 @@ public function getParentRealPath() */ public function getParentRelativePath() { - $scriptFilename = str_replace( [ '/', '\\' ], '/', dirname( $_SERVER[ 'SCRIPT_FILENAME' ] ) ); - $relativePath = str_replace( [ '/', '\\' ], '/', dirname( $this->pathName ) ) . '/'; + $scriptFilename = str_replace(['/', '\\'], '/', dirname($_SERVER[ 'SCRIPT_FILENAME' ])); + $relativePath = str_replace(['/', '\\'], '/', dirname($this->pathName)) . '/'; - if ( strpos( $scriptFilename, 'public' ) ) { - return str_replace( dirname( $scriptFilename ), '..', $relativePath ); + if (strpos($scriptFilename, 'public')) { + return str_replace(dirname($scriptFilename), '..', $relativePath); } - return str_replace( $scriptFilename, '', $relativePath ); + return str_replace($scriptFilename, '', $relativePath); } // ------------------------------------------------------------------------ @@ -122,9 +123,9 @@ public function getParentRelativePath() * * @return \O2System\Spl\Info\SplDirectoryInfo */ - public function getPathInfo( $className = null ) + public function getPathInfo($className = null) { - return isset( $className ) ? new $className( pathinfo( $this->pathName ) ) : $this; + return isset($className) ? new $className(pathinfo($this->pathName)) : $this; } // ------------------------------------------------------------------------ @@ -152,7 +153,7 @@ public function getDirName() */ public function getPathName() { - return isset( $this->pathName ) ? $this->getPath() : null; + return isset($this->pathName) ? $this->getPath() : null; } // ------------------------------------------------------------------------ @@ -166,7 +167,7 @@ public function getPathName() */ public function getPath() { - return realpath( $this->pathName ); + return realpath($this->pathName); } // ------------------------------------------------------------------------ @@ -194,14 +195,14 @@ public function getRealPath() */ public function getRelativePath() { - $scriptFilename = str_replace( [ '/', '\\' ], '/', dirname( $_SERVER[ 'SCRIPT_FILENAME' ] ) ); - $relativePath = str_replace( [ '/', '\\' ], '/', $this->pathName ); + $scriptFilename = str_replace(['/', '\\'], '/', dirname($_SERVER[ 'SCRIPT_FILENAME' ])); + $relativePath = str_replace(['/', '\\'], '/', $this->pathName); - if ( strpos( $scriptFilename, 'public' ) ) { - return str_replace( dirname( $scriptFilename ), '..', $relativePath ); + if (strpos($scriptFilename, 'public')) { + return str_replace(dirname($scriptFilename), '..', $relativePath); } - return str_replace( $scriptFilename, '', $relativePath ); + return str_replace($scriptFilename, '', $relativePath); } // ------------------------------------------------------------------------ @@ -215,7 +216,7 @@ public function getRelativePath() */ public function isReadable() { - return (bool)is_dir( $this->pathName ); + return (bool)is_dir($this->pathName); } // ------------------------------------------------------------------------ @@ -230,31 +231,31 @@ public function isReadable() public function isWritable() { // If we're on a Unix server with safe_mode off we call is_writable - if ( DIRECTORY_SEPARATOR === '/' AND - ( strpos( phpversion(), '5.4' ) !== false OR ! ini_get( 'safe_mode' ) ) + if (DIRECTORY_SEPARATOR === '/' AND + (strpos(phpversion(), '5.4') !== false OR ! ini_get('safe_mode')) ) { - return (bool)is_writable( $this->pathName ); + return (bool)is_writable($this->pathName); } /* For Windows servers and safe_mode "on" installations we'll actually * write a file then read it. Bah... */ - if ( is_dir( $this->pathName ) ) { - $file = $this->pathName . md5( mt_rand() ); - if ( ( $fp = @fopen( $file, 'ab' ) ) === false ) { + if (is_dir($this->pathName)) { + $file = $this->pathName . md5(mt_rand()); + if (($fp = @fopen($file, 'ab')) === false) { return false; } - fclose( $fp ); - @chmod( $file, 0777 ); - @unlink( $file ); + fclose($fp); + @chmod($file, 0777); + @unlink($file); return true; - } elseif ( ! is_dir( $this->pathName ) OR ( $fp = @fopen( $this->pathName, 'ab' ) ) === false ) { + } elseif ( ! is_dir($this->pathName) OR ($fp = @fopen($this->pathName, 'ab')) === false) { return false; } - fclose( $fp ); + fclose($fp); return true; } @@ -270,7 +271,7 @@ public function isWritable() */ public function getATime() { - return fileatime( $this->pathName ); + return fileatime($this->pathName); } // ------------------------------------------------------------------------ @@ -284,7 +285,7 @@ public function getATime() */ public function getCTime() { - return filectime( $this->pathName ); + return filectime($this->pathName); } // ------------------------------------------------------------------------ @@ -298,7 +299,7 @@ public function getCTime() */ public function getMTime() { - return filemtime( $this->pathName ); + return filemtime($this->pathName); } // ------------------------------------------------------------------------ @@ -312,7 +313,7 @@ public function getMTime() */ public function getInode() { - return fileinode( $this->pathName ); + return fileinode($this->pathName); } // ------------------------------------------------------------------------ @@ -326,9 +327,9 @@ public function getInode() * * @return int */ - public function getPerms( $octal = false ) + public function getPerms($octal = false) { - return $octal === false ? fileperms( $this->pathName ) : 0 . decoct( fileperms( $this->pathName ) & 0777 ); + return $octal === false ? fileperms($this->pathName) : 0 . decoct(fileperms($this->pathName) & 0777); } // ------------------------------------------------------------------------ @@ -342,19 +343,19 @@ public function getPerms( $octal = false ) * * @return array|int|string */ - public function getOwner( $id = false ) + public function getOwner($id = false) { - if ( $id ) { - if ( false !== ( $uid = fileowner( $this->pathName ) ) ) { - if ( function_exists( 'posix_getpwuid' ) ) { - return posix_getpwuid( $uid ); - } elseif ( $uid == 0 ) { + if ($id) { + if (false !== ($uid = fileowner($this->pathName))) { + if (function_exists('posix_getpwuid')) { + return posix_getpwuid($uid); + } elseif ($uid == 0) { return 'root'; } } } - return fileowner( $this->pathName ); + return fileowner($this->pathName); } // ------------------------------------------------------------------------ @@ -368,19 +369,19 @@ public function getOwner( $id = false ) * * @return array|int|string */ - public function getGroup( $id = false ) + public function getGroup($id = false) { - if ( $id ) { - if ( false !== ( $grid = fileowner( $this->pathName ) ) ) { - if ( function_exists( 'posix_getgrgid' ) ) { - return posix_getgrgid( $grid ); - } elseif ( $grid == 0 ) { + if ($id) { + if (false !== ($grid = fileowner($this->pathName))) { + if (function_exists('posix_getgrgid')) { + return posix_getgrgid($grid); + } elseif ($grid == 0) { return 'root'; } } } - return filegroup( $this->pathName ); + return filegroup($this->pathName); } // ------------------------------------------------------------------------ @@ -394,7 +395,7 @@ public function getGroup( $id = false ) */ public function getStat() { - return stat( $this->pathName ); + return stat($this->pathName); } // ------------------------------------------------------------------------ @@ -410,9 +411,9 @@ public function getSize() { $size = 0; - $files = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $this->pathName ) ); + $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->pathName)); - foreach ( $files as $file ) { + foreach ($files as $file) { $size += $file->getSize(); } @@ -431,19 +432,19 @@ public function getSize() public function getTree() { $tree = []; - $directoryIterator = new \DirectoryIterator( $this->pathName ); + $directoryIterator = new \DirectoryIterator($this->pathName); - foreach ( $directoryIterator as $directoryNode ) { - if ( $directoryNode->isDir() AND $directoryNode->isDot() === false ) { - $tree[ $directoryNode->getFilename() ] = ( new SplDirectoryInfo( + foreach ($directoryIterator as $directoryNode) { + if ($directoryNode->isDir() AND $directoryNode->isDot() === false) { + $tree[ $directoryNode->getFilename() ] = (new SplDirectoryInfo( $directoryNode->getPathName() - ) )->getTree(); - } elseif ( $directoryNode->isFile() ) { + ))->getTree(); + } elseif ($directoryNode->isFile()) { $tree[] = $directoryNode->getFilename(); } } - arsort( $tree, SORT_FLAG_CASE ); + arsort($tree, SORT_FLAG_CASE); return $tree; } @@ -459,7 +460,7 @@ public function getTree() */ public function getHandle() { - return dir( $this->pathName )->handle; + return dir($this->pathName)->handle; } // ------------------------------------------------------------------------ diff --git a/src/Info/SplFileInfo.php b/src/Info/SplFileInfo.php index 19d992d..de322c7 100644 --- a/src/Info/SplFileInfo.php +++ b/src/Info/SplFileInfo.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Info; @@ -35,12 +36,12 @@ class SplFileInfo extends \SplFileInfo * * @param string $filePath File Path. */ - public function __construct( $filePath ) + public function __construct($filePath) { - parent::__construct( $filePath ); + parent::__construct($filePath); - if ( file_exists( $filePath ) ) { - $this->mime = finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $filePath ); + if (file_exists($filePath)) { + $this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filePath); } } @@ -56,7 +57,7 @@ public function getMime() */ public function getFilename() { - return str_replace( '.' . $this->getExtension(), '', parent::getFilename() ); + return str_replace('.' . $this->getExtension(), '', parent::getFilename()); } /** @@ -66,13 +67,13 @@ public function getFilename() * * @return string */ - public function getBasename( $suffix = null ) + public function getBasename($suffix = null) { - if ( is_null( $suffix ) ) { + if (is_null($suffix)) { return parent::getBasename(); } - return str_replace( '.' . $this->getExtension(), '.' . trim( $suffix, '.' ), parent::getFilename() ); + return str_replace('.' . $this->getExtension(), '.' . trim($suffix, '.'), parent::getFilename()); } /** @@ -82,6 +83,6 @@ public function getBasename( $suffix = null ) */ public function getDirectoryInfo() { - return new SplDirectoryInfo( dirname( $this->getRealPath() ) ); + return new SplDirectoryInfo(dirname($this->getRealPath())); } } \ No newline at end of file diff --git a/src/Info/SplNamespaceInfo.php b/src/Info/SplNamespaceInfo.php index e7ddcda..20b022d 100644 --- a/src/Info/SplNamespaceInfo.php +++ b/src/Info/SplNamespaceInfo.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Info; @@ -41,25 +42,25 @@ class SplNamespaceInfo * @param mixed $namespace * @param null|string|array $path */ - public function __construct( $namespace, $path = null ) + public function __construct($namespace, $path = null) { - if ( is_object( $namespace ) ) { - $className = get_class( $namespace ); - $namespace = pathinfo( $className, PATHINFO_DIRNAME ); + if (is_object($namespace)) { + $className = get_class($namespace); + $namespace = pathinfo($className, PATHINFO_DIRNAME); - $reflection = new \ReflectionClass( $className ); + $reflection = new \ReflectionClass($className); - $path = pathinfo( $reflection->getFileName(), PATHINFO_DIRNAME ); + $path = pathinfo($reflection->getFileName(), PATHINFO_DIRNAME); } $this->name = $namespace; - if ( isset( $path ) ) { - if ( is_string( $path ) ) { - $this->paths[] = new SplDirectoryInfo( $path ); - } elseif ( is_array( $path ) ) { - foreach ( $path as $directory ) { - $this->paths[] = new SplDirectoryInfo( $directory ); + if (isset($path)) { + if (is_string($path)) { + $this->paths[] = new SplDirectoryInfo($path); + } elseif (is_array($path)) { + foreach ($path as $directory) { + $this->paths[] = new SplDirectoryInfo($directory); } } } @@ -75,12 +76,12 @@ public function __construct( $namespace, $path = null ) * * @return mixed|null */ - public function __call( $method, array $args = [] ) + public function __call($method, array $args = []) { - if ( method_exists( $this, $method ) ) { - return call_user_func_array( [ &$this, $method ], $args ); - } elseif ( method_exists( $this->directoryInfo, $method ) ) { - return call_user_func_array( [ &$this->directoryInfo, $method ], $args ); + if (method_exists($this, $method)) { + return call_user_func_array([&$this, $method], $args); + } elseif (method_exists($this->directoryInfo, $method)) { + return call_user_func_array([&$this->directoryInfo, $method], $args); } return null; @@ -97,6 +98,6 @@ public function __call( $method, array $args = [] ) */ public function getParent() { - return str_replace( DIRECTORY_SEPARATOR, '\\', pathinfo( $this->name, PATHINFO_DIRNAME ) ) . '\\'; + return str_replace(DIRECTORY_SEPARATOR, '\\', pathinfo($this->name, PATHINFO_DIRNAME)) . '\\'; } } \ No newline at end of file diff --git a/src/Interfaces/SplArrayInterface.php b/src/Interfaces/SplArrayInterface.php index 2ebb9c0..f5e2086 100644 --- a/src/Interfaces/SplArrayInterface.php +++ b/src/Interfaces/SplArrayInterface.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Interfaces; @@ -43,7 +44,7 @@ public function isEmpty(); * * @return bool */ - public function has( $needle, $strict = false ); + public function has($needle, $strict = false); // ------------------------------------------------------------------------ diff --git a/src/Iterators/ArrayIterator.php b/src/Iterators/ArrayIterator.php index c931a8f..b189665 100644 --- a/src/Iterators/ArrayIterator.php +++ b/src/Iterators/ArrayIterator.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Iterators; @@ -54,7 +55,7 @@ public function first() */ public function last() { - $this->seek( ( $this->count() ) - 1 ); + $this->seek(($this->count()) - 1); return $this->current(); } @@ -66,10 +67,10 @@ public function last() * * @param mixed $value The new value to store at the index. */ - public function push( $value ) + public function push($value) { - $this->offsetSet( $this->count(), $value ); - $this->seek( $this->count() - 1 ); + $this->offsetSet($this->count(), $value); + $this->seek($this->count() - 1); } // ------------------------------------------------------------------------ @@ -81,12 +82,12 @@ public function push( $value ) * * @param mixed $value The new value to store at the index. */ - public function unshift( $value ) + public function unshift($value) { $storage = $this->getArrayCopy(); - array_unshift( $storage, $value ); + array_unshift($storage, $value); - parent::__construct( $storage ); + parent::__construct($storage); } // ------------------------------------------------------------------------ @@ -94,17 +95,17 @@ public function unshift( $value ) public function shift() { $storage = $this->getArrayCopy(); - array_shift( $storage ); + array_shift($storage); - parent::__construct( $storage ); + parent::__construct($storage); } public function pop() { $storage = $this->getArrayCopy(); - array_pop( $storage ); + array_pop($storage); - parent::__construct( $storage ); + parent::__construct($storage); } /** @@ -118,9 +119,9 @@ public function pop() * * @return bool */ - public function has( $needle, $strict = false ) + public function has($needle, $strict = false) { - return (bool)in_array( $needle, $this->getArrayCopy(), $strict ); + return (bool)in_array($needle, $this->getArrayCopy(), $strict); } // ------------------------------------------------------------------------ @@ -135,11 +136,11 @@ public function has( $needle, $strict = false ) * * @return mixed Returns the key for needle if it is found in the array, FALSE otherwise. */ - public function search( $needle, $seek = false ) + public function search($needle, $seek = false) { - if ( false !== ( $position = array_search( $needle, $this->getArrayCopy() ) ) ) { - if ( $seek === true ) { - $this->seek( $position ); + if (false !== ($position = array_search($needle, $this->getArrayCopy()))) { + if ($seek === true) { + $this->seek($position); } return $position; @@ -162,12 +163,12 @@ public function search( $needle, $seek = false ) * * @return array Returns the filtered array. */ - public function unique( $sortFlags = SORT_STRING, $exchangeArray = false ) + public function unique($sortFlags = SORT_STRING, $exchangeArray = false) { - $unique = array_unique( $this->getArrayCopy(), $sortFlags ); + $unique = array_unique($this->getArrayCopy(), $sortFlags); - if ( $exchangeArray ) { - $this->exchangeArray( $unique ); + if ($exchangeArray) { + $this->exchangeArray($unique); } return $unique; @@ -186,10 +187,10 @@ public function unique( $sortFlags = SORT_STRING, $exchangeArray = false ) * @return array of the old storage. * @since 5.1.0 */ - public function exchangeArray( array $values ) + public function exchangeArray(array $values) { $oldStorage = $this->getArrayCopy(); - parent::__construct( $values ); + parent::__construct($values); return $oldStorage; } @@ -205,12 +206,12 @@ public function exchangeArray( array $values ) * * @return array The array merged copy of the resulting array */ - public function merge( array $values ) + public function merge(array $values) { $storage = $this->getArrayCopy(); - $storage = array_merge( $storage, $values ); + $storage = array_merge($storage, $values); - $this->exchangeArray( $storage ); + $this->exchangeArray($storage); return $storage; } @@ -226,13 +227,13 @@ public function merge( array $values ) * * @return void */ - public function remove( $needle ) + public function remove($needle) { - if ( false !== ( $position = array_search( $needle, $this->getArrayCopy() ) ) ) { - $firstStorage = array_splice( $this->getArrayCopy(), 0, $position ); - $endStorage = array_splice( $this->getArrayCopy(), $position + 1 ); + if (false !== ($position = array_search($needle, $this->getArrayCopy()))) { + $firstStorage = array_splice($this->getArrayCopy(), 0, $position); + $endStorage = array_splice($this->getArrayCopy(), $position + 1); - parent::__construct( array_merge( $firstStorage, $endStorage ) ); + parent::__construct(array_merge($firstStorage, $endStorage)); } } diff --git a/src/Traits/Collectors/ConfigCollectorTrait.php b/src/Traits/Collectors/ConfigCollectorTrait.php index 9a3c62d..c5f76a8 100644 --- a/src/Traits/Collectors/ConfigCollectorTrait.php +++ b/src/Traits/Collectors/ConfigCollectorTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Traits\Collectors; @@ -37,11 +38,11 @@ trait ConfigCollectorTrait * * @return $this */ - public function addConfig( $key, $value ) + public function addConfig($key, $value) { - if ( isset( $this->config[ $key ] ) ) { - if ( is_array( $value ) AND is_array( $this->config[ $key ] ) ) { - $this->config[ $key ] = array_merge( $this->config[ $key ], $value ); + if (isset($this->config[ $key ])) { + if (is_array($value) AND is_array($this->config[ $key ])) { + $this->config[ $key ] = array_merge($this->config[ $key ], $value); } else { $this->config[ $key ] = $value; } @@ -64,12 +65,12 @@ public function addConfig( $key, $value ) * * @return mixed */ - final public function getConfig( $key = null, $offset = null ) + final public function getConfig($key = null, $offset = null) { - if ( isset( $key ) ) { - if ( isset( $this->config[ $key ] ) ) { - if ( isset( $offset ) ) { - return isset( $this->config[ $key ][ $offset ] ) ? $this->config[ $key ][ $offset ] : null; + if (isset($key)) { + if (isset($this->config[ $key ])) { + if (isset($offset)) { + return isset($this->config[ $key ][ $offset ]) ? $this->config[ $key ][ $offset ] : null; } return $this->config[ $key ]; @@ -92,19 +93,19 @@ final public function getConfig( $key = null, $offset = null ) * * @return static */ - public function setConfig( $key, $value = null ) + public function setConfig($key, $value = null) { - if ( is_array( $key ) ) { - if ( empty( $this->config ) ) { + if (is_array($key)) { + if (empty($this->config)) { $this->config = $key; } else { - $this->config = array_merge( $this->config, $key ); + $this->config = array_merge($this->config, $key); } - } elseif( $key instanceof Config ) { + } elseif ($key instanceof Config) { $this->config = $key; - } elseif ( isset( $this->config[ $key ] ) ) { - if ( is_array( $value ) AND is_array( $this->config[ $key ] ) ) { - $this->config[ $key ] = array_merge( $this->config[ $key ], $value ); + } elseif (isset($this->config[ $key ])) { + if (is_array($value) AND is_array($this->config[ $key ])) { + $this->config[ $key ] = array_merge($this->config[ $key ], $value); } else { $this->config[ $key ] = $value; } diff --git a/src/Traits/Collectors/ErrorCollectorTrait.php b/src/Traits/Collectors/ErrorCollectorTrait.php index f3c8858..014c1ca 100644 --- a/src/Traits/Collectors/ErrorCollectorTrait.php +++ b/src/Traits/Collectors/ErrorCollectorTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Traits\Collectors; @@ -32,71 +33,71 @@ trait ErrorCollectorTrait // ------------------------------------------------------------------------ /** - * ErrorCollectorTrait::setErrors + * ErrorCollectorTrait::getErrors * - * Sets errors. + * Gets errors. * - * @param array $errors + * @return array */ - protected function setErrors( array $errors ) + public function getErrors() { - $this->errors = $errors; + return $this->errors; } // ------------------------------------------------------------------------ /** - * ErrorCollectorTrait::addErrors + * ErrorCollectorTrait::setErrors * - * Adds errors. + * Sets errors. * * @param array $errors */ - protected function addErrors( array $errors ) + protected function setErrors(array $errors) { - foreach ( $errors as $code => $message ) { - $this->addError( $code, $message ); - } + $this->errors = $errors; } // ------------------------------------------------------------------------ /** - * ErrorCollectorTrait::addError - * - * Add error. + * ErrorCollectorTrait::hasErrors * - * @param int $code Error code. - * @param string $message Error message. + * @return bool */ - protected function addError( $code, $message ) + public function hasErrors() { - $this->errors[ $code ] = $message; + return (bool)count($this->errors) ? true : false; } // ------------------------------------------------------------------------ /** - * ErrorCollectorTrait::getErrors + * ErrorCollectorTrait::addErrors * - * Gets errors. + * Adds errors. * - * @return array + * @param array $errors */ - public function getErrors() + protected function addErrors(array $errors) { - return $this->errors; + foreach ($errors as $code => $message) { + $this->addError($code, $message); + } } // ------------------------------------------------------------------------ /** - * ErrorCollectorTrait::hasErrors + * ErrorCollectorTrait::addError * - * @return bool + * Add error. + * + * @param int $code Error code. + * @param string $message Error message. */ - public function hasErrors() + protected function addError($code, $message) { - return (bool) count($this->errors) ? true : false; + $this->errors[ $code ] = $message; } } \ No newline at end of file diff --git a/src/Traits/Collectors/FileExtensionCollectorTrait.php b/src/Traits/Collectors/FileExtensionCollectorTrait.php index c19fe5a..7622eeb 100644 --- a/src/Traits/Collectors/FileExtensionCollectorTrait.php +++ b/src/Traits/Collectors/FileExtensionCollectorTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Traits\Collectors; @@ -28,28 +29,28 @@ public function getFileExtensions() return $this->fileExtensions; } - public function setFileExtensions( array $fileExtensions ) + public function setFileExtensions(array $fileExtensions) { $this->fileExtensions = $fileExtensions; return $this; } - public function addFileExtensions( array $fileExtensions ) + public function addFileExtensions(array $fileExtensions) { - foreach ( $fileExtensions as $fileExtension ) { - $this->addFileExtension( $fileExtension ); + foreach ($fileExtensions as $fileExtension) { + $this->addFileExtension($fileExtension); } return $this; } - public function addFileExtension( $fileExtension ) + public function addFileExtension($fileExtension) { - $fileExtension = '.' . trim( $fileExtension, '.' ); + $fileExtension = '.' . trim($fileExtension, '.'); - if ( ! in_array( $fileExtension, $this->fileExtensions ) ) { - array_push( $this->fileExtensions, $fileExtension ); + if ( ! in_array($fileExtension, $this->fileExtensions)) { + array_push($this->fileExtensions, $fileExtension); } return $this; diff --git a/src/Traits/Collectors/FilePathCollectorTrait.php b/src/Traits/Collectors/FilePathCollectorTrait.php index 1cd40c2..497debe 100644 --- a/src/Traits/Collectors/FilePathCollectorTrait.php +++ b/src/Traits/Collectors/FilePathCollectorTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Traits\Collectors; @@ -37,7 +38,7 @@ trait FilePathCollectorTrait */ protected $filePaths = []; - public function setFileDirName( $fileDirName ) + public function setFileDirName($fileDirName) { $this->fileDirName = $fileDirName; @@ -46,10 +47,10 @@ public function setFileDirName( $fileDirName ) // ------------------------------------------------------------------------ - public function removeFilePath( $filePath ) + public function removeFilePath($filePath) { - if ( false !== ( $key = array_search( $filePath, $this->filePaths ) ) ) { - unset( $this->filePaths[ $key ] ); + if (false !== ($key = array_search($filePath, $this->filePaths))) { + unset($this->filePaths[ $key ]); } return $this; @@ -57,27 +58,27 @@ public function removeFilePath( $filePath ) // ------------------------------------------------------------------------ - public function getFilePaths( $reverse = false ) + public function getFilePaths($reverse = false) { - return ( $reverse === true ? array_reverse( $this->filePaths ) : $this->filePaths ); + return ($reverse === true ? array_reverse($this->filePaths) : $this->filePaths); } // ------------------------------------------------------------------------ - public function setFilePaths( array $filePaths ) + public function setFilePaths(array $filePaths) { $this->filePaths = []; - $this->addFilePaths( $filePaths ); + $this->addFilePaths($filePaths); return $this; } // ------------------------------------------------------------------------ - public function addFilePaths( array $filePaths ) + public function addFilePaths(array $filePaths) { - foreach ( $filePaths as $filePath ) { - $this->addFilePath( $filePath ); + foreach ($filePaths as $filePath) { + $this->addFilePath($filePath); } return $this; @@ -85,14 +86,14 @@ public function addFilePaths( array $filePaths ) // ------------------------------------------------------------------------ - public function addFilePath( $filePath, $offset = null ) + public function addFilePath($filePath, $offset = null) { $filePath = rtrim( - str_replace( [ '\\', '/' ], DIRECTORY_SEPARATOR, $filePath ), + str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $filePath), DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR; - if ( isset( $this->fileDirName ) ) { + if (isset($this->fileDirName)) { $filePath = str_replace( $this->fileDirName . DIRECTORY_SEPARATOR, '', @@ -100,8 +101,8 @@ public function addFilePath( $filePath, $offset = null ) ) . $this->fileDirName . DIRECTORY_SEPARATOR; } - if ( is_dir( $filePath ) AND ! in_array( $filePath, $this->filePaths ) ) { - if( isset( $offset ) ) { + if (is_dir($filePath) AND ! in_array($filePath, $this->filePaths)) { + if (isset($offset)) { $this->filePaths[ $offset ] = $filePath; } else { $this->filePaths[] = $filePath; diff --git a/src/Traits/OptionsSetterTrait.php b/src/Traits/OptionsSetterTrait.php index e1b3e3f..0f4535e 100644 --- a/src/Traits/OptionsSetterTrait.php +++ b/src/Traits/OptionsSetterTrait.php @@ -8,6 +8,7 @@ * @author Steeve Andrian Salim * @copyright Copyright (c) Steeve Andrian Salim */ + // ------------------------------------------------------------------------ namespace O2System\Spl\Traits; @@ -28,14 +29,14 @@ trait OptionsSetterTrait * * @return $this */ - public function setOptions( array $options ) + public function setOptions(array $options) { - if ( count( $options ) ) { - foreach ( $options as $method => $value ) { - $method = camelcase( 'set_' . $method ); + if (count($options)) { + foreach ($options as $method => $value) { + $method = camelcase('set_' . $method); - if ( method_exists( $this, $method ) ) { - call_user_func_array( [ &$this, $method ], [ $value ] ); + if (method_exists($this, $method)) { + call_user_func_array([&$this, $method], [$value]); } } } diff --git a/src/autoload.php b/src/autoload.php index b310118..8a04321 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -16,27 +16,27 @@ * @param $className */ spl_autoload_register( - function ( $className ) { - if ( strpos( $className, 'O2System\Spl\\' ) === false ) { + function ($className) { + if (strpos($className, 'O2System\Spl\\') === false) { return; } - $className = ltrim( $className, '\\' ); + $className = ltrim($className, '\\'); $filePath = ''; - if ( $lastNsPos = strripos( $className, '\\' ) ) { - $namespace = substr( $className, 0, $lastNsPos ); - $className = substr( $className, $lastNsPos + 1 ); + if ($lastNsPos = strripos($className, '\\')) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); $filePath = $namespace . '\\'; } - $filePath .= str_replace( '_', DIRECTORY_SEPARATOR, $className ) . '.php'; + $filePath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; // Fixed Path - $filePath = str_replace( 'O2System\Spl\\', __DIR__ . DIRECTORY_SEPARATOR, $filePath ); - $filePath = str_replace( [ '\\', '/' ], DIRECTORY_SEPARATOR, $filePath ); + $filePath = str_replace('O2System\Spl\\', __DIR__ . DIRECTORY_SEPARATOR, $filePath); + $filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $filePath); - if ( file_exists( $filePath ) ) { + if (file_exists($filePath)) { require $filePath; }