Skip to content

Commit

Permalink
Merge pull request #16 from PhantPHP/version-4
Browse files Browse the repository at this point in the history
Version 4
  • Loading branch information
lennyrouanet authored Oct 21, 2022
2 parents 9a7d469 + bed2210 commit d97f0d0
Show file tree
Hide file tree
Showing 94 changed files with 2,330 additions and 2,645 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ vendor/*

# Test
.phpunit*
public/code-coverage
.public

# Dev
.DS_Store
.nova/*
.php-cs-fixer.cache
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ PHP >= 8.0

## Abstract

- Aggregate
- Collection
- Entity
- Enum
- CollectionPaginated
- Value
- Boolean
- Decimal
Expand All @@ -38,6 +36,12 @@ PHP >= 8.0

- GpsCoordinates

### Fr

- CodeCommune
- CodePostal
- NumeroDepartement


## Id

Expand All @@ -52,16 +56,16 @@ PHP >= 8.0

## Number

- Note
- Grade
- Rate


## Person

- Birthday
- Firstname
- Gender
- Lastname
- Person


## Time
Expand Down
8 changes: 0 additions & 8 deletions component/Abstract/Aggregate.php

This file was deleted.

95 changes: 48 additions & 47 deletions component/Abstract/Collection.php
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;
}
}
170 changes: 85 additions & 85 deletions component/Abstract/CollectionPaginated.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Phant\DataStructure\Abstract;
Expand All @@ -7,89 +8,88 @@

abstract class CollectionPaginated extends Collection
{
private ?int $itemPage;
private ?int $itemByPage;
private ?int $itemTotal;

private ?int $pageCurrent;
private ?int $pageTotal;

public function __construct(
?int $pageCurrent = null,
?int $itemByPage = null,
?int $itemTotal = null
)
{
$this->itemByPage = $itemByPage;
$this->itemTotal = $itemTotal;
$this->itemPage = null;

$this->pageCurrent = $pageCurrent;
$this->pageTotal = null;

parent::__construct();
}

public function getItemByPage(): ?int
{
return $this->itemByPage;
}

public function getItemTotal(): ?int
{
return $this->itemTotal;
}

public function getItemPage(): ?int
{
return $this->itemPage;
}

public function getPageCurrent(): ?int
{
return $this->pageCurrent;
}

public function getPageTotal(): ?int
{
return $this->pageTotal;
}

protected function addItem(mixed $item): self
{
parent::addItem($item);

$this->paginationCalculation();

return $this;
}

protected function removeItem(mixed $item): self
{
parent::removeItem($item);

$this->paginationCalculation();

return $this;
}

protected function paginationCalculation(): void
{
$this->itemPageCalculation();
$this->pageTotalCalculation();
}

private function itemPageCalculation(): void
{
$this->itemPage = $this->getNbItems();
}

private function pageTotalCalculation(): void
{
$this->pageTotal = 0;

if ($this->itemTotal && $this->itemByPage) {
$this->pageTotal = (int)ceil($this->itemTotal / $this->itemByPage);
}
}
private ?int $itemPage;
private ?int $itemByPage;
private ?int $itemTotal;

private ?int $pageCurrent;
private ?int $pageTotal;

public function __construct(
?int $pageCurrent = null,
?int $itemByPage = null,
?int $itemTotal = null
) {
$this->itemByPage = $itemByPage;
$this->itemTotal = $itemTotal;
$this->itemPage = null;

$this->pageCurrent = $pageCurrent;
$this->pageTotal = null;

parent::__construct();
}

public function getItemByPage(): ?int
{
return $this->itemByPage;
}

public function getItemTotal(): ?int
{
return $this->itemTotal;
}

public function getItemPage(): ?int
{
return $this->itemPage;
}

public function getPageCurrent(): ?int
{
return $this->pageCurrent;
}

public function getPageTotal(): ?int
{
return $this->pageTotal;
}

protected function addItem(mixed $item): self
{
parent::addItem($item);

$this->paginationCalculation();

return $this;
}

protected function removeItem(mixed $item): self
{
parent::removeItem($item);

$this->paginationCalculation();

return $this;
}

protected function paginationCalculation(): void
{
$this->itemPageCalculation();
$this->pageTotalCalculation();
}

private function itemPageCalculation(): void
{
$this->itemPage = $this->getNbItems();
}

private function pageTotalCalculation(): void
{
$this->pageTotal = 0;

if ($this->itemTotal && $this->itemByPage) {
$this->pageTotal = (int)ceil($this->itemTotal / $this->itemByPage);
}
}
}
8 changes: 0 additions & 8 deletions component/Abstract/Entity.php

This file was deleted.

38 changes: 0 additions & 38 deletions component/Abstract/Enum.php

This file was deleted.

Loading

0 comments on commit d97f0d0

Please sign in to comment.