Skip to content

Commit

Permalink
Merge pull request #638 from tienvx/log-new-bug
Browse files Browse the repository at this point in the history
Log new bug
  • Loading branch information
tienvx committed Jul 26, 2022
2 parents cbe7a79 + a04a649 commit 91eb056
Show file tree
Hide file tree
Showing 87 changed files with 459 additions and 401 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ vendor/bin/phpunit
## Validate code with coding standards

```shell
phpcs --standard=PSR12 src tests
phpcs --standard=PSR12 src tests config
php-cs-fixer fix --diff --dry-run
phpstan analyse src tests
phpstan analyse src tests config
```

## Built With
Expand Down
5 changes: 1 addition & 4 deletions src/EventListener/EntitySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@

class EntitySubscriber implements EventSubscriber
{
protected MessageBusInterface $messageBus;

protected string $reducer;

public function __construct(MessageBusInterface $messageBus)
public function __construct(protected MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}

public function postPersist(LifecycleEventArgs $args): void
Expand Down
17 changes: 4 additions & 13 deletions src/Generator/RandomGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,12 @@ class RandomGenerator extends AbstractGenerator
public const MAX_TRANSITION_COVERAGE = 100;
public const MAX_PLACE_COVERAGE = 100;

protected PetrinetHelperInterface $petrinetHelper;
protected MarkingHelperInterface $markingHelper;
protected ModelHelperInterface $modelHelper;
protected GuardedTransitionServiceInterface $transitionService;

public function __construct(
PetrinetHelperInterface $petrinetHelper,
MarkingHelperInterface $markingHelper,
ModelHelperInterface $modelHelper,
GuardedTransitionServiceInterface $transitionService
protected PetrinetHelperInterface $petrinetHelper,
protected MarkingHelperInterface $markingHelper,
protected ModelHelperInterface $modelHelper,
protected GuardedTransitionServiceInterface $transitionService
) {
$this->petrinetHelper = $petrinetHelper;
$this->markingHelper = $markingHelper;
$this->modelHelper = $modelHelper;
$this->transitionService = $transitionService;
}

public static function getName(): string
Expand Down
28 changes: 28 additions & 0 deletions src/Message/CreateBugMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tienvx\Bundle\MbtBundle\Message;

class CreateBugMessage implements MessageInterface
{
public function __construct(
protected int $taskId,
protected array $steps,
protected string $message
) {
}

public function getTaskId(): int
{
return $this->taskId;
}

public function getSteps(): array
{
return $this->steps;
}

public function getMessage(): string
{
return $this->message;
}
}
5 changes: 1 addition & 4 deletions src/Message/RecordVideoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

class RecordVideoMessage implements MessageInterface
{
protected int $bugId;

public function __construct(int $bugId)
public function __construct(protected int $bugId)
{
$this->bugId = $bugId;
}

public function getBugId(): int
Expand Down
5 changes: 1 addition & 4 deletions src/Message/ReduceBugMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

class ReduceBugMessage implements MessageInterface
{
protected int $id;

public function __construct(int $id)
public function __construct(protected int $id)
{
$this->id = $id;
}

public function getId(): int
Expand Down
17 changes: 6 additions & 11 deletions src/Message/ReduceStepsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

class ReduceStepsMessage implements MessageInterface
{
protected int $bugId;
protected int $length;
protected int $from;
protected int $to;

public function __construct(int $bugId, int $length, int $from, int $to)
{
$this->bugId = $bugId;
$this->length = $length;
$this->from = $from;
$this->to = $to;
public function __construct(
protected int $bugId,
protected int $length,
protected int $from,
protected int $to
) {
}

public function getBugId(): int
Expand Down
5 changes: 1 addition & 4 deletions src/Message/ReportBugMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

class ReportBugMessage implements MessageInterface
{
protected int $bugId;

public function __construct(int $bugId)
public function __construct(protected int $bugId)
{
$this->bugId = $bugId;
}

public function getBugId(): int
Expand Down
5 changes: 1 addition & 4 deletions src/Message/RunTaskMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

class RunTaskMessage implements MessageInterface
{
protected int $id;

public function __construct(int $id)
public function __construct(protected int $id)
{
$this->id = $id;
}

public function getId(): int
Expand Down
45 changes: 45 additions & 0 deletions src/MessageHandler/CreateBugMessageHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Tienvx\Bundle\MbtBundle\MessageHandler;

use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Tienvx\Bundle\MbtBundle\Entity\Bug;
use Tienvx\Bundle\MbtBundle\Exception\UnexpectedValueException;
use Tienvx\Bundle\MbtBundle\Message\CreateBugMessage;
use Tienvx\Bundle\MbtBundle\Model\BugInterface;
use Tienvx\Bundle\MbtBundle\Model\TaskInterface;
use Tienvx\Bundle\MbtBundle\Repository\TaskRepositoryInterface;
use Tienvx\Bundle\MbtBundle\Service\ConfigInterface;

class CreateBugMessageHandler implements MessageHandlerInterface
{
public function __construct(
protected ConfigInterface $config,
protected TaskRepositoryInterface $taskRepository
) {
}

public function __invoke(CreateBugMessage $message): void
{
$task = $this->taskRepository->find($message->getTaskId());

if (!$task instanceof TaskInterface) {
throw new UnexpectedValueException(sprintf(
'Can not create bug for task %d: task not found',
$message->getTaskId()
));
}

$this->taskRepository->addBug($task, $this->createBug($message->getSteps(), $message->getMessage()));
}

public function createBug(array $steps, string $message): BugInterface
{
$bug = new Bug();
$bug->setTitle($this->config->getDefaultBugTitle());
$bug->setSteps($steps);
$bug->setMessage($message);

return $bug;
}
}
5 changes: 1 addition & 4 deletions src/MessageHandler/RecordVideoMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class RecordVideoMessageHandler implements MessageHandlerInterface
{
protected BugHelperInterface $bugHelper;

public function __construct(BugHelperInterface $bugHelper)
public function __construct(protected BugHelperInterface $bugHelper)
{
$this->bugHelper = $bugHelper;
}

public function __invoke(RecordVideoMessage $message): void
Expand Down
5 changes: 1 addition & 4 deletions src/MessageHandler/ReduceBugMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class ReduceBugMessageHandler implements MessageHandlerInterface
{
protected BugHelperInterface $bugHelper;

public function __construct(BugHelperInterface $bugHelper)
public function __construct(protected BugHelperInterface $bugHelper)
{
$this->bugHelper = $bugHelper;
}

public function __invoke(ReduceBugMessage $message): void
Expand Down
5 changes: 1 addition & 4 deletions src/MessageHandler/ReduceStepsMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class ReduceStepsMessageHandler implements MessageHandlerInterface
{
protected BugHelperInterface $bugHelper;

public function __construct(BugHelperInterface $bugHelper)
public function __construct(protected BugHelperInterface $bugHelper)
{
$this->bugHelper = $bugHelper;
}

public function __invoke(ReduceStepsMessage $message): void
Expand Down
5 changes: 1 addition & 4 deletions src/MessageHandler/ReportBugMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class ReportBugMessageHandler implements MessageHandlerInterface
{
protected BugHelperInterface $bugHelper;

public function __construct(BugHelperInterface $bugHelper)
public function __construct(protected BugHelperInterface $bugHelper)
{
$this->bugHelper = $bugHelper;
}

public function __invoke(ReportBugMessage $message): void
Expand Down
5 changes: 1 addition & 4 deletions src/MessageHandler/RunTaskMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class RunTaskMessageHandler implements MessageHandlerInterface
{
protected TaskHelperInterface $taskHelper;

public function __construct(TaskHelperInterface $taskHelper)
public function __construct(protected TaskHelperInterface $taskHelper)
{
$this->taskHelper = $taskHelper;
}

public function __invoke(RunTaskMessage $message): void
Expand Down
13 changes: 5 additions & 8 deletions src/Model/Bug/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

class Step implements StepInterface, NodeIdentifierInterface
{
protected ColorInterface $color;
protected array $places;
protected int $transition;

public function __serialize(): array
{
return [
Expand All @@ -28,11 +24,12 @@ public function __unserialize(array $data)
$this->transition = $data['transition'];
}

public function __construct(array $places, ColorInterface $color, int $transition)
{
public function __construct(
protected array $places,
protected ColorInterface $color,
protected int $transition
) {
$this->setPlaces($places);
$this->setColor($color);
$this->setTransition($transition);
}

public function __clone()
Expand Down
4 changes: 1 addition & 3 deletions src/Model/Values.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

class Values implements ValuesInterface
{
protected array $values = [];

public function __construct(array $values = [])
public function __construct(protected array $values = [])
{
$this->values = [];

Expand Down
11 changes: 4 additions & 7 deletions src/Plugin/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

class PluginManager implements PluginManagerInterface
{
protected ServiceLocator $locator;
protected array $plugins;

public function __construct(ServiceLocator $locator, array $plugins)
{
$this->locator = $locator;
$this->plugins = $plugins;
public function __construct(
protected ServiceLocator $locator,
protected array $plugins
) {
}

public function all(): array
Expand Down
5 changes: 1 addition & 4 deletions src/Reducer/DispatcherTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ abstract class DispatcherTemplate implements DispatcherInterface
{
protected const MIN_STEPS = 3;

protected MessageBusInterface $messageBus;

public function __construct(MessageBusInterface $messageBus)
public function __construct(protected MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}

public function dispatch(BugInterface $bug): int
Expand Down
26 changes: 13 additions & 13 deletions src/Reducer/HandlerTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,23 @@
use Symfony\Component\Messenger\MessageBusInterface;
use Throwable;
use Tienvx\Bundle\MbtBundle\Exception\StepsNotConnectedException;
use Tienvx\Bundle\MbtBundle\Message\CreateBugMessage;
use Tienvx\Bundle\MbtBundle\Message\ReduceBugMessage;
use Tienvx\Bundle\MbtBundle\Model\BugInterface;
use Tienvx\Bundle\MbtBundle\Repository\BugRepositoryInterface;
use Tienvx\Bundle\MbtBundle\Service\ConfigInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Builder\StepsBuilderInterface;
use Tienvx\Bundle\MbtBundle\Service\Step\Runner\BugStepsRunner;

abstract class HandlerTemplate implements HandlerInterface
{
protected BugRepositoryInterface $bugRepository;
protected MessageBusInterface $messageBus;
protected BugStepsRunner $stepsRunner;
protected StepsBuilderInterface $stepsBuilder;

public function __construct(
BugRepositoryInterface $bugRepository,
MessageBusInterface $messageBus,
BugStepsRunner $stepsRunner,
StepsBuilderInterface $stepsBuilder
protected BugRepositoryInterface $bugRepository,
protected MessageBusInterface $messageBus,
protected BugStepsRunner $stepsRunner,
protected StepsBuilderInterface $stepsBuilder,
protected ConfigInterface $config
) {
$this->bugRepository = $bugRepository;
$this->messageBus = $messageBus;
$this->stepsRunner = $stepsRunner;
$this->stepsBuilder = $stepsBuilder;
}

public function handle(BugInterface $bug, int $from, int $to): void
Expand All @@ -50,6 +44,12 @@ function (Throwable $throwable) use ($bug, $newSteps): void {
if ($throwable->getMessage() === $bug->getMessage()) {
$this->bugRepository->updateSteps($bug, $newSteps);
$this->messageBus->dispatch(new ReduceBugMessage($bug->getId()));
} elseif ($this->config->shouldCreateNewBugWhileReducing()) {
$this->messageBus->dispatch(new CreateBugMessage(
$bug->getTask()->getId(),
$newSteps,
$throwable->getMessage()
));
}
}
);
Expand Down
Loading

0 comments on commit 91eb056

Please sign in to comment.