Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-05-10 21:39:31 +02:00
parent e9493e52ec
commit f5d685dfd4
71 changed files with 619 additions and 531 deletions

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement;
use App\Services\ElementTypeNameGenerator;
@ -33,23 +35,18 @@ final class AbstractDBElementProvider implements PlaceholderProviderInterface
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
}
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof AbstractDBElement) {
if ($placeholder === '[[TYPE]]') {
if ('[[TYPE]]' === $placeholder) {
return $this->elementTypeNameGenerator->getLocalizedTypeLabel($label_target);
}
if ($placeholder === '[[ID]]') {
if ('[[ID]]' === $placeholder) {
return (string) ($label_target->getID() ?? 'unknown');
}
}
return null;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\UserSystem\User;
use IntlDateFormatter;
use Locale;
@ -28,11 +30,9 @@ use Symfony\Component\Security\Core\Security;
/**
* Provides Placeholders for infos about global infos like Installation name or datetimes.
* @package App\Services\LabelSystem\PlaceholderProviders
*/
final class GlobalProviders implements PlaceholderProviderInterface
{
private $partdb_title;
private $security;
@ -42,34 +42,32 @@ final class GlobalProviders implements PlaceholderProviderInterface
$this->security = $security;
}
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($placeholder === "[[INSTALL_NAME]]") {
if ('[[INSTALL_NAME]]' === $placeholder) {
return $this->partdb_title;
}
$user = $this->security->getUser();
if ($placeholder === "[[USERNAME]]") {
if ('[[USERNAME]]' === $placeholder) {
if ($user instanceof User) {
return $user->getName();
}
return 'anonymous';
}
if ($placeholder === "[[USERNAME_FULL]]") {
if ('[[USERNAME_FULL]]' === $placeholder) {
if ($user instanceof User) {
return $user->getFullName(true);
}
return 'anonymous';
}
$now = new \DateTime();
if ($placeholder === '[[DATETIME]]') {
if ('[[DATETIME]]' === $placeholder) {
$formatter = IntlDateFormatter::create(
Locale::getDefault(),
IntlDateFormatter::SHORT,
@ -80,7 +78,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
return $formatter->format($now);
}
if ($placeholder === '[[DATE]]') {
if ('[[DATE]]' === $placeholder) {
$formatter = IntlDateFormatter::create(
Locale::getDefault(),
IntlDateFormatter::SHORT,
@ -91,7 +89,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
return $formatter->format($now);
}
if ($placeholder === '[[TIME]]') {
if ('[[TIME]]' === $placeholder) {
$formatter = IntlDateFormatter::create(
Locale::getDefault(),
IntlDateFormatter::NONE,
@ -104,4 +102,4 @@ final class GlobalProviders implements PlaceholderProviderInterface
return null;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,21 +23,16 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\NamedElementInterface;
final class NamedElementProvider implements PlaceholderProviderInterface
{
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof NamedElementInterface && $placeholder === '[[NAME]]') {
if ($label_target instanceof NamedElementInterface && '[[NAME]]' === $placeholder) {
return $label_target->getName();
}
return null;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\PartLot;
use App\Services\AmountFormatter;
use App\Services\LabelSystem\LabelTextReplacer;
@ -41,20 +43,20 @@ final class PartLotProvider implements PlaceholderProviderInterface
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof PartLot) {
if ($placeholder === '[[LOT_ID]]') {
if ('[[LOT_ID]]' === $placeholder) {
return $label_target->getID() ?? 'unknown';
}
if ($placeholder === '[[LOT_NAME]]') {
if ('[[LOT_NAME]]' === $placeholder) {
return $label_target->getName();
}
if ($placeholder === '[[LOT_COMMENT]]') {
if ('[[LOT_COMMENT]]' === $placeholder) {
return $label_target->getComment();
}
if ($placeholder === '[[EXPIRATION_DATE]]') {
if ($label_target->getExpirationDate() === null) {
if ('[[EXPIRATION_DATE]]' === $placeholder) {
if (null === $label_target->getExpirationDate()) {
return '';
}
$formatter = IntlDateFormatter::create(
@ -67,25 +69,25 @@ final class PartLotProvider implements PlaceholderProviderInterface
return $formatter->format($label_target->getExpirationDate());
}
if ($placeholder === '[[AMOUNT]]') {
if ('[[AMOUNT]]' === $placeholder) {
if ($label_target->isInstockUnknown()) {
return '?';
}
return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit());
}
if ($placeholder === '[[LOCATION]]') {
if ('[[LOCATION]]' === $placeholder) {
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : '';
}
if ($placeholder === '[[LOCATION_FULL]]') {
if ('[[LOCATION_FULL]]' === $placeholder) {
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : '';
}
return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart());
}
return null;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,14 +23,12 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\Part;
use App\Services\SIFormatter;
use Symfony\Contracts\Translation\TranslatorInterface;
final class PartProvider implements PlaceholderProviderInterface
{
private $siFormatter;
private $translator;
@ -37,76 +38,74 @@ final class PartProvider implements PlaceholderProviderInterface
$this->translator = $translator;
}
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $part, array $options = []): ?string
{
if (!$part instanceof Part) {
if (! $part instanceof Part) {
return null;
}
if ($placeholder === '[[CATEGORY]]') {
if ('[[CATEGORY]]' === $placeholder) {
return $part->getCategory() ? $part->getCategory()->getName() : '';
}
if ($placeholder === '[[CATEGORY_FULL]]') {
if ('[[CATEGORY_FULL]]' === $placeholder) {
return $part->getCategory() ? $part->getCategory()->getFullPath() : '';
}
if ($placeholder === '[[MANUFACTURER]]') {
if ('[[MANUFACTURER]]' === $placeholder) {
return $part->getManufacturer() ? $part->getManufacturer()->getName() : '';
}
if ($placeholder === '[[MANUFACTURER_FULL]]') {
if ('[[MANUFACTURER_FULL]]' === $placeholder) {
return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : '';
}
if ($placeholder === '[[FOOTPRINT]]') {
if ('[[FOOTPRINT]]' === $placeholder) {
return $part->getFootprint() ? $part->getFootprint()->getName() : '';
}
if ($placeholder === '[[FOOTPRINT_FULL]]') {
if ('[[FOOTPRINT_FULL]]' === $placeholder) {
return $part->getFootprint() ? $part->getFootprint()->getFullPath() : '';
}
if ($placeholder === '[[MASS]]') {
if ('[[MASS]]' === $placeholder) {
return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : '';
}
if ($placeholder === '[[MPN]]') {
if ('[[MPN]]' === $placeholder) {
return $part->getManufacturerProductNumber();
}
if ($placeholder === '[[TAGS]]') {
if ('[[TAGS]]' === $placeholder) {
return $part->getTags();
}
if ($placeholder === '[[M_STATUS]]') {
if ($part->getManufacturingStatus() === '') {
if ('[[M_STATUS]]' === $placeholder) {
if ('' === $part->getManufacturingStatus()) {
return '';
}
return $this->translator->trans('m_status.' . $part->getManufacturingStatus());
return $this->translator->trans('m_status.'.$part->getManufacturingStatus());
}
$parsedown = new \Parsedown();
if ($placeholder === '[[DESCRIPTION]]') {
if ('[[DESCRIPTION]]' === $placeholder) {
return $parsedown->line($part->getDescription());
}
if ($placeholder === '[[DESCRIPTION_T]]') {
if ('[[DESCRIPTION_T]]' === $placeholder) {
return strip_tags($parsedown->line($part->getDescription()));
}
if ($placeholder === '[[COMMENT]]') {
if ('[[COMMENT]]' === $placeholder) {
return $parsedown->line($part->getComment());
}
if ($placeholder === '[[COMMENT_T]]') {
if ('[[COMMENT_T]]' === $placeholder) {
return strip_tags($parsedown->line($part->getComment()));
}
return null;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,17 +23,17 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
interface PlaceholderProviderInterface
{
/**
* Determines the real value of this placeholder.
* If the placeholder is not supported, null must be returned.
* @param string $placeholder The placeholder (e.g. "%%PLACEHOLDER%%") that should be replaced
* @param object $label_target The object that is targeted by the label
* @param array $options A list of options that can be used to specify the generated output further.
*
* @param string $placeholder The placeholder (e.g. "%%PLACEHOLDER%%") that should be replaced
* @param object $label_target The object that is targeted by the label
* @param array $options A list of options that can be used to specify the generated output further.
*
* @return string|null The real value of this placeholder, null if not supported.
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string;
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,33 +23,30 @@
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
final class StructuralDBElementProvider implements PlaceholderProviderInterface
{
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof AbstractStructuralDBElement) {
if ($placeholder === '[[COMMENT]]') {
if ('[[COMMENT]]' === $placeholder) {
return $label_target->getComment();
}
if ($placeholder === '[[COMMENT_T]]') {
if ('[[COMMENT_T]]' === $placeholder) {
return strip_tags($label_target->getComment());
}
if ($placeholder === '[[FULL_PATH]]') {
if ('[[FULL_PATH]]' === $placeholder) {
return $label_target->getFullPath();
}
if ($placeholder === '[[PARENT]]') {
if ('[[PARENT]]' === $placeholder) {
return $label_target->getParent() ? $label_target->getParent()->getName() : '';
}
if ($placeholder === '[[PARENT_FULL_PATH]]') {
if ('[[PARENT_FULL_PATH]]' === $placeholder) {
return $label_target->getParent() ? $label_target->getParent()->getFullPath() : '';
}
}
return null;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -26,23 +29,18 @@ use Locale;
final class TimestampableElementProvider implements PlaceholderProviderInterface
{
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof TimeStampableInterface) {
if ($placeholder === '[[LAST_MODIFIED]]') {
if ('[[LAST_MODIFIED]]' === $placeholder) {
return IntlDateFormatter::formatObject($label_target->getLastModified() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
}
if ($placeholder === '[[CREATION_DATE]]') {
if ('[[CREATION_DATE]]' === $placeholder) {
return IntlDateFormatter::formatObject($label_target->getAddedDate() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
}
}
return null;
}
}
}