Skip to content

Commit

Permalink
Rename text components
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-kozhevnikov committed Aug 27, 2023
1 parent c9f3c0c commit 587aba2
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 32 deletions.
10 changes: 5 additions & 5 deletions config/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
'options' => '-a',
'message' => [
'handlers' => [
// \Cross\Git\Message\Handlers\FirstUppercaseHandler::class,
// \Cross\Git\Message\Handlers\ProjectIssueHandler::class => [
// 'project' => \Cross\Git\Message\Receivers\ProjectNameReceiver::class,
// 'issue' => \Cross\Git\Message\Receivers\IssueNumberReceiver::class,
// ],
\Cross\Git\Text\Handlers\Cases\FirstUppercase::class,
\Cross\Git\Text\Handlers\Jira\Issue::class => [
'project' => \Cross\Git\Text\Extractors\Jira\ProjectFromBranch::class,
'issue' => \Cross\Git\Text\Extractors\Jira\IssueFromBranch::class,
],
],
],
],
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Cross\Commands\Attributes\Description;
use Cross\Commands\Attributes\Name;
use Cross\Commands\ShellCommand;
use Cross\Git\Message\Handlers\Manager;
use Cross\Git\Text\Handlers\Manager;
use Exception;

#[Name('git:commit')]
Expand Down Expand Up @@ -38,11 +38,11 @@ protected function message(): string
$manager->set($handlers);

try {
return $manager->handle($message);
$message = $manager->handle($message);
} catch (Exception $exception) {
$this->error($exception->getMessage());
}

return '';
return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Cross\Git\Message\Receivers;
namespace Cross\Git\Text\Extractors;

interface ReceiverInterface
interface ExtractorInterface
{
/**
* Receives something from something end returns it.
*/
public function receive(): ?string;
public function extract(): ?string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

declare(strict_types=1);

namespace Cross\Git\Message\Receivers;
namespace Cross\Git\Text\Extractors\Jira;

use Cross\Git\Helpers\Git;
use Cross\Git\Text\Extractors\ExtractorInterface;

class IssueNumberReceiver implements ReceiverInterface
class IssueFromBranch implements ExtractorInterface
{
/**
* @inheritDoc
*/
public function receive(): ?string
public function extract(): ?string
{
$branch = (new Git())->getCurrentBranch();

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

declare(strict_types=1);

namespace Cross\Git\Message\Receivers;
namespace Cross\Git\Text\Extractors\Jira;

use Cross\Git\Helpers\Git;
use Cross\Git\Text\Extractors\ExtractorInterface;

class ProjectNameReceiver implements ReceiverInterface
class ProjectFromBranch implements ExtractorInterface
{
/**
* @inheritDoc
*/
public function receive(): ?string
public function extract(): ?string
{
$branch = (new Git())->getCurrentBranch();

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

declare(strict_types=1);

namespace Cross\Git\Message\Handlers;
namespace Cross\Git\Text\Handlers\Cases;

class FirstUppercaseHandler implements HandlerInterface
use Cross\Git\Text\Handlers\HandlerInterface;

class FirstUppercase implements HandlerInterface
{
/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Cross\Git\Message\Handlers;
namespace Cross\Git\Text\Handlers;

interface HandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

declare(strict_types=1);

namespace Cross\Git\Message\Handlers;
namespace Cross\Git\Text\Handlers\Jira;

use Cross\Git\Message\Receivers\ReceiverInterface;
use Cross\Git\Text\Extractors\ExtractorInterface;
use Cross\Git\Text\Handlers\HandlerInterface;
use RuntimeException;

class ProjectIssueHandler implements HandlerInterface
class Issue implements HandlerInterface
{
/**
* Project name receiver.
* Project name extractor.
*/
protected ReceiverInterface $project;
protected ExtractorInterface $project;

/**
* Issue number receiver.
* Issue number extractor.
*/
protected ReceiverInterface $issue;
protected ExtractorInterface $issue;

/**
* Constructor.
*/
public function __construct(ReceiverInterface|string $project, ReceiverInterface|string $issue)
public function __construct(ExtractorInterface|string $project, ExtractorInterface|string $issue)
{
$this->project = is_string($project) ? new $project() : $project;
$this->issue = is_string($issue) ? new $issue() : $issue;
Expand All @@ -34,11 +35,11 @@ public function __construct(ReceiverInterface|string $project, ReceiverInterface
*/
public function handle(string $message): string
{
if (! $project = $this->project->receive()) {
if (! $project = $this->project->extract()) {
throw new RuntimeException('Project name is not received.');
}

if (! $issue = $this->issue->receive()) {
if (! $issue = $this->issue->extract()) {
throw new RuntimeException('Issue number is not received.');
}

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

declare(strict_types=1);

namespace Cross\Git\Message\Handlers;
namespace Cross\Git\Text\Handlers;

use InvalidArgumentException;

Expand Down Expand Up @@ -42,7 +42,7 @@ public function add(HandlerInterface|string $handler, array $args = []): void
$handler = new $handler(...$args);
}

if (! ($handler instanceof HandlerInterface)) {
if (! $handler instanceof HandlerInterface) {
throw new InvalidArgumentException('Handler does not implement the interface');
}

Expand Down

0 comments on commit 587aba2

Please sign in to comment.