Fixed code style.

This commit is contained in:
Jan Böhmer 2020-03-29 22:16:06 +02:00
parent b6e88db35f
commit 3671c94844
19 changed files with 55 additions and 60 deletions

View file

@ -197,7 +197,7 @@ abstract class BaseAdminController extends AbstractController
//We can not use dynamic form events here, because the parent entity list is build from database!
$form = $this->createForm($this->form_class, $entity, [
'attachment_class' => $this->attachment_class,
'parameter_class' => $this->parameter_class
'parameter_class' => $this->parameter_class,
]);
} elseif ($form->isSubmitted() && ! $form->isValid()) {
$this->addFlash('error', 'entity.edit_flash.invalid');

View file

@ -135,7 +135,7 @@ class PartController extends AbstractController
'pictures' => $this->partPreviewGenerator->getPreviewAttachments($part),
'timeTravel' => $timeTravel_timestamp,
'description_params' => $parameterExtractor->extractParameters($part->getDescription()),
'comment_params' => $parameterExtractor->extractParameters($part->getComment())
'comment_params' => $parameterExtractor->extractParameters($part->getComment()),
]
);
}

View file

@ -43,7 +43,6 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Parameters\PartParameter;
use App\Entity\UserSystem\User;
use App\Form\Permissions\PermissionsType;
use App\Form\UserAdminForm;
@ -69,7 +68,7 @@ class UserController extends AdminPages\BaseAdminController
protected $route_base = 'user';
protected $attachment_class = UserAttachment::class;
//Just define a value here to prevent error. It is not used.
protected $parameter_class = "not used";
protected $parameter_class = 'not used';
/**
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="user_edit")

View file

@ -89,16 +89,16 @@ class PartFixtures extends Fixture
$orderdetail = new Orderdetail();
$orderdetail->setSupplier($manager->find(Supplier::class, 1));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice("10.0"));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice("15.0"));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice('10.0'));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice('15.0'));
$part->addOrderdetail($orderdetail);
$orderdetail = new Orderdetail();
$orderdetail->setSupplierpartnr('BC 547');
$orderdetail->setObsolete(true);
$orderdetail->setSupplier($manager->find(Supplier::class, 1));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice("10.0"));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice("15.1"));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice('10.0'));
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice('15.1'));
$part->addOrderdetail($orderdetail);
$attachment = new PartAttachment();

View file

@ -44,7 +44,6 @@ namespace App\DataTables\Column;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\Parameters\AbstractParameter;
@ -99,7 +98,7 @@ class LogEntryTargetColumn extends AbstractColumn
$tmp = '';
//The element is existing
if ($target instanceof NamedElementInterface && !empty($target->getName())) {
if ($target instanceof NamedElementInterface && ! empty($target->getName())) {
try {
$tmp = sprintf(
'<a href="%s">%s</a>',
@ -126,15 +125,15 @@ class LogEntryTargetColumn extends AbstractColumn
//Add a hint to the associated element if possible
if (null !== $target && $this->options['show_associated']) {
if ($target instanceof Attachment && $target->getElement() !== null) {
if ($target instanceof Attachment && null !== $target->getElement()) {
$on = $target->getElement();
} elseif ($target instanceof AbstractParameter && $target->getElement() !== null) {
} elseif ($target instanceof AbstractParameter && null !== $target->getElement()) {
$on = $target->getElement();
} elseif ($target instanceof PartLot && $target->getPart() !== null) {
} elseif ($target instanceof PartLot && null !== $target->getPart()) {
$on = $target->getPart();
} elseif ($target instanceof Orderdetail && $target->getPart() !== null) {
} elseif ($target instanceof Orderdetail && null !== $target->getPart()) {
$on = $target->getPart();
} elseif ($target instanceof Pricedetail && $target->getOrderdetail() !== null && $target->getOrderdetail()->getPart() !== null) {
} elseif ($target instanceof Pricedetail && null !== $target->getOrderdetail() && null !== $target->getOrderdetail()->getPart()) {
$on = $target->getOrderdetail()->getPart();
}
@ -146,7 +145,7 @@ class LogEntryTargetColumn extends AbstractColumn
$this->elementTypeNameGenerator->getTypeNameCombination($on, true)
);
} catch (EntityNotSupportedException $exception) {
$tmp .= ' (' . $this->elementTypeNameGenerator->getTypeNameCombination($target, true) .')';
$tmp .= ' ('.$this->elementTypeNameGenerator->getTypeNameCombination($target, true).')';
}
}
}

View file

@ -212,7 +212,7 @@ class LogDataTable implements DataTableTypeInterface
$dataTable->add('target', LogEntryTargetColumn::class, [
'label' => $this->translator->trans('log.target'),
'show_associated' => $options['mode'] !== 'element_history',
'show_associated' => 'element_history' !== $options['mode'],
]);
$dataTable->add('extra', LogEntryExtraColumn::class, [

View file

@ -28,7 +28,6 @@ use App\Entity\Base\AbstractNamedDBElement;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use LogicException;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -213,7 +212,8 @@ abstract class AbstractParameter extends AbstractNamedDBElement
}
/**
* Returns the name of the group this parameter is associated to (e.g. Technical Parameters)
* Returns the name of the group this parameter is associated to (e.g. Technical Parameters).
*
* @return string
*/
public function getGroup(): string
@ -223,12 +223,13 @@ abstract class AbstractParameter extends AbstractNamedDBElement
/**
* Sets the name of the group this parameter is associated to.
* @param string $group
*
* @return $this
*/
public function setGroup(string $group): self
{
$this->group = $group;
return $this;
}

View file

@ -73,6 +73,7 @@ trait ParametersTrait
foreach ($this->parameters as $parameter) {
$tmp[$parameter->getGroup()][] = $parameter;
}
return $tmp;
}
}

View file

@ -328,9 +328,6 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
return $this;
}
/**
* @inheritDoc
*/
public function getName(): string
{
return $this->description;

View file

@ -361,9 +361,6 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
return $this;
}
/**
* @inheritDoc
*/
public function getName(): string
{
return $this->getSupplierPartNr();

View file

@ -60,7 +60,7 @@ class EventLoggerSubscriber implements EventSubscriber
Orderdetail::class => ['part'],
Pricedetail::class => ['orderdetail'],
Attachment::class => ['element'],
AbstractParameter::class => ['element']
AbstractParameter::class => ['element'],
];
protected const MAX_STRING_LENGTH = 2000;

View file

@ -45,7 +45,6 @@ namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\PartParameter;
use App\Form\AttachmentFormType;
use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;

View file

@ -113,14 +113,14 @@ class ParameterType extends AbstractType
'attr' => [
'placeholder' => 'parameter.group.placeholder',
'class' => 'form-control-sm',
]
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => AbstractParameter::class,
]);
'data_class' => AbstractParameter::class,
]);
}
}

View file

@ -52,7 +52,6 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Form\AttachmentFormType;
use App\Form\ParameterGroupType;
use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\SIUnitType;

View file

@ -49,7 +49,6 @@ use App\Form\Type\SIUnitType;
use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

View file

@ -27,11 +27,11 @@ final class Version20200311204104 extends AbstractMigration
$this->addSql('ALTER TABLE `users` ADD perms_parts_parameters SMALLINT NOT NULL');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT');
$sql = 'UPDATE `groups`' .
$sql = 'UPDATE `groups`'.
'SET perms_parts_parameters = 341 WHERE (id = 1 AND name = "admins") OR (id = 3 AND name = "users");';
$this->addSql($sql);
$sql = 'UPDATE `groups`' .
$sql = 'UPDATE `groups`'.
'SET perms_parts_parameters = 681 WHERE (id = 2 AND name = "readonly");';
$this->addSql($sql);

View file

@ -64,9 +64,10 @@ class GitVersionInfo
$git = file($this->project_dir.'/.git/HEAD');
$head = explode('/', $git[0], 3);
if (!isset($head[2])) {
if (! isset($head[2])) {
return null;
}
return trim($head[2]);
}
@ -88,7 +89,7 @@ class GitVersionInfo
if (file_exists($filename)) {
$head = file($filename);
if (!isset($head[0])) {
if (! isset($head[0])) {
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,31 +23,29 @@
namespace App\Services\Parameters;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parameters\PartParameter;
class ParameterExtractor
{
protected const ALLOWED_PARAM_SEPARATORS = [", ", "\n"];
protected const ALLOWED_PARAM_SEPARATORS = [', ', "\n"];
protected const CHAR_LIMIT = 1000;
/**
* Tries to extract parameters from the given string.
* Useful for extraction from part description and comment.
* @param string $input
* @param string $class
*
* @return AbstractParameter[]
*/
public function extractParameters(string $input, string $class = PartParameter::class): array
{
if (!is_a($class, AbstractParameter::class, true)) {
if (! is_a($class, AbstractParameter::class, true)) {
throw new \InvalidArgumentException('$class must be a child class of AbstractParameter!');
}
//Restrict search length
$input = mb_strimwidth($input,0,self::CHAR_LIMIT);
$input = mb_strimwidth($input, 0, self::CHAR_LIMIT);
$parameters = [];
@ -52,7 +53,7 @@ class ParameterExtractor
$split = $this->splitString($input);
foreach ($split as $param_string) {
$tmp = $this->stringToParam($param_string, $class);
if ($tmp !== null) {
if (null !== $tmp) {
$parameters[] = $tmp;
}
}
@ -67,7 +68,7 @@ class ParameterExtractor
$matches = [];
\preg_match($regex, $input, $matches);
if (!empty($matches)) {
if (! empty($matches)) {
[$raw, $name, $value] = $matches;
$value = trim($value);
@ -90,7 +91,8 @@ class ParameterExtractor
protected function splitString(string $input): array
{
//Allow comma as limiter (include space, to prevent splitting in german style numbers)
$input = str_replace(static::ALLOWED_PARAM_SEPARATORS, ";", $input);
return explode(";", $input);
$input = str_replace(static::ALLOWED_PARAM_SEPARATORS, ';', $input);
return explode(';', $input);
}
}
}

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,10 +29,9 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ParameterExtractorTest extends WebTestCase
{
protected $service;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
//Get an service instance.
@ -40,26 +42,26 @@ class ParameterExtractorTest extends WebTestCase
public function emptyDataProvider(): array
{
return [
[""],
[" "],
[''],
[' '],
["\t\n"],
[":;"],
["NPN Transistor"],
["=BC547 rewr"],
["<i>For good</i>, [b]bad[/b], evil"],
["Param:; Test"]
[':;'],
['NPN Transistor'],
['=BC547 rewr'],
['<i>For good</i>, [b]bad[/b], evil'],
['Param:; Test'],
];
}
/**
* @dataProvider emptyDataProvider
*/
public function testShouldReturnEmpty(string $input)
public function testShouldReturnEmpty(string $input): void
{
$this->assertEmpty($this->service->extractParameters($input));
}
public function testExtract()
public function testExtract(): void
{
$parameters = $this->service->extractParameters(' Operating Voltage: 10 V; Property : Value, Ström=1A (Test)');
$this->assertContainsOnly(AbstractParameter::class, $parameters);
@ -70,6 +72,5 @@ class ParameterExtractorTest extends WebTestCase
$this->assertSame('Value', $parameters[1]->getValueText());
$this->assertSame('Ström', $parameters[2]->getName());
$this->assertSame('1A (Test)', $parameters[2]->getValueText());
}
}