Skip to content

Commit

Permalink
[TASK] Some minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Atomschinken committed Aug 16, 2024
1 parent 59eca5f commit b24d082
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 34 deletions.
4 changes: 1 addition & 3 deletions Classes/Command/ProcessQueueCommand.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Command;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception;
use Sitegeist\ImageJack\Runner\TemplateRunner;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
2 changes: 1 addition & 1 deletion Classes/EventListener/MimeTypeCacheParams.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\EventListener;

Expand Down
3 changes: 2 additions & 1 deletion Classes/Processor/ImageJackProcessor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Processor;

Expand All @@ -18,6 +18,7 @@ public function processTask(TaskInterface $task): void
parent::processTask($task);
$processedFile = $task->getTargetFile();

/** @var TemplateRunner $templateRunner */
$templateRunner = GeneralUtility::makeInstance(TemplateRunner::class, $processedFile);
$templateRunner->run();

Expand Down
4 changes: 2 additions & 2 deletions Classes/Runner/TemplateRunner.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Runner;

use Sitegeist\ImageJack\Utility\LoggerUtility;
use Psr\Log\LogLevel;
use Sitegeist\ImageJack\Utility\LoggerUtility;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down
2 changes: 1 addition & 1 deletion Classes/Templates/AbstractTemplate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

Expand Down
15 changes: 7 additions & 8 deletions Classes/Templates/AvifTemplate.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
use Psr\Log\LogLevel;
use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Utility\CommandUtility;
Expand All @@ -15,7 +15,7 @@ class AvifTemplate extends AbstractTemplate implements TemplateInterface, Conver
{
public function isAvailable(): bool
{
return (in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive());
return in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive();
}

public function getSupportedMimeTypes(): array
Expand Down Expand Up @@ -74,7 +74,7 @@ public function processFile(): void
try {
$this->storage->addFile(
$targetFile,
$this->image->getParentFolder(), /* @phpstan-ignore-line */
$this->image->getParentFolder(), // @phpstan-ignore-line
$this->image->getName() . '.avif',
DuplicationBehavior::REPLACE
);
Expand Down Expand Up @@ -113,20 +113,19 @@ protected function convertImageUsingGd(string $quality, string $targetFile): boo
/** @var Typo3Version $version */
$version = GeneralUtility::makeInstance(Typo3Version::class);
if ($version->getMajorVersion() == 13) {
$graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);/* @phpstan-ignore-line */
$graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);// @phpstan-ignore-line
} else {
$graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class);
}
$image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);/* @phpstan-ignore-line */
$image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);// @phpstan-ignore-line
// Convert CMYK to RGB
if (!imageistruecolor($image)) {
imagepalettetotruecolor($image);
}

return imageavif($image, $targetFile, (int)$quality);
} else {
$this->logger->writeLog('Avif is not supported by your GD version', LogLevel::ERROR);
}
$this->logger->writeLog('Avif is not supported by your GD version', LogLevel::ERROR);

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Templates/ConverterInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

Expand Down
6 changes: 3 additions & 3 deletions Classes/Templates/JpegTemplate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

Expand All @@ -11,7 +11,7 @@ class JpegTemplate extends AbstractTemplate implements TemplateInterface
{
public function isAvailable(): bool
{
return (in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive());
return in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive();
}

public function getSupportedMimeTypes(): array
Expand Down Expand Up @@ -43,7 +43,7 @@ public function processFile(): void
try {
$this->storage->addFile(
$this->imagePath,
$this->image->getParentFolder(), /* @phpstan-ignore-line */
$this->image->getParentFolder(), // @phpstan-ignore-line
$this->image->getName(),
DuplicationBehavior::REPLACE
);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Templates/PngTemplate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

Expand Down Expand Up @@ -43,7 +43,7 @@ public function processFile(): void
try {
$this->storage->addFile(
$this->imagePath,
$this->image->getParentFolder(), /* @phpstan-ignore-line */
$this->image->getParentFolder(), // @phpstan-ignore-line
$this->image->getName(),
DuplicationBehavior::REPLACE
);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Templates/TemplateInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

Expand Down
15 changes: 7 additions & 8 deletions Classes/Templates/WebpTemplate.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Templates;

use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
use Psr\Log\LogLevel;
use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Utility\CommandUtility;
Expand All @@ -15,7 +15,7 @@ class WebpTemplate extends AbstractTemplate implements TemplateInterface, Conver
{
public function isAvailable(): bool
{
return (in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive());
return in_array($this->image->getMimeType(), $this->getSupportedMimeTypes()) && $this->isActive();
}

public function getSupportedMimeTypes(): array
Expand Down Expand Up @@ -74,7 +74,7 @@ public function processFile(): void
try {
$this->storage->addFile(
$targetFile,
$this->image->getParentFolder(), /* @phpstan-ignore-line */
$this->image->getParentFolder(), // @phpstan-ignore-line
$this->image->getName() . '.webp',
DuplicationBehavior::REPLACE
);
Expand Down Expand Up @@ -112,20 +112,19 @@ protected function convertImageUsingGd(string $quality, string $targetFile): boo
if (function_exists('imagewebp') && defined('IMG_WEBP') && (imagetypes() & IMG_WEBP) === IMG_WEBP) {
$version = GeneralUtility::makeInstance(Typo3Version::class);
if ($version->getMajorVersion() == 13) {
$graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);/* @phpstan-ignore-line */
$graphicalFunctionsObject = GeneralUtility::makeInstance(GifBuilder::class);// @phpstan-ignore-line
} else {
$graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class);
}
$image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);/* @phpstan-ignore-line */
$image = $graphicalFunctionsObject->imageCreateFromFile($this->imagePath);// @phpstan-ignore-line
// Convert CMYK to RGB
if (!imageistruecolor($image)) {
imagepalettetotruecolor($image);
}

return imagewebp($image, $targetFile, (int)$quality);
} else {
$this->logger->writeLog('Webp is not supported by your GD version', LogLevel::ERROR);
}
$this->logger->writeLog('Webp is not supported by your GD version', LogLevel::ERROR);

return false;
}
Expand Down
3 changes: 1 addition & 2 deletions Classes/Utility/LoggerUtility.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace Sitegeist\ImageJack\Utility;

Expand Down Expand Up @@ -59,7 +59,6 @@ public function __construct($logLevel = 'info')
*
* @param string $message
* @param string $level
* @return void
*/
public function writeLog(string $message, string $level): void
{
Expand Down
2 changes: 1 addition & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use Psr\Log\LogLevel;
use Sitegeist\ImageJack\Hook\TsfeHook;
use Sitegeist\ImageJack\Templates\AvifTemplate;
use Sitegeist\ImageJack\Templates\JpegTemplate;
use Sitegeist\ImageJack\Templates\PngTemplate;
use Sitegeist\ImageJack\Templates\WebpTemplate;
use Sitegeist\ImageJack\Templates\AvifTemplate;
use Sitegeist\ImageJack\Xclass\AmazonS3Driver;
use Sitegeist\ImageJack\Xclass\LocalDriver;
use TYPO3\CMS\Core\Information\Typo3Version;
Expand Down

0 comments on commit b24d082

Please sign in to comment.