Skip to content
Snippets Groups Projects
Unverified Commit e963c98f authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

fix: use `set` in `get` method consistently

parent 9314a136
No related branches found
No related tags found
1 merge request!9fix: use `set` in `get` method consistently
## [3.0.2] - Unreleased
### Fixed
- `ArrayContainer::get` now uses `ArrayContainer::set` for value presence check
## [3.0.1] - 2021-08-14
### Added
- Added set_expiration method for WordPressTransientContainer class
......@@ -59,4 +63,4 @@
## [1.0.0] - 2019-02-04
### Added
- first stable version
\ No newline at end of file
- first stable version
......@@ -12,45 +12,45 @@ use WPDesk\Persistence\PersistentContainer;
* @package WPDesk\Persistence
*/
class ArrayContainer implements PersistentContainer {
use FallbackFromGetTrait;
/** @var array */
protected $array;
public function __construct( array $initial = [] ) {
$this->array = $initial;
}
public function set( string $id, $value ) {
if ( $value === null ) {
$this->delete( $id );
} else {
$this->array[ $id ] = $value;
}
}
public function delete( string $id ) {
unset( $this->array[ $id ] );
}
public function has( $id ): bool {
return key_exists( $id, $this->array );
}
public function get( $id ) {
if ( ! isset( $this->array[ $id ] ) ) {
throw new ElementNotExistsException( sprintf( 'Element %s not exists!', $id ) );
}
return $this->array[ $id ];
}
/**
* Return array that is used internally to save the data.
*
* @return array
*/
public function get_array() {
return $this->array;
}
}
\ No newline at end of file
use FallbackFromGetTrait;
/** @var array */
protected $array;
public function __construct( array $initial = [] ) {
$this->array = $initial;
}
public function set( string $id, $value ) {
if ($value === null ) {
$this->delete($id);
} else {
$this->array[ $id ] = $value;
}
}
public function delete( string $id ) {
unset($this->array[ $id ]);
}
public function has( $id ): bool {
return key_exists($id, $this->array);
}
public function get( $id ) {
if ( ! $this->has( $id ) ) {
throw new ElementNotExistsException(sprintf('Element %s not exists!', $id));
}
return $this->array[ $id ];
}
/**
* Return array that is used internally to save the data.
*
* @return array
*/
public function get_array() {
return $this->array;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment