Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Implement t3n-Codestyle and add pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Kleine-Börger committed Jan 16, 2019
1 parent 002677d commit 55db1e5
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 257 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: php
php:
- 7.2

install:
- composer selfupdate
- composer --ignore-platform-reqs install

script:
- bin/phpcs
24 changes: 14 additions & 10 deletions Classes/Command/AppCommandController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Yeebase\Readiness\Command;

/**
Expand Down Expand Up @@ -28,6 +31,7 @@ class AppCommandController extends CommandController
{
/**
* @Flow\Inject
*
* @var SystemLoggerInterface
*/
protected $systemLogger;
Expand All @@ -38,13 +42,13 @@ class AppCommandController extends CommandController
protected function runReadyTasks(): Result
{
$taskRunner = new ReadyTaskRunner();
$taskRunner->onBeforeTask(function (TaskInterface $task) {
$taskRunner->onBeforeTask(function (TaskInterface $task): void {
$this->output('Executing %s... ', [$task->getName()]);
});
$taskRunner->onTaskResult(function (TaskInterface $task, Result $result) {
$taskRunner->onTaskResult(function (TaskInterface $task, Result $result): void {
if ($result->hasErrors()) {
$this->outputFormatted('<error>%s</error>', [$task->getErrorLabel()]);
} else if ($result->hasNotices()) {
} elseif ($result->hasNotices()) {
$this->outputFormatted('<comment>%s</comment>', [$task->getNoticeLabel()]);
} else {
$this->outputFormatted('<success>%s</success>', [$task->getSuccessLabel()]);
Expand All @@ -53,7 +57,7 @@ protected function runReadyTasks(): Result

try {
return $taskRunner->run();
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
$this->output->output('<error>%s</error>', [$exception->getMessage()]);
$this->systemLogger->logException($exception);
$result = new Result();
Expand All @@ -69,13 +73,13 @@ protected function runTests(): Result
{
$testRunner = new TestRunner();

$testRunner->onBeforeTest(function (TestInterface $test) {
$testRunner->onBeforeTest(function (TestInterface $test): void {
$this->output->output('Testing %s... ', [$test->getName()]);
});
$testRunner->onTestResult(function (TestInterface $test, Result $result) {
$testRunner->onTestResult(function (TestInterface $test, Result $result): void {
if ($result->hasErrors()) {
$this->output->outputLine('<error>%s</error>', [$test->getErrorLabel()]);
} else if ($result->hasNotices()) {
} elseif ($result->hasNotices()) {
$this->output->outputLine('<commment>%s</commment>', [$test->getNoticeLabel()]);
} else {
$this->output->outputLine('<info>%s</info>', [$test->getSuccessLabel()]);
Expand All @@ -88,21 +92,21 @@ protected function runTests(): Result
/**
* Checks the readiness of the application
*/
public function isReadyCommand()
public function isReadyCommand(): void
{
$this->outputLine();
$this->outputLine('<info>Running tests...</info>');
$this->outputLine();
$testResult = $this->runTests();
$this->outputLine();
if (!$testResult->hasErrors()) {
if (! $testResult->hasErrors()) {
$this->outputLine();
$this->outputLine('<info>All checks passed, executing ready tasks...</info>');
$this->outputLine();
$readyResult = $this->runReadyTasks();
$this->outputLine();

if (!$readyResult->hasErrors()) {
if (! $readyResult->hasErrors()) {
$this->outputLine('<success>Application is ready</success>');
$this->outputLine();
$this->outputLine();
Expand Down
26 changes: 8 additions & 18 deletions Classes/Eel/Helper/ChainHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Yeebase\Readiness\Eel\Helper;

/**
Expand All @@ -11,56 +14,43 @@
* source code.
*/

use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Error\Messages\Error;
use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
use Yeebase\Readiness\Service\EelRuntime;

class ChainHelper implements ProtectedContextAwareInterface
{

/**
* @Flow\Inject
*
* @var EelRuntime
*/
protected $runtime;

/**
* @return bool
*/
public function isValid(): bool
{
$result = $this->runtime->getChainResult();
return !$result->hasErrors();
return ! $result->hasErrors();
}

/**
* @return bool
*/
public function isInvalid(): bool
{
$result = $this->runtime->getChainResult();
return $result->hasErrors();
}

/**
* @return string
*/
public function getCombinedErrorMessages(): string
{
$result = $this->runtime->getChainResult();
$messages = array_map(function (Error $error) {
$messages = array_map(static function (Error $error) {
return $error->getMessage();
}, $result->getErrors());

return implode(PHP_EOL, $messages);
}

/**
* @param string $methodName
* @return boolean
*/
public function allowsCallOfMethod($methodName)
public function allowsCallOfMethod(string $methodName): bool
{
return $this->runtime->isTaskContext();
}
Expand Down
48 changes: 14 additions & 34 deletions Classes/Eel/Helper/LockHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Yeebase\Readiness\Eel\Helper;

/**
Expand All @@ -21,12 +24,14 @@ class LockHelper implements ProtectedContextAwareInterface
{
/**
* @Flow\InjectConfiguration("lockPrefix")
*
* @var string
*/
protected $lockPrefix;

/**
* @Flow\InjectConfiguration("defaultCacheName")
*
* @var string
*/
protected $defaultCacheName;
Expand All @@ -38,28 +43,23 @@ class LockHelper implements ProtectedContextAwareInterface

/**
* @Flow\Inject
*
* @var CacheManager
*/
protected $cacheManager;

/**
* @Flow\Inject
*
* @var EelRuntime
*/
protected $runtime;

/**
* @param string $name
* @return string
*/
protected function getEntryIdentifier(string $name): string
{
return (!empty($this->lockPrefix) ? $this->lockPrefix . '_' : '') . $name;
return (! empty($this->lockPrefix) ? $this->lockPrefix . '_' : '') . $name;
}

/**
* @return FrontendInterface
*/
protected function getCache(): FrontendInterface
{
try {
Expand All @@ -72,7 +72,6 @@ protected function getCache(): FrontendInterface
}

/**
* @param string $cacheName
* @return $this
*/
public function withCache(string $cacheName)
Expand All @@ -81,46 +80,27 @@ public function withCache(string $cacheName)
return $this;
}

/**
* @param string $lockName
* @param string $value
*/
public function set(string $lockName, string $value = '1')
public function set(string $lockName, string $value = '1'): void
{
$this->getCache()->set($this->getEntryIdentifier($lockName), $value, [], 0);
}

/**
* @param string $lockName
*/
public function unset(string $lockName)
public function unset(string $lockName): void
{
$this->getCache()->remove($this->getEntryIdentifier($lockName));
}

/**
* @param string $lockName
* @return bool
*/
public function isSet(string $lockName)
public function isSet(string $lockName): bool
{
return $this->getCache()->has($this->getEntryIdentifier($lockName));
}

/**
* @param string $lockName
* @return bool
*/
public function isUnset(string $lockName)
public function isUnset(string $lockName): bool
{
return !$this->isSet($lockName);
return ! $this->isSet($lockName);
}

/**
* @param string $methodName
* @return boolean
*/
public function allowsCallOfMethod($methodName)
public function allowsCallOfMethod(string $methodName): bool
{
return substr($methodName, 0, 2) === 'is' || $this->runtime->isTaskContext();
}
Expand Down
Loading

0 comments on commit 55db1e5

Please sign in to comment.