Skip to content

Commit

Permalink
refactor structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kurowski committed Jan 11, 2023
1 parent 40a8488 commit 34f9775
Show file tree
Hide file tree
Showing 26 changed files with 168 additions and 176 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Retrieve all information about multiple events.
Basic usage:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters();
$events = $client->getEvents($parameters); // $parameters are optional

// example of reading data
Expand All @@ -71,39 +71,39 @@ foreach ($events as $event) {
Events can be filtered by group, category, program or intended for:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters();

// only camps
$parameters->setGroup(\HnutiBrontosaurus\BisClient\Enums\EventGroup::CAMP());
$parameters->setGroup(\HnutiBrontosaurus\BisClient\Event\Group::CAMP());

// only events of "voluntary" category
$parameters->setCategory(\HnutiBrontosaurus\BisClient\Enums\EventCategory::VOLUNTEERING());
$parameters->setCategory(\HnutiBrontosaurus\BisClient\Event\Category::VOLUNTEERING());

// only events of "PsB" program
$parameters->setProgram(\HnutiBrontosaurus\BisClient\Enums\Program::HOLIDAYS_WITH_BRONTOSAURUS());
$parameters->setProgram(\HnutiBrontosaurus\BisClient\Event\Program::HOLIDAYS_WITH_BRONTOSAURUS());

// only events intended for first time participants
$parameters->setIntendedFor(\HnutiBrontosaurus\BisClient\Enums\IntendedFor::FIRST_TIME_PARTICIPANT());
$parameters->setIntendedFor(\HnutiBrontosaurus\BisClient\Event\IntendedFor::FIRST_TIME_PARTICIPANT());

$events = $client->getEvents($parameters);
```

Note that each method call rewrites the previous one:

```php
$parameters->setCategory(\HnutiBrontosaurus\BisClient\Enums\EventCategory::VOLUNTEERING());
$parameters->setCategory(\HnutiBrontosaurus\BisClient\Enums\EventCategory::EXPERIENCE());
$parameters->setCategory(\HnutiBrontosaurus\BisClient\Event\Category::VOLUNTEERING());
$parameters->setCategory(\HnutiBrontosaurus\BisClient\Event\Category::EXPERIENCE());
// ⚠ result is only "EXPERIENCE"
```

You can set more values at once with method's plural complement:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters();

$parameters->setCategories([
\HnutiBrontosaurus\BisClient\Enums\EventCategory::VOLUNTEERING(),
\HnutiBrontosaurus\BisClient\Enums\EventCategory::EXPERIENCE(),
\HnutiBrontosaurus\BisClient\Event\Category::VOLUNTEERING(),
\HnutiBrontosaurus\BisClient\Event\Category::EXPERIENCE(),
]);

$events = $client->getEvents($parameters);
Expand All @@ -114,11 +114,11 @@ $events = $client->getEvents($parameters);
Restrict retrieved events to be in given period:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters();

$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Request\Event\Period::RUNNING_AND_FUTURE()); // default
$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Request\Event\Period::RUNNING_ONLY());
$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Request\Event\Period::UNLIMITED());
$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Event\Request\Period::RUNNING_AND_FUTURE()); // default
$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Event\Request\Period::RUNNING_ONLY());
$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Event\Request\Period::UNLIMITED());

$events = $client->getEvents($parameters);
```
Expand All @@ -135,7 +135,7 @@ $parameters->setDateEndLessThanOrEqualTo($date);
$parameters->setDateEndGreaterThanOrEqualTo($date);
```

If you need to reset default/previous setting:
If you need to reset default/previous dates:

```php
// either
Expand All @@ -155,7 +155,7 @@ $parameters->setDateStartLessThanOrEqualTo($date, reset: true);
Choose whether you want to order by start or end date:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters();

// sort events by date from or date to
$parameters->orderByStartDate();
Expand All @@ -164,7 +164,7 @@ $parameters->orderByEndDate(); // default
$events = $client->getEvents($parameters);
```

Both methods have optional parameter `bool $desc` which obviously sorts events in DESC order:
Both methods have optional parameter `$desc` which allows to sort events in DESC order:

```php
$parameters->orderByDateFrom(desc: true);
Expand All @@ -175,7 +175,7 @@ $parameters->orderByDateFrom(desc: true);
Limit the size of obtained events or remove the limit completely:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters();

$parameters->setLimit(50);
$parameters->removeLimit();
Expand All @@ -189,7 +189,7 @@ $events = $client->getEvents($parameters);
For retrieving information about all administration units:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\AdministrationUnit\AdministrationUnitParameters();
$parameters = new \HnutiBrontosaurus\BisClient\AdministrationUnit\Request\AdministrationUnitParameters();
$administrationUnits = $client->getAdministrationUnits($parameters); // $parameters is optional

foreach ($administrationUnits as $administrationUnit) {
Expand All @@ -205,7 +205,7 @@ foreach ($administrationUnits as $administrationUnit) {
Retrieving information about all opportunities:

```php
$parameters = new \HnutiBrontosaurus\BisClient\Request\Opportunity\OpportunityParameters();
$parameters = new \HnutiBrontosaurus\BisClient\Opportunity\Request\OpportunityParameters();
$opportunities = $client->getOpportunities($parameters); // $parameters is optional

foreach ($opportunities as $opportunity) {
Expand Down Expand Up @@ -283,9 +283,10 @@ composer install

- `docs` – instruction on how connection between brontoweb and BIS works (todo: move to brontoweb repo)
- `src` – source code
- `Enums` – basic enum types
- `Request` – request-related value objects
- `Response` – response-related value objects and exceptions
- `AdministrationUnit` – value objects related to administration units
- `Event` – value objects related to events
- `Opportunity` – value objects related to opportunities
- `Response` – response value objects common to all endpoints
- `BisClient` – client itself, serves for making requests to BIS API
- `BisClientFactory` – takes configuration and creates instance of `BisClient`
- `HttpClient` – wrapper around Guzzle client which adds BIS API specific pieces into the request
Expand Down
23 changes: 23 additions & 0 deletions src/AdministrationUnit/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\AdministrationUnit;

use Grifart\Enum\AutoInstances;
use Grifart\Enum\Enum;


/**
* @method static Category CLUB()
* @method static Category BASIC_SECTION()
* @method static Category REGIONAL_CENTER()
* @method static Category HEADQUARTER()
*/
final class Category extends Enum
{
use AutoInstances;

protected const CLUB = 'club';
protected const BASIC_SECTION = 'basic_section';
protected const REGIONAL_CENTER = 'regional_center';
protected const HEADQUARTER = 'headquarter';
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Request\AdministrationUnit;
namespace HnutiBrontosaurus\BisClient\AdministrationUnit\Request;

use HnutiBrontosaurus\BisClient\Enums\AdministrationUnitCategory;
use HnutiBrontosaurus\BisClient\Request\LimitParameter;
use HnutiBrontosaurus\BisClient\Request\QueryParameters;
use HnutiBrontosaurus\BisClient\AdministrationUnit\Category;
use HnutiBrontosaurus\BisClient\LimitParameter;
use HnutiBrontosaurus\BisClient\QueryParameters;


final class AdministrationUnitParameters implements QueryParameters
Expand All @@ -17,17 +17,17 @@ public function __construct()

// categories

/** @var AdministrationUnitCategory[] */
/** @var Category[] */
private array $categories = [];

public function setCategory(AdministrationUnitCategory $category): self
public function setCategory(Category $category): self
{
$this->categories = [$category];
return $this;
}

/**
* @param AdministrationUnitCategory[] $categories
* @param Category[] $categories
*/
public function setCategories(array $categories): self
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Response\AdministrationUnit;
namespace HnutiBrontosaurus\BisClient\AdministrationUnit\Response;

use HnutiBrontosaurus\BisClient\Enums\AdministrationUnitCategory;
use HnutiBrontosaurus\BisClient\AdministrationUnit\Category;
use HnutiBrontosaurus\BisClient\Response\Coordinates;


Expand All @@ -21,7 +21,7 @@ private function __construct(
private ?string $phone,
private ?string $email,
private ?string $website,
private AdministrationUnitCategory $category,
private Category $category,
private ?string $chairman,
private ?string $manager,
private array $rawData,
Expand Down Expand Up @@ -68,7 +68,7 @@ public static function fromResponseData(array $data): self
$data['phone'] !== '' ? $data['phone'] : null,
$data['email'] !== '' ? $data['email'] : null,
$data['www'] !== '' ? $data['www'] : null,
AdministrationUnitCategory::fromScalar($data['category']['slug']),
Category::fromScalar($data['category']['slug']),
$data['chairman'] !== null ? $data['chairman']['name'] : null,
$data['manager'] !== null ? $data['manager']['name'] : null,
$data,
Expand Down Expand Up @@ -138,25 +138,25 @@ public function getManager(): ?string

public function isClub(): bool
{
return $this->category->equals(AdministrationUnitCategory::CLUB());
return $this->category->equals(Category::CLUB());
}


public function isBaseUnit(): bool
{
return $this->category->equals(AdministrationUnitCategory::BASIC_SECTION());
return $this->category->equals(Category::BASIC_SECTION());
}


public function isRegionalUnit(): bool
{
return $this->category->equals(AdministrationUnitCategory::REGIONAL_CENTER());
return $this->category->equals(Category::REGIONAL_CENTER());
}


public function isOffice(): bool
{
return $this->category->equals(AdministrationUnitCategory::HEADQUARTER());
return $this->category->equals(Category::HEADQUARTER());
}


Expand Down
13 changes: 6 additions & 7 deletions src/BisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace HnutiBrontosaurus\BisClient;

use HnutiBrontosaurus\BisClient\Request\AdministrationUnit\AdministrationUnitParameters;
use HnutiBrontosaurus\BisClient\Request\Event\EventParameters;
use HnutiBrontosaurus\BisClient\Request\Opportunity\OpportunityParameters;
use HnutiBrontosaurus\BisClient\Request\QueryParameters;
use HnutiBrontosaurus\BisClient\Response\AdministrationUnit\AdministrationUnit;
use HnutiBrontosaurus\BisClient\Response\Event\Event;
use HnutiBrontosaurus\BisClient\Response\Opportunity\Opportunity;
use HnutiBrontosaurus\BisClient\AdministrationUnit\Request\AdministrationUnitParameters as AdministrationUnitParameters;
use HnutiBrontosaurus\BisClient\AdministrationUnit\Response\AdministrationUnit;
use HnutiBrontosaurus\BisClient\Event\Request\EventParameters as EventParameters;
use HnutiBrontosaurus\BisClient\Event\Response\Event;
use HnutiBrontosaurus\BisClient\Opportunity\Request\OpportunityParameters as OpportunityParameters;
use HnutiBrontosaurus\BisClient\Opportunity\Response\Opportunity;


final class BisClient
Expand Down
23 changes: 0 additions & 23 deletions src/Enums/AdministrationUnitCategory.php

This file was deleted.

34 changes: 17 additions & 17 deletions src/Enums/EventCategory.php → src/Event/Category.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Enums;
namespace HnutiBrontosaurus\BisClient\Event;

use Grifart\Enum\AutoInstances;
use Grifart\Enum\Enum;


/**
* @method static EventCategory VOLUNTEERING()
* @method static EventCategory EXPERIENCE()
* @method static EventCategory EDUCATIONAL_LECTURE()
* @method static EventCategory EDUCATIONAL_COURSE()
* @method static EventCategory EDUCATIONAL_OHB()
* @method static EventCategory EDUCATIONAL_EDUCATIONAL()
* @method static EventCategory EDUCATIONAL_EDUCATIONAL_WITH_STAY()
* @method static EventCategory CLUB_MEETING()
* @method static EventCategory CLUB_LECTURE()
* @method static EventCategory FOR_PUBLIC()
* @method static EventCategory ECO_TENT()
* @method static EventCategory EXHIBITION()
* @method static EventCategory INTERNAL_VOLUNTEER_MEETING()
* @method static EventCategory INTERNAL_GENERAL_MEETING()
* @method static EventCategory INTERNAL_SECTION_MEETING()
* @method static Category VOLUNTEERING()
* @method static Category EXPERIENCE()
* @method static Category EDUCATIONAL_LECTURE()
* @method static Category EDUCATIONAL_COURSE()
* @method static Category EDUCATIONAL_OHB()
* @method static Category EDUCATIONAL_EDUCATIONAL()
* @method static Category EDUCATIONAL_EDUCATIONAL_WITH_STAY()
* @method static Category CLUB_MEETING()
* @method static Category CLUB_LECTURE()
* @method static Category FOR_PUBLIC()
* @method static Category ECO_TENT()
* @method static Category EXHIBITION()
* @method static Category INTERNAL_VOLUNTEER_MEETING()
* @method static Category INTERNAL_GENERAL_MEETING()
* @method static Category INTERNAL_SECTION_MEETING()
*/
final class EventCategory extends Enum
final class Category extends Enum
{
use AutoInstances;

Expand Down
10 changes: 5 additions & 5 deletions src/Enums/EventGroup.php → src/Event/Group.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Enums;
namespace HnutiBrontosaurus\BisClient\Event;

use Grifart\Enum\AutoInstances;
use Grifart\Enum\Enum;


/**
* @method static EventGroup CAMP()
* @method static EventGroup WEEKEND_EVENT()
* @method static EventGroup OTHER()
* @method static Group CAMP()
* @method static Group WEEKEND_EVENT()
* @method static Group OTHER()
*/
final class EventGroup extends Enum
final class Group extends Enum
{
use AutoInstances;

Expand Down
2 changes: 1 addition & 1 deletion src/Enums/IntendedFor.php → src/Event/IntendedFor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Enums;
namespace HnutiBrontosaurus\BisClient\Event;

use Grifart\Enum\AutoInstances;
use Grifart\Enum\Enum;
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/Program.php → src/Event/Program.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Enums;
namespace HnutiBrontosaurus\BisClient\Event;

use Grifart\Enum\AutoInstances;
use Grifart\Enum\Enum;
Expand Down
Loading

0 comments on commit 34f9775

Please sign in to comment.