-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from PhantPHP/version-4
Version 4
- Loading branch information
Showing
94 changed files
with
2,330 additions
and
2,645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ vendor/* | |
|
||
# Test | ||
.phpunit* | ||
public/code-coverage | ||
.public | ||
|
||
# Dev | ||
.DS_Store | ||
.nova/* | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\DataStructure\Abstract; | ||
|
||
abstract class Collection | ||
{ | ||
protected array $items; | ||
|
||
public function __construct() | ||
{ | ||
$this->items = []; | ||
} | ||
|
||
protected function addItem(mixed $item): self | ||
{ | ||
if (array_search($item, $this->items) == false) { | ||
$this->items[] = $item; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
protected function removeItem(mixed $item): self | ||
{ | ||
if (($key = array_search($item, $this->items)) !== false) { | ||
unset($this->items[ $key ]); | ||
$this->items = array_values($this->items); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function itemsIterator(): \Generator | ||
{ | ||
foreach ($this->items as $item) { | ||
yield $item; | ||
} | ||
} | ||
|
||
public function isEmpty(): bool | ||
{ | ||
return empty($this->items); | ||
} | ||
|
||
public function getNbItems(): int | ||
{ | ||
return count($this->items); | ||
} | ||
|
||
public function getByKey(int $key): mixed | ||
{ | ||
return $this->items[ $key ] ?? null; | ||
} | ||
protected array $items; | ||
|
||
public function __construct() | ||
{ | ||
$this->items = []; | ||
} | ||
|
||
protected function addItem(mixed $item): self | ||
{ | ||
if (array_search($item, $this->items) == false) { | ||
$this->items[] = $item; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
protected function removeItem(mixed $item): self | ||
{ | ||
if (($key = array_search($item, $this->items)) !== false) { | ||
unset($this->items[ $key ]); | ||
$this->items = array_values($this->items); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function itemsIterator(): \Generator | ||
{ | ||
foreach ($this->items as $item) { | ||
yield $item; | ||
} | ||
} | ||
|
||
public function isEmpty(): bool | ||
{ | ||
return empty($this->items); | ||
} | ||
|
||
public function getNbItems(): int | ||
{ | ||
return count($this->items); | ||
} | ||
|
||
public function getByKey(int $key): mixed | ||
{ | ||
return $this->items[ $key ] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.