diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index 9fb05dea..5fc8c5a8 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -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'); diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index c24c09ab..45008d1e 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -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()), ] ); } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 97738de0..a7d9ef5a 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -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") diff --git a/src/DataFixtures/PartFixtures.php b/src/DataFixtures/PartFixtures.php index b9a8a566..a47af181 100644 --- a/src/DataFixtures/PartFixtures.php +++ b/src/DataFixtures/PartFixtures.php @@ -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(); diff --git a/src/DataTables/Column/LogEntryTargetColumn.php b/src/DataTables/Column/LogEntryTargetColumn.php index d6c69655..e332edd5 100644 --- a/src/DataTables/Column/LogEntryTargetColumn.php +++ b/src/DataTables/Column/LogEntryTargetColumn.php @@ -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( '%s', @@ -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).')'; } } } diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index 135e9717..abbcf127 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -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, [ diff --git a/src/Entity/Parameters/AbstractParameter.php b/src/Entity/Parameters/AbstractParameter.php index 095df7ee..70665026 100644 --- a/src/Entity/Parameters/AbstractParameter.php +++ b/src/Entity/Parameters/AbstractParameter.php @@ -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; } diff --git a/src/Entity/Parameters/ParametersTrait.php b/src/Entity/Parameters/ParametersTrait.php index 192dd842..e543eff0 100644 --- a/src/Entity/Parameters/ParametersTrait.php +++ b/src/Entity/Parameters/ParametersTrait.php @@ -73,6 +73,7 @@ trait ParametersTrait foreach ($this->parameters as $parameter) { $tmp[$parameter->getGroup()][] = $parameter; } + return $tmp; } } diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index 2b8676dd..ef82a8bd 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -328,9 +328,6 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named return $this; } - /** - * @inheritDoc - */ public function getName(): string { return $this->description; diff --git a/src/Entity/PriceInformations/Orderdetail.php b/src/Entity/PriceInformations/Orderdetail.php index d938bfa3..84999672 100644 --- a/src/Entity/PriceInformations/Orderdetail.php +++ b/src/Entity/PriceInformations/Orderdetail.php @@ -361,9 +361,6 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N return $this; } - /** - * @inheritDoc - */ public function getName(): string { return $this->getSupplierPartNr(); diff --git a/src/EventSubscriber/EventLoggerSubscriber.php b/src/EventSubscriber/EventLoggerSubscriber.php index f6c89e14..1a80188f 100644 --- a/src/EventSubscriber/EventLoggerSubscriber.php +++ b/src/EventSubscriber/EventLoggerSubscriber.php @@ -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; diff --git a/src/Form/AdminPages/BaseEntityAdminForm.php b/src/Form/AdminPages/BaseEntityAdminForm.php index d1e029b9..09878973 100644 --- a/src/Form/AdminPages/BaseEntityAdminForm.php +++ b/src/Form/AdminPages/BaseEntityAdminForm.php @@ -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; diff --git a/src/Form/ParameterType.php b/src/Form/ParameterType.php index 8cd66abd..413df3e4 100644 --- a/src/Form/ParameterType.php +++ b/src/Form/ParameterType.php @@ -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, + ]); } } diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index 1610afcf..06ae6895 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -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; diff --git a/src/Form/Part/PartLotType.php b/src/Form/Part/PartLotType.php index ac0e55c6..8d67e514 100644 --- a/src/Form/Part/PartLotType.php +++ b/src/Form/Part/PartLotType.php @@ -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; diff --git a/src/Migrations/Version20200311204104.php b/src/Migrations/Version20200311204104.php index 0cd173d8..cd01e65a 100644 --- a/src/Migrations/Version20200311204104.php +++ b/src/Migrations/Version20200311204104.php @@ -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); diff --git a/src/Services/GitVersionInfo.php b/src/Services/GitVersionInfo.php index 35669936..b1653e4f 100644 --- a/src/Services/GitVersionInfo.php +++ b/src/Services/GitVersionInfo.php @@ -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; } diff --git a/src/Services/Parameters/ParameterExtractor.php b/src/Services/Parameters/ParameterExtractor.php index 835d4fa0..64903ee5 100644 --- a/src/Services/Parameters/ParameterExtractor.php +++ b/src/Services/Parameters/ParameterExtractor.php @@ -1,4 +1,7 @@ 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); } -} \ No newline at end of file +} diff --git a/tests/Services/Parameters/ParameterExtractorTest.php b/tests/Services/Parameters/ParameterExtractorTest.php index b88f0ab7..94b79576 100644 --- a/tests/Services/Parameters/ParameterExtractorTest.php +++ b/tests/Services/Parameters/ParameterExtractorTest.php @@ -1,4 +1,7 @@ For good, [b]bad[/b], evil"], - ["Param:; Test"] + [':;'], + ['NPN Transistor'], + ['=BC547 rewr'], + ['For good, [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()); - } }