Skip to content

Commit

Permalink
Merge pull request #60 from tienvx/validate-path
Browse files Browse the repository at this point in the history
Validate path
  • Loading branch information
tienvx committed Sep 16, 2018
2 parents 21b07d4 + 1785743 commit 39b4a7e
Show file tree
Hide file tree
Showing 40 changed files with 198 additions and 92 deletions.
3 changes: 2 additions & 1 deletion src/Command/HandlePathReducerMessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\Command;

use Exception;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -31,7 +32,7 @@ protected function configure()
/**
* @param InputInterface $input
* @param OutputInterface $output
* @throws \Exception
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ReduceStepsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\Command;

use Exception;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -34,7 +35,7 @@ protected function configure()
/**
* @param InputInterface $input
* @param OutputInterface $output
* @throws \Exception
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ReportBugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\Command;

use Exception;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -35,7 +36,7 @@ protected function configure()
/**
* @param InputInterface $input
* @param OutputInterface $output
* @throws \Exception
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/Compiler/GeneratorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler;

use Exception;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Expand All @@ -21,7 +22,7 @@ public function __construct(string $generatorService = 'mbt.generator_manager',

/**
* @param ContainerBuilder $container
* @throws \Exception
* @throws Exception
*/
public function process(ContainerBuilder $container)
{
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/Compiler/PathReducerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler;

use Exception;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Expand All @@ -21,7 +22,7 @@ public function __construct(string $pathReducerService = 'mbt.path_reducer_manag

/**
* @param ContainerBuilder $container
* @throws \Exception
* @throws Exception
*/
public function process(ContainerBuilder $container)
{
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/Compiler/ReporterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler;

use Exception;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Expand All @@ -21,7 +22,7 @@ public function __construct(string $reporterService = 'mbt.reporter_manager', st

/**
* @param ContainerBuilder $container
* @throws \Exception
* @throws Exception
*/
public function process(ContainerBuilder $container)
{
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/Compiler/SecurityTokenPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler;

use Exception;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -21,7 +22,7 @@ public function __construct(string $tokenStorageService = 'security.token_storag

/**
* @param ContainerBuilder $container
* @throws \Exception
* @throws Exception
*/
public function process(ContainerBuilder $container)
{
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/Compiler/TaggedServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\DependencyInjection\Compiler;

use Exception;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use InvalidArgumentException;
Expand All @@ -12,7 +13,7 @@ trait TaggedServiceTrait
* @param string $tagName
* @param ContainerBuilder $container
* @return array
* @throws \Exception
* @throws Exception
*/
private function findTaggedServices(string $tagName, ContainerBuilder $container)
{
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/TienvxMbtExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\DependencyInjection;

use Exception;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Monolog\Logger;
Expand Down Expand Up @@ -36,7 +37,7 @@ class TienvxMbtExtension extends Extension
{
/**
* {@inheritdoc}
* @throws \Exception
* @throws Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Bug.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Bug
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
* @MbtAssert\Path
*/
private $path;

Expand Down
6 changes: 4 additions & 2 deletions src/Generator/GeneratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tienvx\Bundle\MbtBundle\Generator;

use Exception;

class GeneratorManager
{
/**
Expand Down Expand Up @@ -30,15 +32,15 @@ public function getGenerators(): array
* @param $name
* @return GeneratorInterface
*
* @throws \Exception
* @throws Exception
*/
public function getGenerator($name): GeneratorInterface
{
if (isset($this->generators[$name])) {
return $this->generators[$name];
}

throw new \Exception(sprintf('Generator %s does not exist.', $name));
throw new Exception(sprintf('Generator %s does not exist.', $name));
}

/**
Expand Down
52 changes: 34 additions & 18 deletions src/Graph/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\Graph;

use Exception;
use Iterator;
use Serializable;

Expand All @@ -27,8 +28,18 @@ class Path implements Serializable, Iterator
*/
protected $position;

/**
* Path constructor.
* @param array $transitions
* @param array $data
* @param array $places
* @throws Exception
*/
public function __construct(array $transitions = [], array $data = [], array $places = [])
{
if (count($transitions) !== count($data) || count($transitions) !== count($places)) {
throw new Exception('Invalid transitions, data or places for path');
}
$this->transitions = $transitions;
$this->data = $data;
$this->places = $places;
Expand All @@ -42,16 +53,26 @@ public function add(?string $transition, ?array $data, array $places)
$this->places[] = $places;
}

public function countTransitions()
public function countTransitions(): int
{
return count(array_filter($this->transitions));
}

public function countPlaces()
public function countPlaces(): int
{
return count($this->places);
}

public function countUniqueTransitions(): int
{
return count(array_unique(array_filter($this->transitions)));
}

public function countUniquePlaces(): int
{
return count(array_unique(call_user_func_array('array_merge', $this->places)));
}

public function getTransitionAt(int $index): ?string
{
return $this->transitions[$index];
Expand All @@ -72,29 +93,24 @@ public function setDataAt(int $index, array $data)
$this->data[$index] = $data;
}

public function getAllTransitions(): array
{
return $this->transitions;
}

public function getAllData(): array
{
return $this->data;
}

public function getAllPlaces(): array
{
return $this->places;
}

public function serialize()
{
return serialize([$this->transitions, $this->data, $this->places]);
}

/**
* @param string $serialized
* @throws Exception
*/
public function unserialize($serialized)
{
list($this->transitions, $this->data, $this->places) = unserialize($serialized);
list($transitions, $data, $places) = unserialize($serialized);
if (count($transitions) !== count($data) || count($transitions) !== count($places)) {
throw new Exception('Invalid transitions, data or places for path');
}
$this->transitions = $transitions;
$this->data = $data;
$this->places = $places;
}

public function current()
Expand Down
3 changes: 2 additions & 1 deletion src/Helper/PathRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\Helper;

use Exception;
use Symfony\Component\Workflow\Workflow;
use Tienvx\Bundle\MbtBundle\Graph\Path;
use Tienvx\Bundle\MbtBundle\Subject\Subject;
Expand All @@ -12,7 +13,7 @@ class PathRunner
* @param Path $path
* @param Workflow $workflow
* @param Subject $subject
* @throws \Exception
* @throws Exception
*/
public static function run(Path $path, Workflow $workflow, Subject $subject)
{
Expand Down
3 changes: 2 additions & 1 deletion src/MessageHandler/BugMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\MessageHandler;

use Exception;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Process\Process;
Expand All @@ -18,7 +19,7 @@ public function __construct(ParameterBagInterface $params)

/**
* @param BugMessage $bugMessage
* @throws \Exception
* @throws Exception
*/
public function __invoke(BugMessage $bugMessage)
{
Expand Down
3 changes: 2 additions & 1 deletion src/MessageHandler/QueuedLoopMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\MessageHandler;

use Exception;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Process\Process;
Expand All @@ -19,7 +20,7 @@ public function __construct(ParameterBagInterface $params)

/**
* @param QueuedLoopMessage $queuedLoopMessage
* @throws \Exception
* @throws Exception
*/
public function __invoke(QueuedLoopMessage $queuedLoopMessage)
{
Expand Down
3 changes: 2 additions & 1 deletion src/MessageHandler/TaskMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\MessageHandler;

use Exception;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Process\Process;
Expand All @@ -18,7 +19,7 @@ public function __construct(ParameterBagInterface $params)

/**
* @param TaskMessage $taskMessage
* @throws \Exception
* @throws Exception
*/
public function __invoke(TaskMessage $taskMessage)
{
Expand Down
3 changes: 2 additions & 1 deletion src/PathReducer/AbstractPathReducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tienvx\Bundle\MbtBundle\PathReducer;

use Exception;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Workflow\Registry;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected function finish(int $bugId)
/**
* @param Bug $bug
* @param Path $path
* @throws \Exception
* @throws Exception
*/
protected function updatePath(Bug $bug, Path $path)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PathReducer/BinaryPathReducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BinaryPathReducer extends AbstractPathReducer
{
/**
* @param Bug $bug
* @throws \Exception
* @throws Exception
*/
public function reduce(Bug $bug)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PathReducer/GreedyPathReducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GreedyPathReducer extends AbstractPathReducer
{
/**
* @param Bug $bug
* @throws \Exception
* @throws Exception
*/
public function reduce(Bug $bug)
{
Expand Down
Loading

0 comments on commit 39b4a7e

Please sign in to comment.