diff --git a/src/Command/SetPasswordCommand.php b/src/Command/SetPasswordCommand.php index 5cf78971..a4398a97 100644 --- a/src/Command/SetPasswordCommand.php +++ b/src/Command/SetPasswordCommand.php @@ -7,7 +7,6 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; @@ -24,11 +23,9 @@ class SetPasswordCommand extends Command $this->entityManager = $entityManager; $this->encoder = $passwordEncoder; - parent::__construct(); } - protected function configure() { $this @@ -44,15 +41,14 @@ class SetPasswordCommand extends Command $user_name = $input->getArgument('user'); /** - * @var User $user + * @var User */ $users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]); $user = $users[0]; - - if($user == null) - { + if (null == $user) { $io->error(sprintf('No user with the given username %s found in the database!', $user_name)); + return; } @@ -62,18 +58,17 @@ class SetPasswordCommand extends Command sprintf('You are going to change the password of %s with ID %d. Proceed?', $user->getFullName(true), $user->getID())); - if(!$proceed) - { + if (!$proceed) { return; } $success = false; - $new_password = ""; + $new_password = ''; - while(!$success) { - $pw1 = $io->askHidden("Please enter new password:"); + while (!$success) { + $pw1 = $io->askHidden('Please enter new password:'); $pw2 = $io->askHidden('Please confirm:'); - if($pw1 !== $pw2) { + if ($pw1 !== $pw2) { $io->error('The entered password did not match! Please try again.'); } else { //Exit loop diff --git a/src/Configuration/PermissionsConfiguration.php b/src/Configuration/PermissionsConfiguration.php index 11ab52c9..52e26358 100644 --- a/src/Configuration/PermissionsConfiguration.php +++ b/src/Configuration/PermissionsConfiguration.php @@ -1,9 +1,8 @@ render('base.html.twig'); } -} \ No newline at end of file +} diff --git a/src/Controller/HomepageController.php b/src/Controller/HomepageController.php index 583db40f..495199da 100644 --- a/src/Controller/HomepageController.php +++ b/src/Controller/HomepageController.php @@ -1,11 +1,9 @@ render('homepage.html.twig', [ - 'banner' => $this->getParameter('banner') + 'banner' => $this->getParameter('banner'), ]); } -} \ No newline at end of file +} diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index d7c0d8f8..4df37e50 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -1,10 +1,9 @@ render('Parts/show_part_info.html.twig', [ 'part' => $part, - 'main_image' => $attachmentFilenameService->attachmentPathToAbsolutePath($filename) + 'main_image' => $attachmentFilenameService->attachmentPathToAbsolutePath($filename), ] ); } @@ -68,6 +64,7 @@ class PartController extends AbstractController * @Route("/part/{id}/edit", name="part_edit") * * @param Part $part + * * @return \Symfony\Component\HttpFoundation\Response */ public function edit(Part $part, Request $request, EntityManagerInterface $em) @@ -114,24 +111,22 @@ class PartController extends AbstractController $em->persist($new_part); $em->flush(); $this->addFlash('success', $translator->trans('part.created_flash')); - return $this->redirectToRoute('part_edit',['id' => $new_part->getID()]); - } + return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]); + } return $this->render('Parts/new_part.html.twig', [ 'part' => $new_part, - 'form' => $form->createView() + 'form' => $form->createView(), ]); } /** * @Route("/part/{id}/clone", name="part_clone") - * */ public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator) { - /** @var Part $new_part */ $new_part = clone $part; @@ -145,15 +140,14 @@ class PartController extends AbstractController $em->persist($new_part); $em->flush(); $this->addFlash('success', $translator->trans('part.created_flash')); - return $this->redirectToRoute('part_edit',['id' => $new_part->getID()]); - } + return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]); + } return $this->render('Parts/new_part.html.twig', [ 'part' => $new_part, - 'form' => $form->createView() + 'form' => $form->createView(), ]); } - -} \ No newline at end of file +} diff --git a/src/Controller/PartListsController.php b/src/Controller/PartListsController.php index 0a0b1882..845ff831 100644 --- a/src/Controller/PartListsController.php +++ b/src/Controller/PartListsController.php @@ -1,9 +1,8 @@ create() ->add("id", TextColumn::class) ->add("name", TextColumn::class) @@ -60,7 +59,6 @@ class PartListsController extends AbstractController $table = $dataTable->createFromType(PartsDataTable::class, ['cid' => $id]) ->handleRequest($request); - if ($table->isCallback()) { return $table->getResponse(); } @@ -71,8 +69,9 @@ class PartListsController extends AbstractController /** * @Route("/parts") * - * @param Request $request + * @param Request $request * @param DataTableFactory $dataTable + * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function showAll(Request $request, DataTableFactory $dataTable) @@ -80,13 +79,10 @@ class PartListsController extends AbstractController $table = $dataTable->createFromType(PartsDataTable::class) ->handleRequest($request); - if ($table->isCallback()) { return $table->getResponse(); } return $this->render('parts_list.html.twig', ['datatable' => $table]); } - - -} \ No newline at end of file +} diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 1ae5d2f4..ddd59b48 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -1,9 +1,8 @@ render('security/login.html.twig', [ 'last_username' => $lastUsername, - 'error' => $error, + 'error' => $error, ]); } @@ -62,5 +59,4 @@ class SecurityController extends AbstractController { throw new \Exception('Will be intercepted before getting here'); } - -} \ No newline at end of file +} diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 777a7095..080491be 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -1,9 +1,8 @@ getUser(); } else { //Else we must check, if the current user is allowed to access $user $this->denyAccessUnlessGranted('read', $user); } - if($this->getParameter('use_gravatar')) { + if ($this->getParameter('use_gravatar')) { $avatar = $this->getGravatar($user->getEmail(), 200, 'identicon'); } else { $avatar = $packages->getUrl('/img/default_avatar.png'); } - return $this->render('Users/user_info.html.twig', [ 'user' => $user, - 'avatar' => $avatar + 'avatar' => $avatar, ]); } @@ -110,16 +105,16 @@ class UserController extends AbstractController $pw_form = $this->createFormBuilder() ->add('old_password', PasswordType::class, [ 'label' => 'user.settings.pw_old.label', - 'constraints'=> [new UserPassword()]]) //This constraint checks, if the current user pw was inputted. + 'constraints' => [new UserPassword()], ]) //This constraint checks, if the current user pw was inputted. ->add('new_password', RepeatedType::class, [ 'type' => PasswordType::class, - 'first_options' => ['label'=> 'user.settings.pw_new.label'], - 'second_options' => ['label'=> 'user.settings.pw_confirm.label'], + 'first_options' => ['label' => 'user.settings.pw_new.label'], + 'second_options' => ['label' => 'user.settings.pw_confirm.label'], 'invalid_message' => 'password_must_match', 'constraints' => [new Length([ 'min' => 6, - 'max' => 128 - ])] + 'max' => 128, + ])], ]) ->add('submit', SubmitType::class, ['label' => 'save']) ->getForm(); @@ -127,7 +122,7 @@ class UserController extends AbstractController $pw_form->handleRequest($request); //Check if password if everything was correct, then save it to User and DB - if($pw_form->isSubmitted() && $pw_form->isValid()) { + if ($pw_form->isSubmitted() && $pw_form->isValid()) { $password = $passwordEncoder->encodePassword($user, $pw_form['new_password']->getData()); $user->setPassword($password); $em->persist($user); @@ -141,21 +136,21 @@ class UserController extends AbstractController return $this->render('Users/user_settings.html.twig', [ 'settings_form' => $form->createView(), - 'pw_form' => $pw_form->createView() + 'pw_form' => $pw_form->createView(), ]); } - /** * Get either a Gravatar URL or complete image tag for a specified email address. * * @param string $email The email address - * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] - * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] - * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] - * @param bool $img True to return a complete IMG tag False for just the URL - * @param array $atts Optional, additional key/value attributes to include in the IMG tag - * @return String containing either just a URL or a complete image tag + * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] + * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] + * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] + * @param bool $img True to return a complete IMG tag False for just the URL + * @param array $atts Optional, additional key/value attributes to include in the IMG tag + * + * @return string containing either just a URL or a complete image tag * @source https://gravatar.com/site/implement/images/php/ */ public function getGravatar(string $email, int $s = 80, string $d = 'mm', string $r = 'g', bool $img = false, array $atts = array()) @@ -164,13 +159,13 @@ class UserController extends AbstractController $url .= md5(strtolower(trim($email))); $url .= "?s=$s&d=$d&r=$r"; if ($img) { - $url = ' $val) { - $url .= ' ' . $key . '="' . $val . '"'; + $url .= ' '.$key.'="'.$val.'"'; } $url .= ' />'; } + return $url; } - -} \ No newline at end of file +} diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index eb41a88d..e2ca6183 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -1,9 +1,8 @@ add("id", TextColumn::class) - ->add("name", TextColumn::class, ['label' => 'name.label', - 'render' => function($value, Part $context) { + ->add('name', TextColumn::class, ['label' => 'name.label', + 'render' => function ($value, Part $context) { return $this->urlGenerator->infoHTML($context); - }]) - ->add("description", TextColumn::class, ['label' => 'description.label']) - ->add("category", TextColumn::class, ['field' => 'category.name', 'label' => 'category.label']) - ->add("instock", TextColumn::class, ['label' => 'instock.label_short']) - ->add("mininstock", TextColumn::class, ['label' => 'mininstock.label_short']) - ->add("storelocation", TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label']) + }, ]) + ->add('description', TextColumn::class, ['label' => 'description.label']) + ->add('category', TextColumn::class, ['field' => 'category.name', 'label' => 'category.label']) + ->add('instock', TextColumn::class, ['label' => 'instock.label_short']) + ->add('mininstock', TextColumn::class, ['label' => 'mininstock.label_short']) + ->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label']) ->addOrderBy('name') ->createAdapter(ORMAdapter::class, [ 'entity' => Part::class, 'criteria' => [ - function (QueryBuilder $builder) use($options) { - if(isset($options['cid'])) { + function (QueryBuilder $builder) use ($options) { + if (isset($options['cid'])) { $builder->andWhere('part.category = :cid') ->setParameter('cid', $options['cid']); } }, - new SearchCriteriaProvider() - ] + new SearchCriteriaProvider(), + ], ]); } -} \ No newline at end of file +} diff --git a/src/Entity/Attachment.php b/src/Entity/Attachment.php index fdd95ff6..cd2e8c14 100644 --- a/src/Entity/Attachment.php +++ b/src/Entity/Attachment.php @@ -1,9 +1,10 @@ -getFilename(), PATHINFO_EXTENSION); @@ -89,10 +87,11 @@ class Attachment extends NamedDBElement *********************************************************************************/ /** - * Get the element, associated with this Attachement (for example a "Part" object) + * Get the element, associated with this Attachement (for example a "Part" object). + * * @return DBElement The associated Element. */ - public function getElement() : AttachmentContainingDBElement + public function getElement(): AttachmentContainingDBElement { return $this->element; } @@ -103,53 +102,56 @@ class Attachment extends NamedDBElement * * @return bool True if the file is existing. */ - public function isFileExisting() : bool + public function isFileExisting(): bool { return file_exists($this->getFilename()) || isURL($this->getFilename()); } /** - * Get the filename, relative to %BASE% + * Get the filename, relative to %BASE%. * * @return string */ - public function getFilename() : string + public function getFilename(): string { return $this->filename; //return str_replace('%BASE%', BASE, $this->filename); } /** - * Get the show_in_table attribute + * Get the show_in_table attribute. * - * @return bool true means, this attachement will be listed in the "Attachements" column of the HTML tables - * false means, this attachement won't be listed in the "Attachements" column of the HTML tables + * @return bool true means, this attachement will be listed in the "Attachements" column of the HTML tables + * false means, this attachement won't be listed in the "Attachements" column of the HTML tables */ - public function getShowInTable() : bool + public function getShowInTable(): bool { return (bool) $this->show_in_table; } /** - * Get the type of this attachement - * @return AttachmentType the type of this attachement + * Get the type of this attachement. + * + * @return AttachmentType the type of this attachement + * * @throws Exception if there was an error */ - public function getType() : AttachmentType + public function getType(): AttachmentType { //TODO - throw new NotImplementedException("Not implemented yet!"); + throw new NotImplementedException('Not implemented yet!'); } /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. + * * @return string The ID as a string; */ public function getIDString(): string { - return 'A' . sprintf('%09d', $this->getID()); + return 'A'.sprintf('%09d', $this->getID()); } /***************************************************************************************************** @@ -158,11 +160,13 @@ class Attachment extends NamedDBElement /** * @param bool $show_in_table + * * @return self */ public function setShowInTable(bool $show_in_table): self { $this->show_in_table = $show_in_table; + return $this; } -} \ No newline at end of file +} diff --git a/src/Entity/AttachmentContainingDBElement.php b/src/Entity/AttachmentContainingDBElement.php index ee4ef06d..36d68a35 100644 --- a/src/Entity/AttachmentContainingDBElement.php +++ b/src/Entity/AttachmentContainingDBElement.php @@ -1,9 +1,10 @@ -attachmentTypes; } - /** - * Get all attachements of this element / Get the element's attachements with a specific type + * Get all attachements of this element / Get the element's attachements with a specific type. * - * @param integer $type_id * if NULL, all attachements of this element will be returned - * * if this is a number > 0, only attachements with this type ID will be returned - * @param boolean $only_table_attachements if true, only attachements with "show_in_table == true" + * @param int $type_id * if NULL, all attachements of this element will be returned + * * if this is a number > 0, only attachements with this type ID will be returned + * @param bool $only_table_attachements if true, only attachements with "show_in_table == true" * * @return Attachment[] the attachements as a one-dimensional array of Attachement objects * * @throws Exception if there was an error */ - public function getAttachments($type_id = null, bool $only_table_attachements = false) : array + public function getAttachments($type_id = null, bool $only_table_attachements = false): array { if ($only_table_attachements || $type_id) { $attachements = $this->attachments; foreach ($attachements as $key => $attachement) { - if (($only_table_attachements && (! $attachement->getShowInTable())) + if (($only_table_attachements && (!$attachement->getShowInTable())) || ($type_id && ($attachement->getType()->getID() !== $type_id))) { unset($attachements[$key]); } diff --git a/src/Entity/AttachmentType.php b/src/Entity/AttachmentType.php index f21ebb9a..ba4d4f98 100644 --- a/src/Entity/AttachmentType.php +++ b/src/Entity/AttachmentType.php @@ -1,9 +1,10 @@ -attachements is used from class "AttachementsContainingDBELement" - if ($this->attachments === null) { + if (null === $this->attachments) { $this->attachments = new ArrayCollection(); } @@ -72,6 +70,7 @@ class AttachmentType extends StructuralDBElement /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. + * * @return string The ID as a string; */ public function getIDString(): string diff --git a/src/Entity/Category.php b/src/Entity/Category.php index 9c7e37eb..f2f6d8fb 100644 --- a/src/Entity/Category.php +++ b/src/Entity/Category.php @@ -1,9 +1,10 @@ -getID()); + return 'C'.sprintf('%09d', $this->getID()); } } diff --git a/src/Entity/Company.php b/src/Entity/Company.php index a5209fd3..757c6600 100644 --- a/src/Entity/Company.php +++ b/src/Entity/Company.php @@ -1,9 +1,10 @@ -address; } /** - * Get the phone number + * Get the phone number. * - * @return string the phone number of the company + * @return string the phone number of the company */ - public function getPhoneNumber() : string + public function getPhoneNumber(): string { return $this->phone_number; } /** - * Get the fax number + * Get the fax number. * - * @return string the fax number of the company + * @return string the fax number of the company */ - public function getFaxNumber() : string + public function getFaxNumber(): string { return $this->fax_number; } /** - * Get the e-mail address + * Get the e-mail address. * - * @return string the e-mail address of the company + * @return string the e-mail address of the company */ - public function getEmailAddress() : string + public function getEmailAddress(): string { return $this->email_address; } /** - * Get the website + * Get the website. * - * @return string the website of the company + * @return string the website of the company */ - public function getWebsite() : string + public function getWebsite(): string { return $this->website; } /** - * Get the link to the website of an article + * Get the link to the website of an article. * - * @param string $partnr * NULL for returning the URL with a placeholder for the part number - * * or the part number for returning the direct URL to the article + * @param string $partnr * NULL for returning the URL with a placeholder for the part number + * * or the part number for returning the direct URL to the article * - * @return string the link to the article + * @return string the link to the article */ - public function getAutoProductUrl($partnr = null) : string + public function getAutoProductUrl($partnr = null): string { if (\is_string($partnr)) { return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url); } + return $this->auto_product_url; } @@ -148,81 +148,86 @@ abstract class Company extends StructuralDBElement *********************************************************************************/ /** - * Set the addres - * @param string $new_address the new address (with "\n" as line break) + * Set the addres. + * + * @param string $new_address the new address (with "\n" as line break) * * @return self */ - public function setAddress(string $new_address) : self + public function setAddress(string $new_address): self { $this->address = $new_address; + return $this; } /** - * Set the phone number + * Set the phone number. * - * @param string $new_phone_number the new phone number + * @param string $new_phone_number the new phone number * * @return self */ - public function setPhoneNumber(string $new_phone_number) : self + public function setPhoneNumber(string $new_phone_number): self { $this->phone_number = $new_phone_number; + return $this; } /** - * Set the fax number + * Set the fax number. * - * @param string $new_fax_number the new fax number + * @param string $new_fax_number the new fax number * * @return self */ - public function setFaxNumber(string $new_fax_number) : self + public function setFaxNumber(string $new_fax_number): self { $this->fax_number = $new_fax_number; + return $this; } /** - * Set the e-mail address + * Set the e-mail address. * - * @param string $new_email_address the new e-mail address + * @param string $new_email_address the new e-mail address * * @return self - */ - public function setEmailAddress(string $new_email_address) : self + public function setEmailAddress(string $new_email_address): self { $this->email_address = $new_email_address; + return $this; } /** - * Set the website + * Set the website. * - * @param string $new_website the new website + * @param string $new_website the new website * * @return self */ - public function setWebsite(string $new_website) : self + public function setWebsite(string $new_website): self { $this->website = $new_website; + return $this; } /** - * Set the link to the website of an article + * Set the link to the website of an article. * - * @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number + * @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number * * @return self */ - public function setAutoProductUrl(string $new_url) : self + public function setAutoProductUrl(string $new_url): self { $this->auto_product_url = $new_url; + return $this; } - -} \ No newline at end of file +} diff --git a/src/Entity/DBElement.php b/src/Entity/DBElement.php index 78b17c60..0211b27b 100644 --- a/src/Entity/DBElement.php +++ b/src/Entity/DBElement.php @@ -1,9 +1,10 @@ -id; } - /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. + * * @return string The ID as a string; */ - abstract public function getIDString() : string; + abstract public function getIDString(): string; public function __clone() { //Set ID to null, so that an new entry is created $this->id = null; } - -} \ No newline at end of file +} diff --git a/src/Entity/Device.php b/src/Entity/Device.php index c45772ec..8a60f686 100644 --- a/src/Entity/Device.php +++ b/src/Entity/Device.php @@ -1,11 +1,11 @@ -order_quantity; } /** - * Get the "order_only_missing_parts" attribute + * Get the "order_only_missing_parts" attribute. * - * @return boolean the "order_only_missing_parts" attribute + * @return bool the "order_only_missing_parts" attribute */ - public function getOrderOnlyMissingParts() : bool + public function getOrderOnlyMissingParts(): bool { return $this->order_only_missing_parts; } @@ -105,40 +103,44 @@ class Device extends PartsContainingDBElement *********************************************************************************/ /** - * Set the order quantity + * Set the order quantity. + * + * @param int $new_order_quantity the new order quantity * - * @param integer $new_order_quantity the new order quantity * @return self */ - public function setOrderQuantity(int $new_order_quantity) : self + public function setOrderQuantity(int $new_order_quantity): self { - if($new_order_quantity < 0) - { + if ($new_order_quantity < 0) { throw new \InvalidArgumentException('The new order quantity must not be negative!'); } $this->order_quantity = $new_order_quantity; + return $this; } /** - * Set the "order_only_missing_parts" attribute - * @param boolean $new_order_only_missing_parts the new "order_only_missing_parts" attribute + * Set the "order_only_missing_parts" attribute. + * + * @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute + * * @return self */ - public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts) : self + public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self { $this->order_only_missing_parts = $new_order_only_missing_parts; + return $this; } - /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. + * * @return string The ID as a string; */ public function getIDString(): string { - return 'D' . sprintf('%09d', $this->getID()); + return 'D'.sprintf('%09d', $this->getID()); } -} \ No newline at end of file +} diff --git a/src/Entity/DevicePart.php b/src/Entity/DevicePart.php index 09b57cb7..281a287c 100644 --- a/src/Entity/DevicePart.php +++ b/src/Entity/DevicePart.php @@ -1,10 +1,11 @@ -getID()); + return 'DP'.sprintf('%06d', $this->getID()); } -} \ No newline at end of file +} diff --git a/src/Entity/Footprint.php b/src/Entity/Footprint.php index df7d275f..dfd96b53 100644 --- a/src/Entity/Footprint.php +++ b/src/Entity/Footprint.php @@ -1,10 +1,11 @@ -getID()); + return 'F'.sprintf('%06d', $this->getID()); } /**************************************** @@ -88,27 +86,28 @@ class Footprint extends PartsContainingDBElement ****************************************/ /** - * Get the filename of the picture (absolute path from filesystem root) - * @return string the saved filename in the DB - * * an empty string if there is no picture + * Get the filename of the picture (absolute path from filesystem root). + * + * @return string the saved filename in the DB + * * an empty string if there is no picture */ - public function getFilename() : string + public function getFilename(): string { return $this->filename; } /** - * Get the filename of the 3d model (absolute path from filesystem root) + * Get the filename of the 3d model (absolute path from filesystem root). * * @param bool $absolute If set to true, then the absolute filename (from system root) is returned. - * If set to false, then the path relative to Part-DB folder is returned. + * If set to false, then the path relative to Part-DB folder is returned. * - * @return string * the absolute path to the model (from filesystem root), as a UNIX path (with slashes) - * * an empty string if there is no model + * @return string * the absolute path to the model (from filesystem root), as a UNIX path (with slashes) + * * an empty string if there is no model */ - public function get3dFilename(bool $absolute = true) : string + public function get3dFilename(bool $absolute = true): string { - if ($absolute === true) { + if (true === $absolute) { //TODO throw new \Exception('Not Implemented yet...'); //return str_replace('%BASE%', BASE, $this->db_data['filename_3d']); @@ -118,17 +117,17 @@ class Footprint extends PartsContainingDBElement } /** - * Check if the filename of this footprint is valid (picture exists) + * Check if the filename of this footprint is valid (picture exists). * * This method is used to get all footprints with broken filename * (Footprint::get_broken_filename_footprints()). * * An empty filename is a valid filename. * - * @return boolean * true if file exists or filename is empty - * * false if there is no file with this filename + * @return bool * true if file exists or filename is empty + * * false if there is no file with this filename */ - public function isFilenameValid() : bool + public function isFilenameValid(): bool { if (empty($this->getFilename())) { return true; @@ -138,24 +137,24 @@ class Footprint extends PartsContainingDBElement } /** - * Check if the filename of this 3d footprint is valid (model exists and have ) + * Check if the filename of this 3d footprint is valid (model exists and have ). * * This method is used to get all footprints with broken 3d filename * (Footprint::get_broken_3d_filename_footprints()). * * An empty filename is a valid filename. * - * @return boolean * true if file exists or filename is empty - * * false if there is no file with this filename + * @return bool * true if file exists or filename is empty + * * false if there is no file with this filename */ - public function is3dFilenameValid() : bool + public function is3dFilenameValid(): bool { if (empty($this->get3dFilename())) { return true; } //Check if file is X3D-Model (these has .x3d extension) - if (strpos($this->get3dFilename(), '.x3d') === false) { + if (false === strpos($this->get3dFilename(), '.x3d')) { return false; } @@ -173,14 +172,14 @@ class Footprint extends PartsContainingDBElement *********************************************************************************/ /** - * Change the filename of this footprint + * Change the filename of this footprint. * * The filename won't be checked if it is valid. * It's not really a Problem if there is no such file... * (For this purpose we have the method Footprint::get_broken_filename_footprints()) * - * @param string $new_filename * the new filename (absolute path from filesystem root, as a UNIX path [only slashes!] !! ) - * * see also lib.functions.php::to_unix_path() + * @param string $new_filename * the new filename (absolute path from filesystem root, as a UNIX path [only slashes!] !! ) + * * see also lib.functions.php::to_unix_path() * * It's really important that you pass the whole (UNIX) path from filesystem root! * If the file is located in the base directory of Part-DB, the base path @@ -190,21 +189,26 @@ class Footprint extends PartsContainingDBElement * * The path-replacing will be done in Footprint::check_values_validity(), not here. * + * @return Footprint + * * @throws Exception if there was an error */ - public function setFilename(string $new_filename) : self + public function setFilename(string $new_filename): self { $this->filename = $new_filename; + return $this; } /** - * Change the 3d model filename of this footprint + * Change the 3d model filename of this footprint. + * * @throws Exception if there was an error */ - public function set3dFilename(string $new_filename) : self + public function set3dFilename(string $new_filename): self { $this->filename = $new_filename; + return $this; } -} \ No newline at end of file +} diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 076bd648..08ae4116 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -1,9 +1,8 @@ getID()); + return 'G'.sprintf('%06d', $this->getID()); } public function getPermissions(): PermissionsEmbed { return $this->permissions; } -} \ No newline at end of file +} diff --git a/src/Entity/Manufacturer.php b/src/Entity/Manufacturer.php index f834fc1e..0cfccf4b 100644 --- a/src/Entity/Manufacturer.php +++ b/src/Entity/Manufacturer.php @@ -1,10 +1,11 @@ -getID()); + return 'M'.sprintf('%06d', $this->getID()); } -} \ No newline at end of file +} diff --git a/src/Entity/NamedDBElement.php b/src/Entity/NamedDBElement.php index cf900f2c..7ed29de7 100644 --- a/src/Entity/NamedDBElement.php +++ b/src/Entity/NamedDBElement.php @@ -1,9 +1,10 @@ -lastModified; } /** * Returns the date/time when the element was created. + * * @return \DateTime The creation time of the part. */ - public function getAddedDate() : \DateTime + public function getAddedDate(): \DateTime { return $this->addedDate; } @@ -99,18 +99,20 @@ abstract class NamedDBElement extends DBElement *********************************************************************************/ /** - * Change the name of this element + * Change the name of this element. * * Spaces at the begin and at the end of the string will be removed * automatically in NamedDBElement::check_values_validity(). * So you don't have to do this yourself. * - * @param string $new_name the new name + * @param string $new_name the new name + * * @return self */ - public function setName(string $new_name) : self + public function setName(string $new_name): self { $this->name = $new_name; + return $this; } @@ -122,15 +124,15 @@ abstract class NamedDBElement extends DBElement /** * Helper for updating the timestamp. It is automatically called by doctrine before persisting. + * * @ORM\PrePersist * @ORM\PreUpdate */ public function updatedTimestamps(): void { $this->lastModified = new \DateTime('now'); - if ($this->addedDate === null) { + if (null === $this->addedDate) { $this->addedDate = new \DateTime('now'); } } - -} \ No newline at end of file +} diff --git a/src/Entity/Orderdetail.php b/src/Entity/Orderdetail.php index 83ff9ee8..e9622549 100644 --- a/src/Entity/Orderdetail.php +++ b/src/Entity/Orderdetail.php @@ -1,10 +1,11 @@ -getID()); + return 'O'.sprintf('%06d', $this->getID()); } /******************************************************************************** @@ -99,23 +97,23 @@ class Orderdetail extends DBElement *********************************************************************************/ /** - * Get the part + * Get the part. * - * @return Part the part of this orderdetails + * @return Part the part of this orderdetails */ - public function getPart() : Part + public function getPart(): Part { return $this->part; } /** - * Get the supplier + * Get the supplier. * - * @return Supplier the supplier of this orderdetails + * @return Supplier the supplier of this orderdetails * * @throws DatabaseException if there was an error */ - public function getSupplier() : Supplier + public function getSupplier(): Supplier { return $this->supplier; } @@ -123,23 +121,23 @@ class Orderdetail extends DBElement /** * Get the supplier part-nr. * - * @return string the part-nr. + * @return string the part-nr. */ - public function getSupplierPartNr() : string + public function getSupplierPartNr(): string { return $this->supplierpartnr; } /** - * Get if this orderdetails is obsolete + * Get if this orderdetails is obsolete. * * "Orderdetails is obsolete" means that the part with that supplier-part-nr * is no longer available from the supplier of that orderdetails. * - * @return boolean * true if this part is obsolete at that supplier - * * false if this part isn't obsolete at that supplier + * @return bool * true if this part is obsolete at that supplier + * * false if this part isn't obsolete at that supplier */ - public function getObsolete() : bool + public function getObsolete(): bool { return (bool) $this->obsolete; } @@ -150,11 +148,11 @@ class Orderdetail extends DBElement * @param $no_automatic_url bool Set this to true, if you only want to get the local set product URL for this Orderdetail * and not a automatic generated one, based from the Supplier * - * @return string the link to the article + * @return string the link to the article */ - public function getSupplierProductUrl(bool $no_automatic_url = false) : string + public function getSupplierProductUrl(bool $no_automatic_url = false): string { - if ($no_automatic_url || $this->supplierpartnr !== '') { + if ($no_automatic_url || '' !== $this->supplierpartnr) { return $this->supplierpartnr; } @@ -162,41 +160,41 @@ class Orderdetail extends DBElement } /** - * Get all pricedetails + * Get all pricedetails. * - * @return Pricedetails[] all pricedetails as a one-dimensional array of Pricedetails objects, - * sorted by minimum discount quantity + * @return Pricedetails[] all pricedetails as a one-dimensional array of Pricedetails objects, + * sorted by minimum discount quantity * * @throws Exception if there was an error */ - public function getPricedetails() : array + public function getPricedetails(): array { return $this->pricedetails; } /** - * Get the price for a specific quantity + * Get the price for a specific quantity. * - * @param boolean $as_money_string * if true, this method returns a money string incl. currency - * * if false, this method returns the price as float - * @param integer $quantity this is the quantity to choose the correct pricedetails - * @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price - * * If you pass NULL, the number from $quantity will be used + * @param bool $as_money_string * if true, this method returns a money string incl. currency + * * if false, this method returns the price as float + * @param int $quantity this is the quantity to choose the correct pricedetails + * @param int|null $multiplier * This is the multiplier which will be applied to every single price + * * If you pass NULL, the number from $quantity will be used * - * @return float|null|string float: the price as a float number (if "$as_money_string == false") - * * null: if there are no prices and "$as_money_string == false" - * * string: the price as a string incl. currency (if "$as_money_string == true") + * @return float|string|null float: the price as a float number (if "$as_money_string == false") + * * null: if there are no prices and "$as_money_string == false" + * * string: the price as a string incl. currency (if "$as_money_string == true") * * @throws Exception if there are no pricedetails for the choosed quantity - * (for example, there are only one pricedetails with the minimum discount quantity '10', - * but the choosed quantity is '5' --> the price for 5 parts is not defined!) + * (for example, there are only one pricedetails with the minimum discount quantity '10', + * but the choosed quantity is '5' --> the price for 5 parts is not defined!) * @throws Exception if there was an error * * @see floatToMoneyString() */ public function getPrice(bool $as_money_string = false, int $quantity = 1, $multiplier = null) { - /** + /* if (($quantity == 0) && ($multiplier === null)) { if ($as_money_string) { return floatToMoneyString(0); @@ -245,12 +243,11 @@ class Orderdetail extends DBElement *********************************************************************************/ /** - * Set the supplier ID + * Set the supplier ID. * - * @param integer $new_supplier_id the ID of the new supplier - + * @param int $new_supplier_id the ID of the new supplier */ - public function setSupplierId(int $new_supplier_id) : self + public function setSupplierId(int $new_supplier_id): self { throw new \Exception('Not implemented yet!'); //TODO; @@ -261,29 +258,31 @@ class Orderdetail extends DBElement /** * Set the supplier part-nr. * - * @param string $new_supplierpartnr the new supplier-part-nr - * + * @param string $new_supplierpartnr the new supplier-part-nr */ - public function setSupplierpartnr(string $new_supplierpartnr) : self + public function setSupplierpartnr(string $new_supplierpartnr): self { $this->supplierpartnr = $new_supplierpartnr; + return $this; } /** - * Set if the part is obsolete at the supplier of that orderdetails + * Set if the part is obsolete at the supplier of that orderdetails. * - * @param boolean $new_obsolete true means that this part is obsolete + * @param bool $new_obsolete true means that this part is obsolete */ - public function setObsolete(bool $new_obsolete) : self + public function setObsolete(bool $new_obsolete): self { $this->obsolete = $new_obsolete; + return $this; } /** * Sets the custom product supplier URL for this order detail. * Set this to "", if the function getSupplierProductURL should return the automatic generated URL. + * * @param $new_url string The new URL for the supplier URL. */ public function setSupplierProductUrl(string $new_url) @@ -292,4 +291,4 @@ class Orderdetail extends DBElement return $this; } -} \ No newline at end of file +} diff --git a/src/Entity/Part.php b/src/Entity/Part.php index b8d7f68f..73931e06 100644 --- a/src/Entity/Part.php +++ b/src/Entity/Part.php @@ -1,10 +1,11 @@ -getID()); + return 'P'.sprintf('%06d', $this->getID()); } - /********************************************************************************* * Getters ********************************************************************************/ @@ -227,9 +222,9 @@ class Part extends AttachmentContainingDBElement * Get the description string like it is saved in the database. * This can contain BBCode, it is not parsed yet. * - * @return string the description + * @return string the description */ - public function getDescription() : string + public function getDescription(): string { return htmlspecialchars($this->description); } @@ -238,28 +233,31 @@ class Part extends AttachmentContainingDBElement * Get the count of parts which are in stock. * When the instock is unkown, then Part::INSTOCK_UNKNOWN is returned. * - * @return int count of parts which are in stock + * @return int count of parts which are in stock */ - public function getInstock() : int + public function getInstock(): int { return $this->instock; } /** * Check if the value of the Instock is unknown. + * * @return bool True, if the value of the instock is unknown. */ - public function isInstockUnknown() : bool + public function isInstockUnknown(): bool { return $this->instock <= static::INSTOCK_UNKNOWN; - }/** @noinspection ReturnTypeCanBeDeclaredInspection */ + } + + /** @noinspection ReturnTypeCanBeDeclaredInspection */ /** - * Get the count of parts which must be in stock at least + * Get the count of parts which must be in stock at least. * - * @return integer count of parts which must be in stock at least + * @return int count of parts which must be in stock at least */ - public function getMinInstock() : int + public function getMinInstock(): int { return $this->mininstock; } @@ -267,32 +265,31 @@ class Part extends AttachmentContainingDBElement /** * Get the comment associated with this part. * - * @return string The raw/unparsed comment + * @return string The raw/unparsed comment */ - public function getComment() : string + public function getComment(): string { - return htmlspecialchars($this->comment); } /** - * Get if this part is obsolete + * Get if this part is obsolete. * * A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". * If a part has no orderdetails, the part isn't marked as obsolete. * - * @return boolean true, if this part is obsolete. false, if this part isn't obsolete + * @return bool true, if this part is obsolete. false, if this part isn't obsolete */ - public function isObsolete() : bool + public function isObsolete(): bool { $all_orderdetails = $this->getOrderdetails(); - if (count($all_orderdetails) === 0) { + if (0 === count($all_orderdetails)) { return false; } foreach ($all_orderdetails as $orderdetails) { - if (! $orderdetails->getObsolete()) { + if (!$orderdetails->getObsolete()) { return false; } } @@ -301,12 +298,12 @@ class Part extends AttachmentContainingDBElement } /** - * Get if this part is visible + * Get if this part is visible. * - * @return boolean true if this part is visible - * false if this part isn't visible + * @return bool true if this part is visible + * false if this part isn't visible */ - public function isVisible() : bool + public function isVisible(): bool { return $this->visible; } @@ -315,21 +312,21 @@ class Part extends AttachmentContainingDBElement * Get if this part is a favorite. * * @return bool * true if this part is a favorite - * * false if this part is not a favorite. + * * false if this part is not a favorite. */ - public function isFavorite() : bool + public function isFavorite(): bool { return $this->favorite; } /** - * Get the selected order orderdetails of this part + * Get the selected order orderdetails of this part. + * + * @return Orderdetail the selected order orderdetails * - * @return Orderdetail the selected order orderdetails - * @return NULL if there is no order supplier selected * @throws Exception */ - public function getOrderOrderdetails() : ?Orderdetail + public function getOrderOrderdetails(): ?Orderdetail { //TODO /* @@ -342,37 +339,37 @@ class Part extends AttachmentContainingDBElement } /** - * Get the order quantity of this part + * Get the order quantity of this part. * - * @return integer the order quantity + * @return int the order quantity */ - public function getOrderQuantity() : int + public function getOrderQuantity(): int { return $this->order_quantity; } /** - * Get the minimum quantity which should be ordered + * Get the minimum quantity which should be ordered. * - * @param boolean $with_devices * if true, all parts from devices which are marked as "to order" will be included in the calculation - * * if false, only max(mininstock - instock, 0) will be returned + * @param bool $with_devices * if true, all parts from devices which are marked as "to order" will be included in the calculation + * * if false, only max(mininstock - instock, 0) will be returned + * + * @return int the minimum order quantity * - * @return integer the minimum order quantity * @throws Exception */ - public function getMinOrderQuantity(bool $with_devices = true) : int + public function getMinOrderQuantity(bool $with_devices = true): int { //TODO throw new \Exception('Not implemented yet...'); - - /** + /* if ($with_devices) { $count_must_order = 0; // for devices with "order_only_missing_parts == false" $count_should_order = 0; // for devices with "order_only_missing_parts == true" $deviceparts = DevicePart::getOrderDeviceParts($this->database, $this->current_user, $this->log, $this->getID()); foreach ($deviceparts as $devicepart) { /** @var $devicepart DevicePart */ - /** @var $device Device */ /** + /* @var $device Device */ /* $device = $devicepart->getDevice(); if ($device->getOrderOnlyMissingParts()) { $count_should_order += $device->getOrderQuantity() * $devicepart->getMountQuantity(); @@ -388,21 +385,22 @@ class Part extends AttachmentContainingDBElement } /** - * Check if this part is marked for manual ordering + * Check if this part is marked for manual ordering. * - * @return boolean the "manual_order" attribute + * @return bool the "manual_order" attribute */ - public function isMarkedForManualOrder() : bool + public function isMarkedForManualOrder(): bool { return $this->manual_order; } /** * Check if the part is automatically marked for Ordering, because the instock value is smaller than the min instock value. - * This is called automatic ordering + * This is called automatic ordering. + * * @return bool True, if the part should be ordered. */ - public function isAutoOrdered() : bool + public function isAutoOrdered(): bool { //Parts with negative instock never gets ordered. if ($this->getInstock() < 0) { @@ -419,15 +417,15 @@ class Part extends AttachmentContainingDBElement * * @param * - * @return string the link to the article + * @return string the link to the article */ - public function getManufacturerProductUrl() : string + public function getManufacturerProductUrl(): string { - if ($this->manufacturer_product_url !== '') { + if ('' !== $this->manufacturer_product_url) { return $this->manufacturer_product_url; } - if ($this->getManufacturer() !== null) { + if (null !== $this->getManufacturer()) { return $this->getManufacturer()->getAutoProductUrl($this->name); } @@ -436,77 +434,74 @@ class Part extends AttachmentContainingDBElement /** * Similar to getManufacturerProductUrl, but here only the database value is returned. + * * @return string The manufacturer url saved in DB for this part. */ - public function getOwnProductURL() : string + public function getOwnProductURL(): string { return $this->manufacturer_product_url; } /** - * Get the category of this part + * Get the category of this part. * * There is always a category, for each part! * - * @return Category the category of this part + * @return Category the category of this part */ - public function getCategory() : Category + public function getCategory(): Category { return $this->category; } /** - * Get the footprint of this part (if there is one) + * Get the footprint of this part (if there is one). * - * @return Footprint the footprint of this part (if there is one) - * @return NULL if this part has no footprint + * @return Footprint the footprint of this part (if there is one) */ - public function getFootprint() : ?Footprint + public function getFootprint(): ?Footprint { return $this->footprint; } /** - * Get the storelocation of this part (if there is one) + * Get the storelocation of this part (if there is one). * - * @return Storelocation the storelocation of this part (if there is one) - * @return NULL if this part has no storelocation + * @return Storelocation the storelocation of this part (if there is one) */ - public function getStorelocation() : ?Storelocation + public function getStorelocation(): ?Storelocation { return $this->storelocation; } /** - * Get the manufacturer of this part (if there is one) + * Get the manufacturer of this part (if there is one). * - * @return Manufacturer the manufacturer of this part (if there is one) - * @return NULL if this part has no manufacturer + * @return Manufacturer the manufacturer of this part (if there is one) */ - public function getManufacturer() : ?Manufacturer + public function getManufacturer(): ?Manufacturer { return $this->manufacturer; } /** - * Get the master picture "Attachement"-object of this part (if there is one) + * Get the master picture "Attachement"-object of this part (if there is one). * - * @return Attachment the master picture Attachement of this part (if there is one) - * @return NULL if this part has no master picture + * @return Attachment the master picture Attachement of this part (if there is one) */ - public function getMasterPictureAttachement() : ?Attachment + public function getMasterPictureAttachement(): ?Attachment { return $this->master_picture_attachment; } /** - * Get all orderdetails of this part + * Get all orderdetails of this part. * - * @param boolean $hide_obsolete If true, obsolete orderdetails will NOT be returned + * @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned * - * @return Orderdetails[] * all orderdetails as a one-dimensional array of Orderdetails objects - * (empty array if there are no ones) - * * the array is sorted by the suppliers names / minimum order quantity + * @return Orderdetails[] * all orderdetails as a one-dimensional array of Orderdetails objects + * (empty array if there are no ones) + * * the array is sorted by the suppliers names / minimum order quantity * * @throws Exception if there was an error */ @@ -519,6 +514,7 @@ class Part extends AttachmentContainingDBElement unset($orderdetails[$key]); } } + return $orderdetails; } else { return $this->orderdetails; @@ -526,44 +522,44 @@ class Part extends AttachmentContainingDBElement } /** - * Get all devices which uses this part + * Get all devices which uses this part. * - * @return Device[] * all devices which uses this part as a one-dimensional array of Device objects - * (empty array if there are no ones) + * @return Device[] * all devices which uses this part as a one-dimensional array of Device objects + * (empty array if there are no ones) * * the array is sorted by the devices names * * @throws Exception if there was an error */ - public function getDevices() : array + public function getDevices(): array { return $this->devices; } /** - * Get all suppliers of this part + * Get all suppliers of this part. * * This method simply gets the suppliers of the orderdetails and prepare them.\n * You can get the suppliers as an array or as a string with individual delimeter. * - * @param boolean $object_array * if true, this method returns an array of Supplier objects - * * if false, this method returns an array of strings - * @param string|NULL $delimeter * if this is a string and "$object_array == false", - * this method returns a string with all - * supplier names, delimeted by "$delimeter" - * @param boolean $full_paths * if true and "$object_array = false", the returned - * suppliernames are full paths (path + name) - * * if true and "$object_array = false", the returned - * suppliernames are only the names (without path) - * @param boolean $hide_obsolete If true, suppliers from obsolete orderdetails will NOT be returned + * @param bool $object_array * if true, this method returns an array of Supplier objects + * * if false, this method returns an array of strings + * @param string|null $delimeter * if this is a string and "$object_array == false", + * this method returns a string with all + * supplier names, delimeted by "$delimeter" + * @param bool $full_paths * if true and "$object_array = false", the returned + * suppliernames are full paths (path + name) + * * if true and "$object_array = false", the returned + * suppliernames are only the names (without path) + * @param bool $hide_obsolete If true, suppliers from obsolete orderdetails will NOT be returned * - * @return array all suppliers as a one-dimensional array of Supplier objects - * (if "$object_array == true") - * @return array all supplier-names as a one-dimensional array of strings - * ("if $object_array == false" and "$delimeter == NULL") - * @return string a sting of all supplier names, delimeted by $delimeter - * ("if $object_array == false" and $delimeter is a string) + * @return array all suppliers as a one-dimensional array of Supplier objects + * (if "$object_array == true") + * @return array all supplier-names as a one-dimensional array of strings + * ("if $object_array == false" and "$delimeter == NULL") + * @return string a sting of all supplier names, delimeted by $delimeter + * ("if $object_array == false" and $delimeter is a string) * - * @throws Exception if there was an error + * @throws Exception if there was an error */ public function getSuppliers(bool $object_array = true, $delimeter = null, bool $full_paths = false, bool $hide_obsolete = false) { @@ -579,7 +575,7 @@ class Part extends AttachmentContainingDBElement } else { $supplier_names = array(); foreach ($suppliers as $supplier) { - /** @var Supplier $supplier */ + /* @var Supplier $supplier */ if ($full_paths) { $supplier_names[] = $supplier->getFullPath(); } else { @@ -596,19 +592,19 @@ class Part extends AttachmentContainingDBElement } /** - * Get all supplier-part-Nrs + * Get all supplier-part-Nrs. * * This method simply gets the suppliers-part-Nrs of the orderdetails and prepare them.\n * You can get the numbers as an array or as a string with individual delimeter. * - * @param string|NULL $delimeter * if this is a string, this method returns a delimeted string - * * otherwise, this method returns an array of strings - * @param boolean $hide_obsolete If true, supplierpartnrs from obsolete orderdetails will NOT be returned + * @param string|null $delimeter * if this is a string, this method returns a delimeted string + * * otherwise, this method returns an array of strings + * @param bool $hide_obsolete If true, supplierpartnrs from obsolete orderdetails will NOT be returned * - * @return array all supplierpartnrs as an array of strings (if "$delimeter == NULL") - * @return string all supplierpartnrs as a string, delimeted ba $delimeter (if $delimeter is a string) + * @return array all supplierpartnrs as an array of strings (if "$delimeter == NULL") + * @return string all supplierpartnrs as a string, delimeted ba $delimeter (if $delimeter is a string) * - * @throws Exception if there was an error + * @throws Exception if there was an error */ public function getSupplierPartNrs($delimeter = null, bool $hide_obsolete = false) { @@ -626,36 +622,36 @@ class Part extends AttachmentContainingDBElement } /** - * Get all prices of this part + * Get all prices of this part. * * This method simply gets the prices of the orderdetails and prepare them.\n * In the returned array/string there is a price for every supplier. * - * @param boolean $float_array * if true, the returned array is an array of floats - * * if false, the returned array is an array of strings - * @param string|NULL $delimeter if this is a string, this method returns a delimeted string - * instead of an array. - * @param integer $quantity this is the quantity to choose the correct priceinformation - * @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price - * * If you pass NULL, the number from $quantity will be used - * @param boolean $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned + * @param bool $float_array * if true, the returned array is an array of floats + * * if false, the returned array is an array of strings + * @param string|null $delimeter if this is a string, this method returns a delimeted string + * instead of an array. + * @param int $quantity this is the quantity to choose the correct priceinformation + * @param int|null $multiplier * This is the multiplier which will be applied to every single price + * * If you pass NULL, the number from $quantity will be used + * @param bool $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned * - * @return array all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true") - * @return array all prices as an array of strings (if "$delimeter == NULL" & "$float_array == false") - * @return string all prices as a string, delimeted by $delimeter (if $delimeter is a string) + * @return array all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true") + * @return array all prices as an array of strings (if "$delimeter == NULL" & "$float_array == false") + * @return string all prices as a string, delimeted by $delimeter (if $delimeter is a string) * * If there are orderdetails without prices, for these orderdetails there * will be a "NULL" in the returned float array (or a "-" in the string array)!! * (This is needed for the HTML output, if there are all orderdetails and prices listed.) * - * @throws Exception if there was an error + * @throws Exception if there was an error */ public function getPrices(bool $float_array = false, $delimeter = null, int $quantity = 1, $multiplier = null, bool $hide_obsolete = false) { $prices = array(); foreach ($this->getOrderdetails($hide_obsolete) as $details) { - $prices[] = $details->getPrice(! $float_array, $quantity, $multiplier); + $prices[] = $details->getPrice(!$float_array, $quantity, $multiplier); } if (\is_string($delimeter)) { @@ -666,23 +662,22 @@ class Part extends AttachmentContainingDBElement } /** - * Get the average price of all orderdetails + * Get the average price of all orderdetails. * * With the $multiplier you're able to multiply the price before it will be returned. * This is useful if you want to have the price as a string with currency, but multiplied with a factor. * - * @param boolean $as_money_string * if true, the retruned value will be a string incl. currency, - * ready to print it out. See float_to_money_string(). - * * if false, the returned value is a float - * @param integer $quantity this is the quantity to choose the correct priceinformations - * @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price - * * If you pass NULL, the number from $quantity will be used + * @param bool $as_money_string * if true, the retruned value will be a string incl. currency, + * ready to print it out. See float_to_money_string(). + * * if false, the returned value is a float + * @param int $quantity this is the quantity to choose the correct priceinformations + * @param int|null $multiplier * This is the multiplier which will be applied to every single price + * * If you pass NULL, the number from $quantity will be used * - * @return float price (if "$as_money_string == false") - * @return NULL if there are no prices for this part and "$as_money_string == false" - * @return string price with currency (if "$as_money_string == true") + * @return float price (if "$as_money_string == false") + * @return string price with currency (if "$as_money_string == true") * - * @throws Exception if there was an error + * @throws Exception if there was an error */ public function getAveragePrice(bool $as_money_string = false, int $quantity = 1, $multiplier = null) { @@ -691,9 +686,9 @@ class Part extends AttachmentContainingDBElement $count = 0; foreach ($prices as $price) { - if ($price !== null) { + if (null !== $price) { $average_price += $price; - $count++; + ++$count; } } @@ -709,29 +704,28 @@ class Part extends AttachmentContainingDBElement } /** - * Get the filename of the master picture (absolute path from filesystem root) + * Get the filename of the master picture (absolute path from filesystem root). * - * @param boolean $use_footprint_filename * if true, and this part has no picture, this method - * will return the filename of its footprint (if available) - * * if false, and this part has no picture, - * this method will return NULL + * @param bool $use_footprint_filename * if true, and this part has no picture, this method + * will return the filename of its footprint (if available) + * * if false, and this part has no picture, + * this method will return NULL * - * @return string the whole path + filename from filesystem root as a UNIX path (with slashes) - * @return NULL if there is no picture + * @return string the whole path + filename from filesystem root as a UNIX path (with slashes) * * @throws \Exception if there was an error */ - public function getMasterPictureFilename(bool $use_footprint_filename = false) : ?string + public function getMasterPictureFilename(bool $use_footprint_filename = false): ?string { $master_picture = $this->getMasterPictureAttachement(); // returns an Attachement-object - if ($master_picture !== null) { + if (null !== $master_picture) { return $master_picture->getFilename(); } if ($use_footprint_filename) { $footprint = $this->getFootprint(); - if ($footprint !== null) { + if (null !== $footprint) { return $footprint->getFilename(); } } @@ -741,15 +735,18 @@ class Part extends AttachmentContainingDBElement /** * Parses the selected fields and extract Properties of the part. + * * @param bool $use_description Use the description field for parsing - * @param bool $use_comment Use the comment field for parsing - * @param bool $use_name Use the name field for parsing - * @param bool $force_output Properties are parsed even if properties are disabled. + * @param bool $use_comment Use the comment field for parsing + * @param bool $use_name Use the name field for parsing + * @param bool $force_output Properties are parsed even if properties are disabled. + * * @return array A array of PartProperty objects. * @return array If Properties are disabled or nothing was detected, then an empty array is returned. + * * @throws Exception */ - public function getProperties(bool $use_description = true, bool $use_comment = true, bool $use_name = true, bool $force_output = false) : array + public function getProperties(bool $use_description = true, bool $use_comment = true, bool $use_name = true, bool $force_output = false): array { //TODO throw new \Exception('Not implemented yet!'); @@ -783,11 +780,13 @@ class Part extends AttachmentContainingDBElement /** * Returns a loop (array) of the array representations of the properties of this part. + * * @param bool $use_description Use the description field for parsing - * @param bool $use_comment Use the comment field for parsing + * @param bool $use_comment Use the comment field for parsing + * * @return array A array of arrays with the name and value of the properties. */ - public function getPropertiesLoop(bool $use_description = true, bool $use_comment = true, bool $use_name = true) : array + public function getPropertiesLoop(bool $use_description = true, bool $use_comment = true, bool $use_name = true): array { //TODO throw new \Exception('Not implemented yet!'); @@ -796,6 +795,7 @@ class Part extends AttachmentContainingDBElement /* @var PartProperty $property */ $arr[] = $property->getArray(true); } + return $arr; } @@ -812,26 +812,27 @@ class Part extends AttachmentContainingDBElement *********************************************************************************/ /** - * Set the description + * Set the description. * - * @param string $new_description the new description + * @param string $new_description the new description * * @return self */ - public function setDescription(?string $new_description) : self + public function setDescription(?string $new_description): self { $this->description = $new_description; + return $this; } /** - * Set the count of parts which are in stock + * Set the count of parts which are in stock. * - * @param integer $new_instock the new count of parts which are in stock + * @param int $new_instock the new count of parts which are in stock * * @return self */ - public function setInstock(int $new_instock, $comment = null) : self + public function setInstock(int $new_instock, $comment = null): self { //Assert::natural($new_instock, 'New instock must be positive. Got: %s'); @@ -858,28 +859,29 @@ class Part extends AttachmentContainingDBElement * If the instock is not unknown and you pass false, nothing is changed. * * @param bool $new_unknown Set this to true if the instock should be marked as unknown. + * * @return Part */ - public function setInstockUnknown(bool $new_unknown) : self + public function setInstockUnknown(bool $new_unknown): self { - if($new_unknown === true) { + if (true === $new_unknown) { $this->instock = self::INSTOCK_UNKNOWN; - } else if ($this->isInstockUnknown()) { + } elseif ($this->isInstockUnknown()) { $this->setInstock(0); } return $this; - } /** * Withdrawal the given number of parts. + * * @param $count int The number of parts which should be withdrawan. * @param $comment string A comment that should be associated with the withdrawal. * * @return self */ - public function withdrawalParts(int $count, $comment = null) : self + public function withdrawalParts(int $count, $comment = null): self { //Assert::greaterThan($count,0, 'Count of withdrawn parts must be greater 0! Got %s!'); //Assert::greaterThan($count, $this->instock, 'You can not withdraw more parts, than there are existing!'); @@ -906,12 +908,13 @@ class Part extends AttachmentContainingDBElement /** * Add the given number of parts. + * * @param $count int The number of parts which should be withdrawan. * @param $comment string A comment that should be associated with the withdrawal. * * @return self */ - public function addParts(int $count, string $comment = null) : self + public function addParts(int $count, string $comment = null): self { //Assert::greaterThan($count, 0, 'Count of added parts must be greater zero! Got %s.'); @@ -938,27 +941,29 @@ class Part extends AttachmentContainingDBElement } /** - * Set the count of parts which should be in stock at least + * Set the count of parts which should be in stock at least. + * + * @param int $new_mininstock the new count of parts which should be in stock at least * - * @param integer $new_mininstock the new count of parts which should be in stock at least * @return self */ - public function setMinInstock(int $new_mininstock) : self + public function setMinInstock(int $new_mininstock): self { //Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.'); $this->mininstock = $new_mininstock; + return $this; } /** - * Set the comment + * Set the comment. * - * @param string $new_comment the new comment + * @param string $new_comment the new comment * * @return self */ - public function setComment(string $new_comment) : self + public function setComment(string $new_comment): self { $this->comment = $new_comment; @@ -966,24 +971,23 @@ class Part extends AttachmentContainingDBElement } /** - * Set the "manual_order" attribute + * Set the "manual_order" attribute. * - * @param boolean $new_manual_order the new "manual_order" attribute - * @param integer $new_order_quantity the new order quantity - * @param integer|NULL $new_order_orderdetails_id * the ID of the new order orderdetails - * * or Zero for "no order orderdetails" - * * or NULL for automatic order orderdetails - * (if the part has exactly one orderdetails, - * set this orderdetails as order orderdetails. - * Otherwise, set "no order orderdetails") + * @param bool $new_manual_order the new "manual_order" attribute + * @param int $new_order_quantity the new order quantity + * @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails + * * or Zero for "no order orderdetails" + * * or NULL for automatic order orderdetails + * (if the part has exactly one orderdetails, + * set this orderdetails as order orderdetails. + * Otherwise, set "no order orderdetails") * * @return self */ - public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null) : self + public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null): self { //Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); - $this->manual_order = $new_manual_order; //TODO; @@ -994,14 +998,14 @@ class Part extends AttachmentContainingDBElement } /** - * Set the ID of the order orderdetails + * Set the ID of the order orderdetails. * - * @param integer|NULL $new_order_orderdetails_id * the new order orderdetails ID - * * Or, to remove the orderdetails, pass a NULL + * @param int|null $new_order_orderdetails_id * the new order orderdetails ID + * * Or, to remove the orderdetails, pass a NULL * * @return self */ - public function setOrderOrderdetailsID($new_order_orderdetails_id) : self + public function setOrderOrderdetailsID($new_order_orderdetails_id): self { //TODO throw new \Exception('Not implemented yet...'); @@ -1010,13 +1014,13 @@ class Part extends AttachmentContainingDBElement } /** - * Set the order quantity + * Set the order quantity. * - * @param integer $new_order_quantity the new order quantity + * @param int $new_order_quantity the new order quantity * * @return self */ - public function setOrderQuantity(int $new_order_quantity) : self + public function setOrderQuantity(int $new_order_quantity): self { //Assert::greaterThan($new_order_quantity,0, 'The new order quantity must be greater zero. Got %s!'); @@ -1026,16 +1030,16 @@ class Part extends AttachmentContainingDBElement } /** - * Set the category of this Part + * Set the category of this Part. * * Every part must have a valid category (in contrast to the * attributes "footprint", "storelocation", ...)! * - * @param Category $category The new category of this part + * @param Category $category The new category of this part * * @return self */ - public function setCategory(Category $category) : self + public function setCategory(Category $category): self { $this->category = $category; @@ -1046,25 +1050,26 @@ class Part extends AttachmentContainingDBElement * Set the new Footprint of this Part. * * @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have - * a footprint. + * a footprint. + * * @return self */ - public function setFootprint(?Footprint $new_footprint) : self + public function setFootprint(?Footprint $new_footprint): self { $this->footprint = $new_footprint; return $this; } - /** * Set the new store location of this part. * * @param Storelocation|null $new_storelocation The new Storelocation of this part. Set to null, if this part should - * not have a storelocation. + * not have a storelocation. + * * @return Part */ - public function setStorelocation(?Storelocation $new_storelocation) : self + public function setStorelocation(?Storelocation $new_storelocation): self { $this->storelocation = $new_storelocation; @@ -1075,10 +1080,11 @@ class Part extends AttachmentContainingDBElement * Sets the new manufacturer of this part. * * @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should - * not have a manufacturer. + * not have a manufacturer. + * * @return Part */ - public function setManufacturer(?Manufacturer $new_manufacturer) : self + public function setManufacturer(?Manufacturer $new_manufacturer): self { $this->manufacturer = $new_manufacturer; @@ -1087,12 +1093,13 @@ class Part extends AttachmentContainingDBElement /** * Set the favorite status for this part. + * * @param $new_favorite_status bool The new favorite status, that should be applied on this part. * Set this to true, when the part should be a favorite. * * @return self */ - public function setFavorite(bool $new_favorite_status) : self + public function setFavorite(bool $new_favorite_status): self { $this->favorite = $new_favorite_status; @@ -1101,10 +1108,12 @@ class Part extends AttachmentContainingDBElement /** * Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer. + * * @param string $new_url The new url + * * @return self */ - public function setManufacturerProductURL(string $new_url) : self + public function setManufacturerProductURL(string $new_url): self { $this->manufacturer_product_url = $new_url; @@ -1112,23 +1121,21 @@ class Part extends AttachmentContainingDBElement } /** - * Set the ID of the master picture Attachement + * Set the ID of the master picture Attachement. * - * @param integer|NULL $new_master_picture_attachement_id * the ID of the Attachement object of the master picture - * * NULL means "no master picture" + * @param int|null $new_master_picture_attachement_id * the ID of the Attachement object of the master picture + * * NULL means "no master picture" * * @throws Exception if the new ID is not valid * @throws Exception if there was an error * * @return self */ - public function setMasterPictureAttachementID($new_master_picture_attachement_id) : self + public function setMasterPictureAttachementID($new_master_picture_attachement_id): self { //TODO throw new \Exception('Not implemented yet!'); return $this; } - - -} \ No newline at end of file +} diff --git a/src/Entity/PartsContainingDBElement.php b/src/Entity/PartsContainingDBElement.php index 22b80077..7ec54b6a 100644 --- a/src/Entity/PartsContainingDBElement.php +++ b/src/Entity/PartsContainingDBElement.php @@ -1,9 +1,10 @@ -$permission_name; @@ -275,19 +270,21 @@ class PermissionsEmbed /** * Returns the value of the operation for the given permission. + * * @param string $permission_name The name of the permission, for which the operation should be returned. - * @param int $bit_n The (lower) bit number of the bit pair for the operation. + * @param int $bit_n The (lower) bit number of the bit pair for the operation. + * * @return bool|null The value of the operation. True, if the given operation is allowed, false if disallowed - * and null if it should inherit from parent. + * and null if it should inherit from parent. */ - public function getPermissionValue(string $permission_name, int $bit_n) : ?bool + public function getPermissionValue(string $permission_name, int $bit_n): ?bool { $value = $this->getBitValue($permission_name, $bit_n); - if ($value == self::ALLOW) { + if (self::ALLOW == $value) { return true; } - if($value == self::DISALLOW) { + if (self::DISALLOW == $value) { return false; } else { return null; @@ -296,14 +293,16 @@ class PermissionsEmbed /** * Reads a bit pair from $data. + * * @param $data int The data from where the bits should be extracted from. * @param $n int The number of the lower bit (of the pair) that should be read. Starting from zero. + * * @return int The value of the bit pair. */ final protected static function readBitPair(int $data, int $n): int { - Assert::lessThanEq($n,31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); - if ($n % 2 !== 0) { + Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); + if (0 !== $n % 2) { throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!'); } @@ -313,24 +312,26 @@ class PermissionsEmbed /** * Writes a bit pair in the given $data and returns it. + * * @param $data int The data which should be modified. * @param $n int The number of the lower bit of the pair which should be written. * @param $new int The new value of the pair. + * * @return int The new data with the modified pair. */ - final protected static function writeBitPair(int $data, int $n, int $new) : int + final protected static function writeBitPair(int $data, int $n, int $new): int { - Assert::lessThanEq($n,31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); + Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); Assert::lessThanEq($new, 3, '$new must be smaller than 3, because a bit pair is written! Got %s.'); - if ($n % 2 !== 0) { + if (0 !== $n % 2) { throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!'); } $mask = 0b11 << $n; //Mask all bits that should be writen $newval = $new << $n; //The new value. $data = ($data & ~$mask) | ($newval & $mask); + return $data; } - -} \ No newline at end of file +} diff --git a/src/Entity/Pricedetail.php b/src/Entity/Pricedetail.php index c441c48d..f30d91a7 100644 --- a/src/Entity/Pricedetail.php +++ b/src/Entity/Pricedetail.php @@ -1,10 +1,11 @@ -orderdetail; } /** - * Get the price + * Get the price. * - * @param boolean $as_money_string * if true, this method returns a money string incl. currency - * * if false, this method returns the price as float - * @param integer $multiplier The returned price (float or string) will be multiplied - * with this multiplier. + * @param bool $as_money_string * if true, this method returns a money string incl. currency + * * if false, this method returns the price as float + * @param int $multiplier The returned price (float or string) will be multiplied + * with this multiplier. * * You will get the price for $multiplier parts. If you want the price which is stored * in the database, you have to pass the "price_related_quantity" count as $multiplier. * - * @return float the price as a float number (if "$as_money_string == false") - * @return string the price as a string incl. currency (if "$as_money_string == true") + * @return float the price as a float number (if "$as_money_string == false") + * @return string the price as a string incl. currency (if "$as_money_string == true") * * @see floatToMoneyString() */ @@ -129,30 +124,30 @@ class Pricedetail extends DBElement } /** - * Get the price related quantity + * Get the price related quantity. * * This is the quantity, for which the price is valid. * - * @return integer the price related quantity + * @return int the price related quantity * * @see Pricedetails::setPriceRelatedQuantity() */ - public function getPriceRelatedQuantity() : int + public function getPriceRelatedQuantity(): int { return $this->price_related_quantity; } /** - * Get the minimum discount quantity + * Get the minimum discount quantity. * * "Minimum discount quantity" means the minimum order quantity for which the price * of this orderdetails is valid. * - * @return integer the minimum discount quantity + * @return int the minimum discount quantity * * @see Pricedetails::setMinDiscountQuantity() */ - public function getMinDiscountQuantity() : int + public function getMinDiscountQuantity(): int { return $this->min_discount_quantity; } @@ -164,9 +159,9 @@ class Pricedetail extends DBElement *********************************************************************************/ /** - * Set the price + * Set the price. * - * @param float $new_price the new price as a float number + * @param float $new_price the new price as a float number * * * This is the price for "price_related_quantity" parts!! * * Example: if "price_related_quantity" is '10', @@ -174,7 +169,7 @@ class Pricedetail extends DBElement * * @return self */ - public function setPrice(float $new_price) : self + public function setPrice(float $new_price): self { Assert::natural($new_price, 'The new price must be positive! Got %s!'); @@ -184,7 +179,7 @@ class Pricedetail extends DBElement } /** - * Set the price related quantity + * Set the price related quantity. * * This is the quantity, for which the price is valid. * @@ -192,13 +187,12 @@ class Pricedetail extends DBElement * If 100pcs costs 20$, you have to set the price to 20$ and the price related * quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically. * - * @param integer $new_price_related_quantity the price related quantity + * @param int $new_price_related_quantity the price related quantity * * @return self */ - public function setPriceRelatedQuantity(int $new_price_related_quantity) : self + public function setPriceRelatedQuantity(int $new_price_related_quantity): self { - Assert::greaterThan($new_price_related_quantity, 0, 'The new price related quantity must be greater zero! Got %s.'); @@ -208,7 +202,7 @@ class Pricedetail extends DBElement } /** - * Set the minimum discount quantity + * Set the minimum discount quantity. * * "Minimum discount quantity" means the minimum order quantity for which the price * of this orderdetails is valid. This way, you're able to use different prices @@ -222,11 +216,11 @@ class Pricedetail extends DBElement * (Each of this examples would be an own Pricedetails-object. * So the orderdetails would have three Pricedetails for one supplier.) * - * @param integer $new_min_discount_quantity the minimum discount quantity + * @param int $new_min_discount_quantity the minimum discount quantity * * @return self */ - public function setMinDiscountQuantity(int $new_min_discount_quantity) : self + public function setMinDiscountQuantity(int $new_min_discount_quantity): self { Assert::greaterThan($new_min_discount_quantity, 0, 'The new minimum discount quantity must be greater zero! Got %s.'); @@ -236,16 +230,14 @@ class Pricedetail extends DBElement return $this; } - - - /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. + * * @return string The ID as a string; */ public function getIDString(): string { - return 'PD' . sprintf('%06d', $this->getID()); + return 'PD'.sprintf('%06d', $this->getID()); } -} \ No newline at end of file +} diff --git a/src/Entity/Storelocation.php b/src/Entity/Storelocation.php index e845fadd..a0f43f23 100644 --- a/src/Entity/Storelocation.php +++ b/src/Entity/Storelocation.php @@ -1,11 +1,11 @@ -is_full; } @@ -93,29 +91,31 @@ class Storelocation extends PartsContainingDBElement *********************************************************************************/ /** - * Change the "is full" attribute of this storelocation + * Change the "is full" attribute of this storelocation. * * "is_full" = true means that there is no more space in this storelocation. * This attribute is only for information, it has no effect. * - * @param boolean $new_is_full * true means that the storelocation is full - * * false means that the storelocation isn't full + * @param bool $new_is_full * true means that the storelocation is full + * * false means that the storelocation isn't full * * @throws Exception if there was an error */ - public function setIsFull(bool $new_is_full) : self + public function setIsFull(bool $new_is_full): self { $this->is_full = $new_is_full; + return $this; } /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. + * * @return string The ID as a string; */ public function getIDString(): string { - return 'L' . sprintf('%06d', $this->getID()); + return 'L'.sprintf('%06d', $this->getID()); } -} \ No newline at end of file +} diff --git a/src/Entity/StructuralDBElement.php b/src/Entity/StructuralDBElement.php index 059dcba2..6fa0cf3d 100644 --- a/src/Entity/StructuralDBElement.php +++ b/src/Entity/StructuralDBElement.php @@ -1,9 +1,10 @@ -getID() == null) { // this is the root node + if (null == $this->getID()) { // this is the root node return false; } -//If this' parents element, is $another_element, then we are finished - return (($this->parent->getID() == $another_element->getID()) - || $this->parent->isChildOf($another_element)); //Otherwise, check recursivley + //If this' parents element, is $another_element, then we are finished + return ($this->parent->getID() == $another_element->getID()) + || $this->parent->isChildOf($another_element); //Otherwise, check recursivley } - /****************************************************************************** * * Getters @@ -125,16 +122,17 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement * * NULL means, the parent is the root node * * the parent ID of the root node is -1 */ - public function getParentID() : int + public function getParentID(): int { return $this->parent_id ?? self::ID_ROOT_ELEMENT; //Null means root element } /** * Get the parent of this element. + * * @return StructuralDBElement|null The parent element. Null if this element, does not have a parent. */ - public function getParent() : ?self + public function getParent(): ?self { return $this->parent; } @@ -142,10 +140,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement /** * Get the comment of the element. * - * @param boolean $parse_bbcode Should BBCode converted to HTML, before returning - * @return string the comment + * @param bool $parse_bbcode Should BBCode converted to HTML, before returning + * + * @return string the comment */ - public function getComment(bool $parse_bbcode = true) : string + public function getComment(bool $parse_bbcode = true): string { $val = htmlspecialchars($this->comment ?? ''); @@ -153,24 +152,23 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement } /** - * Get the level + * Get the level. * * The level of the root node is -1. * - * @return integer the level of this element (zero means a most top element - * [a subelement of the root node]) - * + * @return int the level of this element (zero means a most top element + * [a subelement of the root node]) */ - public function getLevel() : int + public function getLevel(): int { - if ($this->level === 0) { + if (0 === $this->level) { $element = $this->parent; $parent_id = $element->getParentID(); while ($parent_id > 0) { /** @var StructuralDBElement $element */ $element = $element->parent; $parent_id = $element->getParentID(); - $this->level++; + ++$this->level; } } @@ -178,22 +176,22 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement } /** - * Get the full path + * Get the full path. * - * @param string $delimeter the delimeter of the returned string + * @param string $delimeter the delimeter of the returned string * - * @return string the full path (incl. the name of this element), delimeted by $delimeter + * @return string the full path (incl. the name of this element), delimeted by $delimeter * - * @throws Exception if there was an error + * @throws Exception if there was an error */ - public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW) : string + public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string { - if (! \is_array($this->full_path_strings)) { + if (!\is_array($this->full_path_strings)) { $this->full_path_strings = array(); $this->full_path_strings[] = $this->getName(); $element = $this; - while ($element->parent != null) { + while (null != $element->parent) { $element = $element->parent; $this->full_path_strings[] = $element->getName(); } @@ -205,19 +203,19 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement } /** - * Get all subelements of this element + * Get all subelements of this element. * - * @param boolean $recursive if true, the search is recursive + * @param bool $recursive if true, the search is recursive * - * @return static[] all subelements as an array of objects (sorted by their full path) + * @return static[] all subelements as an array of objects (sorted by their full path) */ - public function getSubelements(bool $recursive) : PersistentCollection + public function getSubelements(bool $recursive): PersistentCollection { - if ($this->children == null) { + if (null == $this->children) { $this->children = new ArrayCollection(); } - if (! $recursive) { + if (!$recursive) { return $this->children; } else { $all_elements = array(); @@ -237,26 +235,29 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement ******************************************************************************/ /** - * Change the parent ID of this element + * Change the parent ID of this element. * - * @param integer|null $new_parent_id * the ID of the new parent element - * * NULL if the parent should be the root node + * @param int|null $new_parent_id * the ID of the new parent element + * * NULL if the parent should be the root node */ - public function setParentID($new_parent_id) : self + public function setParentID($new_parent_id): self { $this->parent_id = $new_parent_id; + return $this; } /** - * Set the comment + * Set the comment. + * + * @param string $new_comment the new comment * - * @param string $new_comment the new comment * @throws Exception if there was an error */ - public function setComment(string $new_comment) : self + public function setComment(string $new_comment): self { $this->comment = $new_comment; + return $this; } @@ -267,21 +268,21 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement *********************************************************************************/ /** - * Build a HTML tree with all subcategories of this element + * Build a HTML tree with all subcategories of this element. * * This method prints a