Small code cleanup

This commit is contained in:
djmaze 2021-11-03 12:18:34 +01:00
parent 6e1cf74908
commit 9da4fd569b
2 changed files with 7 additions and 7 deletions

View file

@ -32,7 +32,7 @@ abstract class Collection extends \ArrayObject implements \JsonSerializable
{ {
if ($bToTop) { if ($bToTop) {
$array = $this->getArrayCopy(); $array = $this->getArrayCopy();
array_unshift($array, $mItem); \array_unshift($array, $mItem);
$this->exchangeArray($array); $this->exchangeArray($array);
} else { } else {
parent::append($mItem); parent::append($mItem);
@ -53,23 +53,23 @@ abstract class Collection extends \ArrayObject implements \JsonSerializable
public function Slice(int $offset, int $length = null, bool $preserve_keys = false) public function Slice(int $offset, int $length = null, bool $preserve_keys = false)
{ {
return new static( return new static(
array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys) \array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys)
); );
} }
public function Crop(int $length = null, int $offset = 0, bool $preserve_keys = false) public function Crop(int $length = null, int $offset = 0, bool $preserve_keys = false)
{ {
$this->exchangeArray( $this->exchangeArray(
array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys) \array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys)
); );
return $this; return $this;
} }
public function jsonSerialize() public function jsonSerialize()
{ {
$aNames = explode('\\', get_class($this)); $aNames = \explode('\\', \get_class($this));
return array( return array(
'@Object' => 'Collection/' . end($aNames), '@Object' => 'Collection/' . \end($aNames),
'@Count' => $this->Count(), '@Count' => $this->Count(),
'@Collection' => $this->getArrayCopy() '@Collection' => $this->getArrayCopy()
); );

View file

@ -20,8 +20,8 @@ class Exception extends \Exception
{ {
public function __construct(string $sMessage = '', int $iCode = 0, \Throwable $oPrevious = null) public function __construct(string $sMessage = '', int $iCode = 0, \Throwable $oPrevious = null)
{ {
$sMessage = 0 === strlen($sMessage) ? str_replace('\\', '-', get_class($this)).' ('. $sMessage = \strlen($sMessage) ? $sMessage
basename($this->getFile()).' ~ '.$this->getLine().')' : $sMessage; : \str_replace('\\', '-', \get_class($this)).' ('.\basename($this->getFile()).' ~ '.$this->getLine().')';
parent::__construct($sMessage, $iCode, $oPrevious); parent::__construct($sMessage, $iCode, $oPrevious);
} }