Skip to content

Commit

Permalink
Fix ArrayAccess methods signature
Browse files Browse the repository at this point in the history
  • Loading branch information
drmad committed Oct 13, 2023
1 parent 9a41d42 commit c4b84fa
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Str.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

namespace Vendimia;
namespace Vendimia\Str;

use BadFunctionCallException;
use ArrayAccess;
use Iterator;
use Stringable;

/**
* String object implementation
*/
class Str implements ArrayAccess, Iterator
class Str implements ArrayAccess, Iterator, Stringable
{

/** The actual string */
Expand Down Expand Up @@ -53,7 +54,7 @@ function __construct($string = '', $encoding = false)
/**
* Syntax sugar for construc a new object
*/
public function new($string = '', $encoding = false)
public static function new($string = '', $encoding = false)
{
return new self($string, $encoding);
}
Expand Down Expand Up @@ -210,17 +211,17 @@ function __toString() {
}

/***** IMPLEMENTACIÓN DEL ARRAYACCESS *****/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return $offset >= 0 && $offset < mb_strlen($this->string);
}

public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return new self(mb_substr($this->string, $offset, 1 ));
}

public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{

// $value debe ser un string
Expand All @@ -232,35 +233,35 @@ public function offsetSet($offset, $value)
mb_substr($this->string, $offset + 1);
}

public function offsetUnset($offset)
public function offsetUnset($offset): void
{
$this->string =
mb_substr($this->string, 0, $offset) .
mb_substr($this->string, $offset + 1);

}

public function current()
public function current(): mixed
{
return $this[$this->iter_index];
}

public function key()
public function key(): mixed
{
return $this->iter_index;
}

public function next()
public function next(): void
{
$this->iter_index++;
}

public function rewind()
public function rewind(): void
{
$this->iter_index = 0;
}

public function valid()
public function valid(): bool
{
return $this->offsetExists($this->iter_index);
}
Expand Down

0 comments on commit c4b84fa

Please sign in to comment.