Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring #100

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ jobs:
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
file: ./docker/Dockerfile
push: true
build-args:
APP_VERSION=${{ steps.previoustag.outputs.tag }}
FRONTEND_IMAGE_TAG=latest
tags:
${{ secrets.DOCKER_HUB_USERNAME }}/buggregator:latest, ${{ secrets.DOCKER_HUB_USERNAME }}/buggregator:${{ steps.previoustag.outputs.tag }}
16 changes: 16 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
pull_request: null

name: phpunit

jobs:
phpunit:
uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
with:
install_protoc: true
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
stability: >-
['prefer-stable']
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ rr*
protoc-gen-php-grpc*
.env
.phpunit.result.cache
.php-cs-fixer.cache
.deptrac.cache
composer.lock
2 changes: 1 addition & 1 deletion .rr.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.7'
version: '3'

rpc:
listen: tcp://127.0.0.1:6001
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<a href="https://discord.gg/vDsCD3EKUB"><img src="https://img.shields.io/badge/discord-chat-magenta.svg"></a>
[![Twitter](https://img.shields.io/badge/twitter-Follow-blue)](https://twitter.com/buggregator)
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dbutschster%26type%3Dpatrons&style=flat)](https://patreon.com/butschster)
[![phpunit](https://github.com/buggregator/server/actions/workflows/phpunit.yml/badge.svg)](https://github.com/buggregator/server/actions/workflows/phpunit.yml)

**Buggregator is a lightweight, standalone server that offers a range of debugging features for PHP applications. Think of it as a Swiss Army knife for developers. What makes it special is that it offers a range of features that you would usually find in various paid tools, but it's available for free.**

Expand Down
4 changes: 4 additions & 0 deletions app/config/broadcasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Application\Broadcasting\InMemoryDriver;
use Spiral\Broadcasting\Driver\NullBroadcast;

return [
Expand All @@ -14,5 +15,8 @@
'null' => [
'driver' => NullBroadcast::class,
],
'in-memory' => [
'driver' => InMemoryDriver::class,
],
],
];
18 changes: 11 additions & 7 deletions app/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
declare(strict_types=1);

use Spiral\Cache\Storage\ArrayStorage;
use Spiral\Cache\Storage\FileStorage;

$defaultStorage = env('CACHE_DEFAULT_STORAGE', 'roadrunner');

return [
'default' => env('CACHE_STORAGE', 'local'),
'default' => env('CACHE_STORAGE', 'roadrunner'),
'aliases' => [
'events' => ['storage' => $defaultStorage, 'prefix' => 'events:'],
'local' => ['storage' => $defaultStorage, 'prefix' => 'local:'],
],
'storages' => [
'local' => [
'type' => 'roadrunner',
'driver' => 'local',
'array' => [
'type' => ArrayStorage::class,
],
'events' => [
'roadrunner' => [
'type' => 'roadrunner',
'driver' => 'events',
'driver' => 'local',
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up(): void
->addColumn('uuid', 'string', ['nullable' => false, 'default' => null])
->addColumn('type', 'string', ['nullable' => false, 'default' => null])
->addColumn('payload', 'longText', ['nullable' => false, 'default' => null])
->addColumn('date', 'datetime', ['nullable' => false, 'default' => null])
->addColumn('timestamp', 'float', ['nullable' => false, 'default' => null])
->addColumn('project_id', 'integer', ['nullable' => true, 'default' => null])
->setPrimaryKeys(['uuid'])
->create();
Expand Down
8 changes: 4 additions & 4 deletions app/modules/Events/Domain/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function __construct(
#[Column(type: 'longText', typecast: 'json')]
private Json $payload,

#[Column(type: 'datetime')]
private DateTimeImmutable $date,
#[Column(type: 'float')]
private float $timestamp,

#[Column(type: 'integer', nullable: true)]
private ?int $projectId,
Expand All @@ -49,9 +49,9 @@ public function getPayload(): Json
return $this->payload;
}

public function getDate(): DateTimeImmutable
public function getTimestamp(): float
{
return $this->date;
return $this->timestamp;
}

public function getProjectId(): ?int
Expand Down
2 changes: 1 addition & 1 deletion app/modules/Events/Domain/EventRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Cycle\ORM\RepositoryInterface;

/**
* @template TEntity of Event
* @extends RepositoryInterface<Event>
*/
interface EventRepositoryInterface extends RepositoryInterface
{
Expand Down
2 changes: 1 addition & 1 deletion app/modules/Events/Domain/Events/EventWasReceived.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
public readonly Uuid $uuid,
public readonly string $type,
public readonly array $payload,
public readonly int $timestamp,
public readonly float $timestamp,
public readonly ?int $projectId = null,
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Application\Commands;
namespace Modules\Events\Interfaces\Commands;

use App\Application\Commands\ClearEvents;
use Modules\Events\Domain\EventRepositoryInterface;
Expand All @@ -14,7 +14,7 @@ final class ClearEventsHandler
{
public function __construct(
private readonly EventRepositoryInterface $events,
private readonly EventDispatcherInterface $dispatcher
private readonly EventDispatcherInterface $dispatcher,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Application\Commands;
namespace Modules\Events\Interfaces\Commands;

use App\Application\Commands\DeleteEvent;
use Modules\Events\Domain\EventRepositoryInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Application\Commands;
namespace Modules\Events\Interfaces\Commands;

use App\Application\Commands\FindProjectByName;
use App\Application\Commands\HandleReceivedEvent;
Expand All @@ -20,7 +20,7 @@ final class StoreEventHandler
public function __construct(
private readonly EventDispatcherInterface $dispatcher,
private readonly EventRepositoryInterface $events,
private readonly QueryBusInterface $queryBus
private readonly QueryBusInterface $queryBus,
) {
}

Expand All @@ -37,9 +37,9 @@ public function handle(HandleReceivedEvent $command): void
$command->uuid,
$command->type,
new Json($command->payload),
Carbon::createFromTimestamp($command->timestamp)->toDateTimeImmutable(),
$command->timestamp,
$projectId,
)
),
);

$this->dispatcher->dispatch(
Expand All @@ -49,7 +49,7 @@ public function handle(HandleReceivedEvent $command): void
payload: $command->payload,
timestamp: $command->timestamp,
projectId: $projectId,
)
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
namespace Modules\Events\Interfaces\Http\Controllers;

use App\Application\Commands\ClearEvents;
use App\Application\HTTP\Response\ResourceInterface;
use App\Application\HTTP\Response\SuccessResource;
use Modules\Events\Interfaces\Http\Request\ClearEventsRequest;
use Spiral\Cqrs\CommandBusInterface;
use Spiral\Router\Annotation\Route;

final class ClearEventsAction
final class ClearAction
{
#[Route(route: 'events', name: 'events.clear', methods: 'DELETE', group: 'api')]
public function __invoke(ClearEventsRequest $request, CommandBusInterface $bus): void
public function __invoke(ClearEventsRequest $request, CommandBusInterface $bus): ResourceInterface
{
$bus->dispatch(
new ClearEvents(type: $request->type)
new ClearEvents(type: $request->type),
);

return new SuccessResource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@

use App\Application\Commands\DeleteEvent;
use App\Application\Domain\ValueObjects\Uuid;
use App\Application\HTTP\Response\ResourceInterface;
use App\Application\HTTP\Response\SuccessResource;
use Spiral\Cqrs\CommandBusInterface;
use Spiral\Router\Annotation\Route;

final class DeleteEventAction
final class DeleteAction
{
#[Route(route: 'event/<uuid>', name: 'event.delete', methods: 'DELETE', group: 'api')]
public function __invoke(CommandBusInterface $bus, Uuid $uuid): void
public function __invoke(CommandBusInterface $bus, Uuid $uuid): ResourceInterface
{
$bus->dispatch(
new DeleteEvent($uuid)
new DeleteEvent($uuid),
);

return new SuccessResource();
}
}
7 changes: 4 additions & 3 deletions app/modules/Events/Interfaces/Http/Controllers/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

use App\Application\Commands\FindEvents;
use Modules\Events\Interfaces\Http\Request\EventsRequest;
use Modules\Events\Interfaces\Http\Resources\EventCollection;
use Spiral\Cqrs\QueryBusInterface;
use Spiral\Router\Annotation\Route;

class ListAction
final class ListAction
{
#[Route(route: 'events', name: 'events.list', methods: 'GET', group: 'api')]
public function __invoke(EventsRequest $request, QueryBusInterface $bus): EventCollection
{
return new EventCollection(
$bus->ask(
new FindEvents(type: $request->type)
)
new FindEvents(type: $request->type),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Application\Commands\FindEventByUuid;
use App\Application\Domain\ValueObjects\Uuid;
use App\Application\Exception\EntityNotFoundException;
use Modules\Events\Interfaces\Http\Resources\EventResource;
use Spiral\Cqrs\QueryBusInterface;
use Spiral\Http\Exception\ClientException\NotFoundException;
use Spiral\Router\Annotation\Route;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Modules\Events\Interfaces\Http\Request;

use Spiral\Filters\Attribute\Input\Post;
use Spiral\Filters\Attribute\Input\Data;
use Spiral\Filters\Model\Filter;
use Spiral\Filters\Model\FilterDefinitionInterface;
use Spiral\Filters\Model\HasFilterDefinition;
use Spiral\Validator\FilterDefinition;

final class ClearEventsRequest extends Filter implements HasFilterDefinition
{
#[Post]
#[Data]
public ?string $type = null;

public function filterDefinition(): FilterDefinitionInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Interfaces\Http\Controllers;
namespace Modules\Events\Interfaces\Http\Resources;

use App\Application\HTTP\Response\ResourceCollection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

declare(strict_types=1);

namespace Modules\Events\Interfaces\Http\Controllers;
namespace Modules\Events\Interfaces\Http\Resources;

use App\Application\HTTP\Response\JsonResource;
use Modules\Events\Domain\Event;
use Psr\Http\Message\ServerRequestInterface;

/**
* @property-read Event $data
Expand All @@ -18,13 +17,13 @@ public function __construct(Event $data)
parent::__construct($data);
}

protected function mapData(ServerRequestInterface $request): array|\JsonSerializable
protected function mapData(): array|\JsonSerializable
{
return [
'uuid' => (string)$this->data->getUuid(),
'type' => $this->data->getType(),
'payload' => $this->data->getPayload(),
'timestamp' => $this->data->getDate()->getTimestamp(),
'timestamp' => $this->data->getTimestamp(),
'project_id' => $this->data->getProjectId(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Application\Queries;
namespace Modules\Events\Interfaces\Queries;

use App\Application\Commands\CountEvents;
use Modules\Events\Domain\EventRepositoryInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Modules\Events\Application\Queries;
namespace Modules\Events\Interfaces\Queries;

use App\Application\Commands\AskEvents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Application\Queries;
namespace Modules\Events\Interfaces\Queries;

use App\Application\Commands\FindEventByUuid;
use App\Application\Exception\EntityNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Modules\Events\Application\Queries;
namespace Modules\Events\Interfaces\Queries;

use App\Application\Commands\FindEvents;
use Modules\Events\Domain\EventRepositoryInterface;
Expand Down
Loading