Skip to content

Commit

Permalink
Fix rector messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Tepper committed Feb 28, 2024
1 parent 06a71fc commit 893fc52
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 104 deletions.
4 changes: 4 additions & 0 deletions Classes/Controller/BanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function banTagByNameAction(string $tagName): void
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR);
}
}

$this->redirect('index');
}

Expand Down Expand Up @@ -130,6 +131,7 @@ public function banByRegexAction(string $regex): void
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR);
}
}

$this->redirect('index');
}

Expand All @@ -139,6 +141,7 @@ private function isCriticalRegex(string $regex): bool
$this->addFlashMessage('Bitte geben Sie einen spezifischeren RegEx ein!', '', AbstractMessage::ERROR);
return true;
}

return false;
}

Expand All @@ -148,6 +151,7 @@ private function isValidTagName(string $tagName): bool
$this->addFlashMessage('Bitte geben Sie einen gültigen Tag-Namen ein! ', '', AbstractMessage::ERROR);
return false;
}

return true;
}
}
10 changes: 2 additions & 8 deletions Classes/Domain/Model/Tag/PageTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@

class PageTag implements TagInterface
{
/**
* @return string
*/
public function getIdentifier()
public function getIdentifier(): string
{
return 'typo3_page';
}

/**
* @return boolean
*/
public function isValid()
public function isValid(): bool
{
return true;
}
Expand Down
1 change: 1 addition & 0 deletions Classes/System/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function sendHeaderForTag(TagInterface $tag): void
if (!$tag->isValid()) {
throw new \RuntimeException('Tag is not valid', 1_435_047_447);
}

header(sprintf(self::HEADER_TAGS, $tag->getIdentifier()), false);
}

Expand Down
2 changes: 2 additions & 0 deletions Classes/System/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function wait(): array
if ($reason instanceof Exception) {
$reason = $reason->getMessage();
}

$phrases[] = [
'reason' => $reason,
'success' => false,
Expand All @@ -89,6 +90,7 @@ public function wait(): array
];
}
}

return $phrases;
}
}
18 changes: 9 additions & 9 deletions Classes/System/Varnish.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ public function __construct(Http $http, ExtensionConfiguration $extensionConfigu
public function shutdown(): array
{
$phrases = $this->http->wait();
if (is_array($phrases)) {
foreach ($phrases as $phrase) {
if ($phrase['success']) {
$this->logManager->getLogger(__CLASS__)
->info($phrase['reason']);
} else {
$this->logManager->getLogger(__CLASS__)
->alert($phrase['reason']);
}
foreach ($phrases as $phrase) {
if ($phrase['success']) {
$this->logManager->getLogger(self::class)
->info($phrase['reason']);
} else {
$this->logManager->getLogger(self::class)
->alert($phrase['reason']);
}
}

return $phrases;
}

Expand All @@ -73,6 +72,7 @@ public function banByTag(TagInterface $tag): self
if (!$tag->isValid()) {
throw new \RuntimeException('Tag is not valid', 1_435_159_558);
}

$this->request('BAN', ['X-Ban-Tags' => $tag->getIdentifier()], $this->extensionConfiguration->getBanTimeout());
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/TYPO3/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function isDebug(): bool
public function getHosts(): array
{
$hosts = explode(',', $this->get('hosts'));
array_walk($hosts, function (&$value): void {
array_walk($hosts, static function (&$value): void {
if (!str_contains($value, 'https://') && !str_contains($value, 'http://')) {
$value = 'http://' . $value;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/TYPO3/Hooks/BackendAjaxHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ protected function isAuthorizedBackendSession(): bool

protected function getBackendUser(): ?BackendUserAuthentication
{
return isset($GLOBALS['BE_USER']) ? $GLOBALS['BE_USER'] : null;
return $GLOBALS['BE_USER'] ?? null;
}
}
3 changes: 3 additions & 0 deletions Classes/TYPO3/Hooks/TceMainHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ private function extractPageIdFromParameters(array $parameters): int
) {
return (int) $parameters[self::UID];
}

if (isset($parameters[self::CACHE_CMD]) && is_numeric($parameters[self::CACHE_CMD])) {
return (int) $parameters[self::CACHE_CMD];
}

if (isset($parameters[self::UID_PAGE]) && is_numeric($parameters[self::UID_PAGE])) {
return (int) $parameters[self::UID_PAGE];
}

return 0;
}

Expand Down
20 changes: 10 additions & 10 deletions Tests/Unit/Domain/Model/Tag/PageIdTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@
*/
class PageIdTagTest extends UnitTestCase
{
public function testIsValidShouldFailWithNegativePageId()
public function testIsValidShouldFailWithNegativePageId(): void
{
$tag = new PageIdTag(-1);
self::assertFalse($tag->isValid());
$this->assertFalse($tag->isValid());
}

public function testIsValidShouldFailWithPageIdZero()
public function testIsValidShouldFailWithPageIdZero(): void
{
$tag = new PageIdTag(0);
self::assertFalse($tag->isValid());
$this->assertFalse($tag->isValid());
}

public function testIsValidShouldFailWithPageIdNotNumeric()
public function testIsValidShouldFailWithPageIdNotNumeric(): void
{
$tag = new PageIdTag('string');
self::assertFalse($tag->isValid());
$this->assertFalse($tag->isValid());
}

public function testIsValidWithInteger()
public function testIsValidWithInteger(): void
{
$tag = new PageIdTag(11);
self::assertTrue($tag->isValid());
$this->assertTrue($tag->isValid());
}

public function testGetIdentifier()
public function testGetIdentifier(): void
{
$tag = new PageIdTag(11);
self::assertSame('page_11', $tag->getIdentifier());
$this->assertSame('page_11', $tag->getIdentifier());
}
}
8 changes: 4 additions & 4 deletions Tests/Unit/Domain/Model/Tag/PageTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
*/
class PageTagTest extends UnitTestCase
{
public function testTagShouldBeValid()
public function testTagShouldBeValid(): void
{
$tag = new PageTag();
self::assertTrue($tag->isValid());
$this->assertTrue($tag->isValid());
}

public function testShouldGetIdentifier()
public function testShouldGetIdentifier(): void
{
$tag = new PageTag();
self::assertSame('typo3_page', $tag->getIdentifier());
$this->assertSame('typo3_page', $tag->getIdentifier());
}
}
12 changes: 6 additions & 6 deletions Tests/Unit/Domain/Model/Tag/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
*/
class TagTest extends UnitTestCase
{
public function testSsValidShouldFailWithEmptyIdentifier()
public function testSsValidShouldFailWithEmptyIdentifier(): void
{
$tag = new Tag('');
self::assertFalse($tag->isValid());
$this->assertFalse($tag->isValid());
}

public function testShouldGetIdentifier()
public function testShouldGetIdentifier(): void
{
$tag = new Tag('myTag');
self::assertSame('myTag', $tag->getIdentifier());
$this->assertSame('myTag', $tag->getIdentifier());
}

public function testShouldGetIsValidWithIdentifier()
public function testShouldGetIsValidWithIdentifier(): void
{
$tag = new Tag('myString');
self::assertTrue($tag->isValid());
$this->assertTrue($tag->isValid());
}
}
2 changes: 1 addition & 1 deletion Tests/Unit/System/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function setUp(): void
$this->header = new Header();
}

public function testShouldThrowRuntimeExceptionWithInvalidTag()
public function testShouldThrowRuntimeExceptionWithInvalidTag(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionCode(1_435_047_447);
Expand Down
9 changes: 5 additions & 4 deletions Tests/Unit/System/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;

/**
* @covers \Aoe\Varnish\System\Http
*/
class HttpTest extends UnitTestCase
{
/**
* @var Client|\PHPUnit\Framework\MockObject\MockObject
* @var Client
*/
private $client;
private MockObject $client;

private Http $http;

Expand All @@ -53,7 +54,7 @@ protected function setUp(): void
$this->http = new Http($this->client);
}

public function testRequestShouldCallClientCorrectly()
public function testRequestShouldCallClientCorrectly(): void
{
$method = 'BAN';
$url = 'domain.tld';
Expand All @@ -79,7 +80,7 @@ public function testRequestShouldCallClientCorrectly()
);
}

public function testRequestShouldCallClientWithDefaultParams()
public function testRequestShouldCallClientWithDefaultParams(): void
{
$method = 'BAN';
$url = 'domain.tld';
Expand Down
25 changes: 13 additions & 12 deletions Tests/Unit/System/VarnishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Aoe\Varnish\System\Varnish;
use Aoe\Varnish\TYPO3\Configuration\ExtensionConfiguration;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use RuntimeException;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogManager;
Expand All @@ -43,19 +44,19 @@ class VarnishTest extends UnitTestCase
private Varnish $varnish;

/**
* @var Http|\PHPUnit\Framework\MockObject\MockObject
* @var Http
*/
private $http;
private MockObject $http;

/**
* @var ExtensionConfiguration|\PHPUnit\Framework\MockObject\MockObject
* @var ExtensionConfiguration
*/
private $extensionConfiguration;
private MockObject $extensionConfiguration;

/**
* @var LogManager|\PHPUnit\Framework\MockObject\MockObject
* @var LogManager
*/
private $logManager;
private MockObject $logManager;

protected function setUp(): void
{
Expand Down Expand Up @@ -86,7 +87,7 @@ protected function setUp(): void
$this->varnish = new Varnish($this->http, $this->extensionConfiguration, $this->logManager);
}

public function testBanByTagShouldThrowExceptionOnInvalidTag()
public function testBanByTagShouldThrowExceptionOnInvalidTag(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionCode(1_435_159_558);
Expand All @@ -101,7 +102,7 @@ public function testBanByTagShouldThrowExceptionOnInvalidTag()
$this->varnish->banByTag($tag);
}

public function testBanByTagShouldCallHttpCorrectly()
public function testBanByTagShouldCallHttpCorrectly(): void
{
$this->http->expects(self::once())
->method('request')
Expand All @@ -111,7 +112,7 @@ public function testBanByTagShouldCallHttpCorrectly()
['X-Ban-Tags' => 'my_identifier'],
10
);
/** @var TagInterface|\PHPUnit\Framework\MockObject\MockObject $tag */
/** @var TagInterface|MockObject $tag */
$tag = $this->getMockBuilder(TagInterface::class)
->onlyMethods(['isValid', 'getIdentifier'])
->getMock();
Expand All @@ -124,15 +125,15 @@ public function testBanByTagShouldCallHttpCorrectly()
$this->varnish->banByTag($tag);
}

public function testBanAllShouldCallHttpCorrectly()
public function testBanAllShouldCallHttpCorrectly(): void
{
$this->http->expects(self::once())
->method('request')
->with('BAN', 'domain.tld', ['X-Ban-All' => '1'], 10);
$this->varnish->banAll();
}

public function testBanByRegexShouldCallHttpCorrectly()
public function testBanByRegexShouldCallHttpCorrectly(): void
{
$this->http
->expects(self::once())
Expand All @@ -141,7 +142,7 @@ public function testBanByRegexShouldCallHttpCorrectly()
$this->varnish->banByRegex('/*');
}

public function testShouldLogOnShutdown()
public function testShouldLogOnShutdown(): void
{
$this->http->expects(self::once())
->method('wait')
Expand Down
Loading

0 comments on commit 893fc52

Please sign in to comment.