Skip to content

add enable faces in messages config option #129

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
composer.phar
vendor/
bin/
.idea/
php-git-hooks.yml
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand All @@ -9,7 +10,6 @@ composer.lock
.guard_coverage
var/cache
var/logs
.php_cs.cache

###> friendsofphp/php-cs-fixer ###
.php_cs
Expand Down
2 changes: 2 additions & 0 deletions php-git-hooks.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pre-commit:
options: '<some options>'
composer: true
message:
enable-faces: true
right-message: 'HEY, GOOD JOB!!'
error-message: 'FIX YOUR CODE!!'
commit-msg:
Expand All @@ -48,5 +49,6 @@ pre-push:
enabled: true
message: 'WARNING!!, your code coverage is lower.'
message:
enable-faces: true
right-message: 'PUSH IT!!'
error-message: 'YOU CAN NOT PUSH CODE!!'
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ConfiguratorScript
{
/**
* @param Event $event
*
* @return mixed
*/
public static function buildConfig(Event $event)
{
Expand Down
18 changes: 16 additions & 2 deletions src/PhpGitHooks/Module/Composer/Contract/Command/ComposerTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ class ComposerTool implements CommandInterface
* @var string
*/
private $errorMessage;
/**
* @var bool
*/
private $enableFaces;

/**
* ComposerToolCommand constructor.
*
* @param array $files
* @param array $files
* @param string $errorMessage
* @param bool $enableFaces
*/
public function __construct(array $files, $errorMessage)
public function __construct(array $files, $errorMessage, $enableFaces)
{
$this->files = $files;
$this->errorMessage = $errorMessage;
$this->enableFaces = $enableFaces;
}

/**
Expand All @@ -35,6 +41,14 @@ public function getErrorMessage()
return $this->errorMessage;
}

/**
* @return bool
*/
public function isEnableFaces()
{
return $this->enableFaces;
}

/**
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ public function __construct(

/**
* @param CommandInterface|ComposerTool $command
*
* @throws ComposerFilesNotFoundException
*/
public function handle(CommandInterface $command)
{
$this->execute($command->getFiles(), $command->getErrorMessage());
$this->execute($command->getFiles(), $command->getErrorMessage(), $command->isEnableFaces());
}

/**
* @param array $files
* @param array $files
* @param string $errorMessage
* @param bool $enableFaces
*
* @throws ComposerFilesNotFoundException
*/
private function execute(array $files, $errorMessage)
private function execute(array $files, $errorMessage, $enableFaces)
{
$composerFilesResponse = $this->getComposerFilesResponse($files);

Expand All @@ -66,24 +69,26 @@ private function execute(array $files, $errorMessage)
$this->executeTool(
$composerFilesResponse->isJsonFile(),
$composerFilesResponse->isLockFile(),
$errorMessage
$errorMessage,
$enableFaces
);
$this->output->writeln($this->outputMessage->getSuccessfulMessage());
}
}

/**
* @param bool $jsonFile
* @param bool $lockFile
* @param bool $jsonFile
* @param bool $lockFile
* @param string $errorMessage
* @param bool $enableFaces
*
* @throws ComposerFilesNotFoundException *
*/
private function executeTool($jsonFile, $lockFile, $errorMessage)
private function executeTool($jsonFile, $lockFile, $errorMessage, $enableFaces)
{
if (true === $jsonFile && false === $lockFile) {
$this->output->writeln($this->outputMessage->getFailMessage());
$this->output->writeln(BadJobLogoResponse::paint($errorMessage));
$this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces));
throw new ComposerFilesNotFoundException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function setUp()

/**
* @test
* @throws ComposerFilesNotFoundException
*/
public function itShouldWorksFine()
{
Expand All @@ -49,12 +50,13 @@ public function itShouldWorksFine()
$this->shouldWriteLnOutput($output->getSuccessfulMessage());

$this->composerToolCommandHandler->handle(
new ComposerTool($files, $this->errorMessage)
new ComposerTool($files, $this->errorMessage, true)
);
}

/**
* @test
* @throws ComposerFilesNotFoundException
*/
public function itShouldThrowException()
{
Expand All @@ -69,15 +71,16 @@ public function itShouldThrowException()
ComposerFilesResponseStub::createInvalidData()
);
$this->shouldWriteLnOutput($output->getFailMessage());
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage, true));

$this->composerToolCommandHandler->handle(
new ComposerTool($files, $this->errorMessage)
new ComposerTool($files, $this->errorMessage, true)
);
}

/**
* @test
* @throws ComposerFilesNotFoundException
*/
public function itShouldNotExecuteComposerTool()
{
Expand All @@ -88,6 +91,6 @@ public function itShouldNotExecuteComposerTool()
ComposerFilesResponseStub::createNoData()
);

$this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage));
$this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class PreCommitResponse
* @var string
*/
private $errorMessage;
/**
* @var bool
*/
private $enableFaces;
/**
* @var bool
*/
Expand Down Expand Up @@ -56,23 +60,25 @@ class PreCommitResponse
/**
* PreCommitResponse constructor.
*
* @param bool $preCommit
* @param string $rightMessage
* @param string $errorMessage
* @param bool $composer
* @param bool $jsonLint
* @param bool $phpLint
* @param PhpMdResponse $phpMd
* @param PhpCsResponse $phpCs
* @param PhpCsFixerResponse $phpCsFixer
* @param PhpUnitResponse $phpUnit
* @param bool $preCommit
* @param string $rightMessage
* @param string $errorMessage
* @param bool $enableFaces
* @param bool $composer
* @param bool $jsonLint
* @param bool $phpLint
* @param PhpMdResponse $phpMd
* @param PhpCsResponse $phpCs
* @param PhpCsFixerResponse $phpCsFixer
* @param PhpUnitResponse $phpUnit
* @param PhpUnitStrictCoverageResponse $phpUnitStrictCoverage
* @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage
* @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage
*/
public function __construct(
$preCommit,
$rightMessage,
$errorMessage,
$enableFaces,
$composer,
$jsonLint,
$phpLint,
Expand All @@ -86,6 +92,7 @@ public function __construct(
$this->preCommit = $preCommit;
$this->rightMessage = $rightMessage;
$this->errorMessage = $errorMessage;
$this->enableFaces = $enableFaces;
$this->composer = $composer;
$this->jsonLint = $jsonLint;
$this->phpLint = $phpLint;
Expand Down Expand Up @@ -121,6 +128,14 @@ public function getErrorMessage()
return $this->errorMessage;
}

/**
* @return bool
*/
public function isEnableFaces()
{
return $this->enableFaces;
}

/**
* @return bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class PrePushResponse
* @var string
*/
private $errorMessage;
/**
* @var bool
*/
private $enableFaces;
/**
* @var PhpUnitGuardCoverageResponse
*/
Expand All @@ -32,17 +36,19 @@ class PrePushResponse
/**
* PrePushResponse constructor.
*
* @param bool $prePush
* @param string $rightMessage
* @param string $errorMessage
* @param PhpUnitResponse $phpUnit
* @param bool $prePush
* @param string $rightMessage
* @param string $errorMessage
* @param bool $enableFaces
* @param PhpUnitResponse $phpUnit
* @param PhpUnitStrictCoverageResponse $phpUnitStrictCoverage
* @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage
* @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage
*/
public function __construct(
$prePush,
$rightMessage,
$errorMessage,
$enableFaces,
PhpUnitResponse $phpUnit,
PhpUnitStrictCoverageResponse $phpUnitStrictCoverage,
PhpUnitGuardCoverageResponse $phpUnitGuardCoverage
Expand All @@ -52,6 +58,7 @@ public function __construct(
$this->prePush = $prePush;
$this->rightMessage = $rightMessage;
$this->errorMessage = $errorMessage;
$this->enableFaces = $enableFaces;
$this->phpUnitGuardCoverage = $phpUnitGuardCoverage;
}

Expand Down Expand Up @@ -95,6 +102,14 @@ public function getErrorMessage()
return $this->errorMessage;
}

/**
* @return string
*/
public function isEnableFaces()
{
return $this->enableFaces;
}

/**
* @return PhpUnitGuardCoverageResponse
*/
Expand Down
20 changes: 18 additions & 2 deletions src/PhpGitHooks/Module/Configuration/Domain/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ class Messages
*/
private $errorMessage;

/**
* @var Enabled
*/
private $enableFaces;

/**
* Messages constructor.
*
* @param Message $rightMessage
* @param Message $errorMessage
* @param Enabled $enableFaces
*/
public function __construct(Message $rightMessage, Message $errorMessage)
public function __construct(Message $rightMessage, Message $errorMessage, Enabled $enableFaces)
{
$this->rightMessage = $rightMessage;
$this->errorMessage = $errorMessage;
$this->enableFaces = $enableFaces;
}

/**
Expand All @@ -41,14 +48,23 @@ public function getErrorMessage()
return $this->errorMessage;
}

/**
* @return Enabled
*/
public function getEnableFaces()
{
return $this->enableFaces;
}

/**
* @return Messages
*/
public function disable()
{
return new self(
new Message(null),
new Message(null)
new Message(null),
new Enabled(true)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static function transform(PreCommit $preCommit, CommitMsg $commitMsg, Pre
],
],
'message' => [
'enable-faces' => $preCommit->getMessages()->getEnableFaces()->value(),
'right-message' => $preCommit->getMessages()->getRightMessage()->value(),
'error-message' => $preCommit->getMessages()->getErrorMessage()->value(),
],
Expand All @@ -115,6 +116,7 @@ public static function transform(PreCommit $preCommit, CommitMsg $commitMsg, Pre
],
],
'message' => [
'enable-faces' => $preCommit->getMessages()->getEnableFaces()->value(),
'right-message' => $prePush->getMessages()->getRightMessage()->value(),
'error-message' => $prePush->getMessages()->getErrorMessage()->value(),
],
Expand Down
Loading