Fixed code style.

This commit is contained in:
Jan Böhmer 2020-01-04 20:24:09 +01:00
parent 1aed1d1d26
commit 9a7223a301
142 changed files with 534 additions and 716 deletions

View file

@ -95,7 +95,7 @@ class AmountFormatter
*
* @return string The formatted string
*
* @throws \InvalidArgumentException Thrown if $value is not numeric.
* @throws \InvalidArgumentException thrown if $value is not numeric
*/
public function format($value, ?MeasurementUnit $unit = null, array $options = [])
{

View file

@ -61,8 +61,6 @@ class AttachmentManager
* or is not existing.
*
* @param Attachment $attachment The attachment for which the filepath should be determined
*
* @return string|null
*/
public function toAbsoluteFilePath(Attachment $attachment): ?string
{
@ -96,7 +94,7 @@ class AttachmentManager
*
* @param Attachment $attachment The attachment for which the existence should be checked
*
* @return bool True if the file is existing.
* @return bool true if the file is existing
*/
public function isFileExisting(Attachment $attachment): bool
{
@ -111,9 +109,7 @@ class AttachmentManager
* Returns the filesize of the attachments in bytes.
* For external attachments or not existing attachments, null is returned.
*
* @param Attachment $attachment The filesize for which the filesize should be calculated.
*
* @return int|null
* @param Attachment $attachment the filesize for which the filesize should be calculated
*/
public function getFileSize(Attachment $attachment): ?int
{

View file

@ -44,11 +44,11 @@ class AttachmentPathResolver
/**
* AttachmentPathResolver constructor.
*
* @param string $project_dir The kernel that should be used to resolve the project dir.
* @param string $media_path The path where uploaded attachments should be stored.
* @param string $project_dir the kernel that should be used to resolve the project dir
* @param string $media_path the path where uploaded attachments should be stored
* @param string|null $footprints_path The path where builtin attachments are stored.
* Set to null if this ressource should be disabled.
* @param string|null $models_path Set to null if this ressource should be disabled.
* @param string|null $models_path set to null if this ressource should be disabled
*/
public function __construct(string $project_dir, string $media_path, string $secure_path, ?string $footprints_path, ?string $models_path)
{
@ -83,8 +83,6 @@ class AttachmentPathResolver
* @internal
*
* @param string|null $param_path The parameter value that should be converted to a absolute path
*
* @return string|null
*/
public function parameterToAbsolutePath(?string $param_path): ?string
{
@ -120,8 +118,6 @@ class AttachmentPathResolver
* Create an array usable for preg_replace out of an array of placeholders or pathes.
* Slashes and other chars become escaped.
* For example: '%TEST%' becomes '/^%TEST%/'.
*
* @return array
*/
protected function arrayToRegexArray(array $array): array
{
@ -139,7 +135,7 @@ class AttachmentPathResolver
* Converts an relative placeholder filepath (with %MEDIA% or older %BASE%) to an absolute filepath on disk.
* The directory separator is always /. Relative pathes are not realy possible (.. is striped).
*
* @param string $placeholder_path The filepath with placeholder for which the real path should be determined.
* @param string $placeholder_path the filepath with placeholder for which the real path should be determined
*
* @return string|null The absolute real path of the file, or null if the placeholder path is invalid
*/
@ -175,7 +171,7 @@ class AttachmentPathResolver
/**
* Converts an real absolute filepath to a placeholder version.
*
* @param string $real_path The absolute path, for which the placeholder version should be generated.
* @param string $real_path the absolute path, for which the placeholder version should be generated
* @param bool $old_version By default the %MEDIA% placeholder is used, which is directly replaced with the
* media directory. If set to true, the old version with %BASE% will be used, which is the project directory.
*
@ -213,7 +209,7 @@ class AttachmentPathResolver
/**
* The path where uploaded attachments is stored.
*
* @return string The absolute path to the media folder.
* @return string the absolute path to the media folder
*/
public function getMediaPath(): string
{
@ -224,7 +220,7 @@ class AttachmentPathResolver
* The path where secured attachments are stored. Must not be located in public/ folder, so it can only be accessed
* via the attachment controller.
*
* @return string The absolute path to the secure path.
* @return string the absolute path to the secure path
*/
public function getSecurePath(): string
{

View file

@ -51,7 +51,7 @@ class AttachmentReverseSearch
*
* @param \SplFileInfo $file The file for which is searched
*
* @return Attachment[] An list of attachments that use the given file.
* @return Attachment[] an list of attachments that use the given file
*/
public function findAttachmentsByFile(\SplFileInfo $file): array
{
@ -69,7 +69,7 @@ class AttachmentReverseSearch
* Deletes the given file if it is not used by more than $threshold attachments.
*
* @param \SplFileInfo $file The file that should be removed
* @param int $threshold The threshold used, to determine if a file should be deleted or not.
* @param int $threshold the threshold used, to determine if a file should be deleted or not
*
* @return bool True, if the file was delete. False if not.
*/

View file

@ -89,7 +89,7 @@ class AttachmentSubmitHandler
* @param Attachment $attachment The attachment that should be used for generating an attachment
* @param string $extension The extension that the new file should have (must only contain chars allowed in pathes)
*
* @return string The new filename.
* @return string the new filename
*/
public function generateAttachmentFilename(Attachment $attachment, string $extension): string
{
@ -114,7 +114,7 @@ class AttachmentSubmitHandler
* @param Attachment $attachment The attachment that should be used for
* @param bool $secure_upload True if the file path should be located in a safe location
*
* @return string The absolute path for the attachment folder.
* @return string the absolute path for the attachment folder
*/
public function generateAttachmentPath(Attachment $attachment, bool $secure_upload = false): string
{
@ -143,7 +143,7 @@ class AttachmentSubmitHandler
* Handle the submit of an attachment form.
* This function will move the uploaded file or download the URL file to server, if needed.
*
* @param Attachment $attachment The attachment that should be used for handling.
* @param Attachment $attachment the attachment that should be used for handling
* @param UploadedFile|null $file If given, that file will be moved to the right location
* @param array $options The options to use with the upload. Here you can specify that an URL should be downloaded,
* or an file should be moved to a secure location.
@ -181,8 +181,8 @@ class AttachmentSubmitHandler
/**
* Move the given attachment to secure location (or back to public folder) if needed.
*
* @param Attachment $attachment The attachment for which the file should be moved.
* @param bool $secure_location This value determines, if the attachment is moved to the secure or public folder.
* @param Attachment $attachment the attachment for which the file should be moved
* @param bool $secure_location this value determines, if the attachment is moved to the secure or public folder
*
* @return Attachment The attachment with the updated filepath
*/

View file

@ -53,7 +53,7 @@ class AttachmentURLGenerator
* Converts the absolute file path to a version relative to the public folder, that can be passed to asset
* Asset Component functions.
*
* @param string $absolute_path The absolute path that should be converted.
* @param string $absolute_path the absolute path that should be converted
* @param string|null $public_path The public path to which the relative pathes should be created.
* The path must NOT have a trailing slash!
* If this is set to null, the global public/ folder is used.
@ -78,8 +78,6 @@ class AttachmentURLGenerator
/**
* Returns a URL under which the attachment file can be viewed.
*
* @return string
*/
public function getViewURL(Attachment $attachment): string
{
@ -101,8 +99,6 @@ class AttachmentURLGenerator
/**
* Returns a URL to an thumbnail of the attachment file.
*
* @return string
*/
public function getThumbnailURL(Attachment $attachment, string $filter_name = 'thumbnail_sm'): string
{
@ -137,8 +133,6 @@ class AttachmentURLGenerator
/**
* Returns a download link to the file associated with the attachment.
*
* @return string
*/
public function getDownloadURL(Attachment $attachment): string
{

View file

@ -55,7 +55,7 @@ class BuiltinAttachmentsFinder
* The array is a list of the relative filenames using the %PLACEHOLDERS%.
* The list contains the files from all configured valid ressoureces.
*
* @return array The list of the ressources, or an empty array if an error happened.
* @return array the list of the ressources, or an empty array if an error happened
*/
public function getListOfRessources(): array
{
@ -92,9 +92,9 @@ class BuiltinAttachmentsFinder
/**
* Find all ressources which are matching the given keyword and the specified options.
*
* @param string $keyword The keyword you want to search for.
* @param string $keyword the keyword you want to search for
* @param array $options Here you can specify some options (see configureOptions for list of options)
* @param array|null $base_list The list from which should be used as base for filtering.
* @param array|null $base_list the list from which should be used as base for filtering
*
* @return array The list of the results matching the specified keyword and options
*/

View file

@ -53,9 +53,9 @@ class FileTypeFilterTools
/**
* Check if a filetype filter string is valid.
*
* @param string $filter The filter string that should be validated.
* @param string $filter the filter string that should be validated
*
* @return bool Returns true, if the string is valid.
* @return bool returns true, if the string is valid
*/
public function validateFilterString(string $filter): bool
{
@ -84,7 +84,7 @@ class FileTypeFilterTools
* Normalize a filter string. All extensions are converted to lowercase, too much whitespaces are removed.
* The filter string is not validated.
*
* @param string $filter The filter string that should be normalized.
* @param string $filter the filter string that should be normalized
*
* @return string The normalized filter string
*/
@ -131,7 +131,7 @@ class FileTypeFilterTools
/**
* Get a list of all file extensions that matches the given filter string.
*
* @param string $filter A valid filetype filter string.
* @param string $filter a valid filetype filter string
*
* @return string[] An array of allowed extensions ['txt', 'csv', 'gif']
*/
@ -166,10 +166,10 @@ class FileTypeFilterTools
/**
* Check if the given extension matches the filter.
*
* @param string $filter The filter which should be used for checking.
* @param string $extension The extension that should be checked.
* @param string $filter the filter which should be used for checking
* @param string $extension the extension that should be checked
*
* @return bool Returns true, if the extension is allowed with the given filter.
* @return bool returns true, if the extension is allowed with the given filter
*/
public function isExtensionAllowed(string $filter, string $extension): bool
{

View file

@ -38,7 +38,7 @@ class PartPreviewGenerator
* The priority is: Part MasterAttachment -> Footprint MasterAttachment -> Category MasterAttachment
* -> Storelocation Attachment -> MeasurementUnit Attachment -> ManufacturerAttachment.
*
* @param Part $part The part for which the attachments should be determined.
* @param Part $part the part for which the attachments should be determined
*
* @return Attachment[]
*/
@ -97,8 +97,6 @@ class PartPreviewGenerator
* The returned attachment is guaranteed to be existing and be a picture.
*
* @param Part $part The part for which the attachment should be determined
*
* @return Attachment|null
*/
public function getTablePreviewAttachment(Part $part): ?Attachment
{
@ -123,9 +121,9 @@ class PartPreviewGenerator
/**
* Checks if a attachment is exising and a valid picture.
*
* @param Attachment|null $attachment The attachment that should be checked.
* @param Attachment|null $attachment the attachment that should be checked
*
* @return bool True if the attachment is valid.
* @return bool true if the attachment is valid
*/
protected function isAttachmentValidPicture(?Attachment $attachment): bool
{

View file

@ -21,22 +21,21 @@
namespace App\Services;
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
class CustomEnvVarProcessor implements EnvVarProcessorInterface
{
/**
* @inheritDoc
* {@inheritdoc}
*/
public function getEnv($prefix, $name, \Closure $getEnv)
{
if ('validMailDSN' === $prefix) {
try {
$env = $getEnv($name);
return !empty($env) && $env !== 'null://null';
return !empty($env) && 'null://null' !== $env;
} catch (EnvNotFoundException $exception) {
return false;
}
@ -44,7 +43,7 @@ class CustomEnvVarProcessor implements EnvVarProcessorInterface
}
/**
* @inheritDoc
* {@inheritdoc}
*/
public static function getProvidedTypes()
{
@ -52,4 +51,4 @@ class CustomEnvVarProcessor implements EnvVarProcessorInterface
'validMailDSN' => 'bool',
];
}
}
}

View file

@ -80,9 +80,9 @@ class ElementTypeNameGenerator
*
* @param DBElement $entity The element for which the label should be generated
*
* @return string The locatlized label for the entity type.
* @return string the locatlized label for the entity type
*
* @throws EntityNotSupportedException When the passed entity is not supported.
* @throws EntityNotSupportedException when the passed entity is not supported
*/
public function getLocalizedTypeLabel(DBElement $entity): string
{
@ -107,11 +107,12 @@ class ElementTypeNameGenerator
* For example this could be something like: "Part: BC547".
* It uses getLocalizedLabel to determine the type.
*
* @param NamedDBElement $entity The entity for which the string should be generated.
* @param NamedDBElement $entity the entity for which the string should be generated
* @param bool $use_html If set to true, a html string is returned, where the type is set italic
*
* @return string The localized string
* @throws EntityNotSupportedException When the passed entity is not supported.
*
* @throws EntityNotSupportedException when the passed entity is not supported
*/
public function getTypeNameCombination(NamedDBElement $entity, bool $use_html = false): string
{

View file

@ -43,9 +43,9 @@ class EntityExporter
* Exports an Entity or an array of entities to multiple file formats.
*
* @param $entity NamedDBElement|NamedDBElement[] The element/elements[] that should be exported
* @param Request $request The request that should be used for option resolving.
* @param Request $request the request that should be used for option resolving
*
* @return Response The generated response containing the exported data.
* @return Response the generated response containing the exported data
*
* @throws \ReflectionException
*/

View file

@ -21,7 +21,6 @@
namespace App\Services;
use App\Entity\Base\DBElement;
use App\Entity\Base\StructuralDBElement;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\File\File;
@ -59,10 +58,10 @@ class EntityImporter
*
* @param string $lines The list of names seperated by \n
* @param string $class_name The name of the class for which the entities should be created
* @param StructuralDBElement|null $parent The element which will be used as parent element for new elements.
* @param array $errors An associative array containing all validation errors.
* @param StructuralDBElement|null $parent the element which will be used as parent element for new elements
* @param array $errors an associative array containing all validation errors
*
* @return StructuralDBElement[] An array containing all valid imported entities (with the type $class_name)
* @return StructuralDBElement[] An array containing all valid imported entities (with the type $class_name)
*/
public function massCreation(string $lines, string $class_name, ?StructuralDBElement $parent = null, array &$errors = []): array
{
@ -72,7 +71,7 @@ class EntityImporter
if (!is_a($class_name, StructuralDBElement::class, true)) {
throw new \InvalidArgumentException('$class_name must be a StructuralDBElement type!');
}
if ($parent !== null && !is_a($parent, $class_name)) {
if (null !== $parent && !is_a($parent, $class_name)) {
throw new \InvalidArgumentException('$parent must have the same type as specified in $class_name!');
}
@ -81,7 +80,7 @@ class EntityImporter
foreach ($names as $name) {
$name = trim($name);
if ($name === '') {
if ('' === $name) {
//Skip empty lines (StrucuralDBElements must have a name)
continue;
}
@ -108,9 +107,9 @@ class EntityImporter
* This methods deserializes the given file and saves it database.
* The imported elements will be checked (validated) before written to database.
*
* @param File $file The file that should be used for importing.
* @param string $class_name The class name of the enitity that should be imported.
* @param array $options Options for the import process.
* @param File $file the file that should be used for importing
* @param string $class_name the class name of the enitity that should be imported
* @param array $options options for the import process
*
* @return array An associative array containing an ConstraintViolationList and the entity name as key are returned,
* if an error happened during validation. When everything was successfull, the array should be empty.
@ -156,11 +155,11 @@ class EntityImporter
*
* The imported elements will NOT be validated. If you want to use the result array, you have to validate it by yourself.
*
* @param File $file The file that should be used for importing.
* @param string $class_name The class name of the enitity that should be imported.
* @param array $options Options for the import process.
* @param File $file the file that should be used for importing
* @param string $class_name the class name of the enitity that should be imported
* @param array $options options for the import process
*
* @return array An array containing the deserialized elements.
* @return array an array containing the deserialized elements
*/
public function fileToEntityArray(File $file, string $class_name, array $options = []): array
{
@ -198,8 +197,8 @@ class EntityImporter
/**
* This functions corrects the parent setting based on the children value of the parent.
*
* @param iterable $entities The list of entities that should be fixed.
* @param null $parent The parent, to which the entity should be set.
* @param iterable $entities the list of entities that should be fixed
* @param null $parent the parent, to which the entity should be set
*/
protected function correctParentEntites(iterable $entities, $parent = null)
{

View file

@ -63,7 +63,7 @@ class EntityURLGenerator
* Throws an exception if the entity class is not known to the map.
*
* @param array $map The map that should be used for determing the controller
* @param $entity mixed The entity for which the controller name should be determined.
* @param $entity mixed The entity for which the controller name should be determined
*
* @return string The name of the controller fitting the entity class
*
@ -93,13 +93,13 @@ class EntityURLGenerator
* For the given types, the [type]URL() functions are called (e.g. infoURL()).
* Not all entity class and $type combinations are supported.
*
* @param $entity mixed The element for which the page should be generated.
* @param $entity mixed The element for which the page should be generated
* @param string $type The page type. Currently supported: 'info', 'edit', 'create', 'clone', 'list'/'list_parts'
*
* @return string The link to the desired page.
* @return string the link to the desired page
*
* @throws EntityNotSupportedException Thrown if the entity is not supported for the given type.
* @throws \InvalidArgumentException Thrown if the givent type is not existing.
* @throws EntityNotSupportedException thrown if the entity is not supported for the given type
* @throws \InvalidArgumentException thrown if the givent type is not existing
*/
public function getURL($entity, string $type)
{
@ -157,7 +157,7 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where info about this entity can be viewed.
*
* @param $entity mixed The entity for which the info should be generated.
* @param $entity mixed The entity for which the info should be generated
*
* @return string The URL to the info page
*
@ -188,9 +188,9 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where this entity can be edited.
*
* @param $entity mixed The entity for which the edit link should be generated.
* @param $entity mixed The entity for which the edit link should be generated
*
* @return string The URL to the edit page.
* @return string the URL to the edit page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/
@ -217,9 +217,9 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where a entity of this type can be created.
*
* @param $entity mixed The entity for which the link should be generated.
* @param $entity mixed The entity for which the link should be generated
*
* @return string The URL to the page.
* @return string the URL to the page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/
@ -247,9 +247,9 @@ class EntityURLGenerator
* Generates an URL to a page, where a new entity can be created, that has the same informations as the
* given entity (element cloning).
*
* @param $entity mixed The entity for which the link should be generated.
* @param $entity mixed The entity for which the link should be generated
*
* @return string The URL to the page.
* @return string the URL to the page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/
@ -265,9 +265,9 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where all parts are listed, which are contained in the given element.
*
* @param $entity mixed The entity for which the link should be generated.
* @param $entity mixed The entity for which the link should be generated
*
* @return string The URL to the page.
* @return string the URL to the page
*
* @throws EntityNotSupportedException If the method is not supported for the given Entity
*/

View file

@ -21,7 +21,6 @@
namespace App\Services;
use App\Entity\Attachments\Attachment;
class FAIconGenerator
@ -42,19 +41,21 @@ class FAIconGenerator
/**
* Gets the Font awesome icon class for a file with the specified extension.
* For example 'pdf' gives you 'fa-file-pdf'
* For example 'pdf' gives you 'fa-file-pdf'.
*
* @param string $extension The file extension (without dot). Must be ASCII chars only!
*
* @return string The fontawesome class with leading 'fa-'
*/
public function fileExtensionToFAType(string $extension) : string
public function fileExtensionToFAType(string $extension): string
{
if ($extension === '') {
if ('' === $extension) {
throw new \InvalidArgumentException('You must specify an extension!');
}
//Normalize file extension
$extension = strtolower($extension);
foreach (self::EXT_MAPPING as $fa => $exts) {
if (in_array($extension, $exts, true)) {
if (\in_array($extension, $exts, true)) {
return $fa;
}
}
@ -65,13 +66,15 @@ class FAIconGenerator
/**
* Returns HTML code to show the given fontawesome icon.
* E.g. <i class="fas fa-file-text"></i>
* E.g. <i class="fas fa-file-text"></i>.
*
* @param string $icon_class The icon which should be shown (e.g. fa-file-text)
* @param string $style The style of the icon 'fas'
* @param string $options Any other css class attributes like size, etc.
* @param string $style The style of the icon 'fas'
* @param string $options Any other css class attributes like size, etc.
*
* @return string The final html
*/
public function generateIconHTML(string $icon_class, string $style = 'fas', string $options = '') : string
public function generateIconHTML(string $icon_class, string $style = 'fas', string $options = ''): string
{
//XSS protection
$icon_class = htmlspecialchars($icon_class);
@ -85,4 +88,4 @@ class FAIconGenerator
$options
);
}
}
}

View file

@ -39,10 +39,10 @@ class MarkdownParser
* Mark the markdown for rendering.
* The rendering of markdown is done on client side.
*
* @param string $markdown The markdown text that should be parsed to html.
* @param string $markdown the markdown text that should be parsed to html
* @param bool $inline_mode Only allow inline markdown codes like (*bold* or **italic**), not something like tables
*
* @return string The markdown in a version that can be parsed on client side.
* @return string the markdown in a version that can be parsed on client side
*/
public function markForRendering(string $markdown, bool $inline_mode = false): string
{

View file

@ -38,10 +38,10 @@ class MoneyFormatter
/**
* Format the the given value in the given currency.
*
* @param string|float $value The value that should be formatted.
* @param string|float $value the value that should be formatted
* @param Currency|null $currency The currency that should be used for formatting. If null the global one is used
* @param int $decimals The number of decimals that should be shown.
* @param bool $show_all_digits If set to true, all digits are shown, even if they are null.
* @param int $decimals the number of decimals that should be shown
* @param bool $show_all_digits if set to true, all digits are shown, even if they are null
*
* @return string
*/

View file

@ -21,7 +21,6 @@
namespace App\Services;
use App\Entity\UserSystem\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
@ -46,20 +45,20 @@ class PasswordResetManager
{
$this->em = $em;
$this->mailer = $mailer;
/** @var PasswordEncoderInterface passwordEncoder */
/* @var PasswordEncoderInterface passwordEncoder */
$this->passwordEncoder = $encoderFactory->getEncoder(User::class);
$this->translator = $translator;
$this->userPasswordEncoder = $userPasswordEncoder;
}
public function request(string $name_or_email) : void
public function request(string $name_or_email): void
{
$repo = $this->em->getRepository(User::class);
//Try to find a user by the given string
$user = $repo->findByEmailOrName($name_or_email);
//Do nothing if no user was found
if ($user === null) {
if (null === $user) {
return;
}
@ -76,11 +75,11 @@ class PasswordResetManager
$mail = new TemplatedEmail();
$mail->to($address);
$mail->subject($this->translator->trans('pw_reset.email.subject'));
$mail->htmlTemplate("mail/pw_reset.html.twig");
$mail->htmlTemplate('mail/pw_reset.html.twig');
$mail->context([
'expiration_date' => $expiration_date,
'token' => $unencrypted_token,
'user' => $user
'user' => $user,
]);
//Send email
@ -93,13 +92,15 @@ class PasswordResetManager
/**
* Sets the new password of the user with the given name, if the token is valid.
* @param string $user The name of the user, which password should be reset
* @param string $token The token that should be used to reset the password
*
* @param string $user The name of the user, which password should be reset
* @param string $token The token that should be used to reset the password
* @param string $new_password The new password that should be applied to user
*
* @return bool Returns true, if the new password was applied. False, if either the username is unknown or the
* token is invalid or expired.
* token is invalid or expired.
*/
public function setNewPassword(string $user, string $token, string $new_password) : bool
public function setNewPassword(string $user, string $token, string $new_password): bool
{
//Try to find the user
$repo = $this->em->getRepository(User::class);
@ -107,7 +108,7 @@ class PasswordResetManager
$user = $repo->findOneBy(['name' => $user]);
//If no user matching the name, show an error message
if ($user === null) {
if (null === $user) {
return false;
}
@ -130,6 +131,7 @@ class PasswordResetManager
//Save to DB
$this->em->flush();
return true;
}
}
}

View file

@ -160,9 +160,9 @@ class PermissionResolver
/**
* Sets the new value for the operation.
*
* @param HasPermissionsInterface $user The user or group for which the value should be changed.
* @param string $permission The name of the permission that should be changed.
* @param string $operation The name of the operation that should be changed.
* @param HasPermissionsInterface $user the user or group for which the value should be changed
* @param string $permission the name of the permission that should be changed
* @param string $operation the name of the operation that should be changed
* @param bool|null $new_val The new value for the permission. true = ALLOW, false = DISALLOW, null = INHERIT
*/
public function setPermission(HasPermissionsInterface $user, string $permission, string $operation, ?bool $new_val): void

View file

@ -41,8 +41,6 @@ class PricedetailHelper
/**
* Determines the highest amount, for which you get additional discount.
* This function determines the highest min_discount_quantity for the given part.
*
* @return float|null
*/
public function getMaxDiscountAmount(Part $part): ?float
{
@ -87,7 +85,7 @@ class PricedetailHelper
/**
* Determines the minimum amount of the part that can be ordered.
*
* @param Part $part The part for which the minimum order amount should be determined.
* @param Part $part the part for which the minimum order amount should be determined
*
* @return float
*/
@ -123,7 +121,7 @@ class PricedetailHelper
/**
* Calculates the average price of a part, when ordering the amount $amount.
*
* @param Part $part The part for which the average price should be calculated.
* @param Part $part the part for which the average price should be calculated
* @param float $amount The order amount for which the average price should be calculated.
* If set to null, the mininmum order amount for the part is used.
* @param Currency|null $currency The currency in which the average price should be calculated

View file

@ -30,7 +30,7 @@ class SIFormatter
* Returns the magnitude of a value (the count of decimal place of the highest decimal place).
* For example, for 100 (=10^2) this function returns 2. For -2500 (=-2.5*10^3) this function returns 3.
*
* @param float $value The value of which the magnitude should be determined.
* @param float $value the value of which the magnitude should be determined
*
* @return int The magnitude of the value
*/
@ -42,7 +42,7 @@ class SIFormatter
/**
* Returns the best SI prefix (and its corresponding divisor) for the given magnitude.
*
* @param int $magnitude The magnitude for which the prefix should be determined.
* @param int $magnitude the magnitude for which the prefix should be determined
*
* @return array A array, containing the divisor in first element, and the prefix symbol in second. For example, [1000, "k"].
*/
@ -66,9 +66,6 @@ class SIFormatter
return [10 ** (3 * $nearest), $symbol];
}
/**
* @return array
*/
public function convertValue(float $value): array
{
//Choose the prefix to use
@ -88,9 +85,7 @@ class SIFormatter
*
* @param float $value The value that should be converted
* @param string $unit The unit that should be appended after the prefix
* @param int $decimals The number of decimals (after decimal dot) that should be outputed.
*
* @return string
* @param int $decimals the number of decimals (after decimal dot) that should be outputed
*/
public function format(float $value, string $unit = '', int $decimals = 2): string
{

View file

@ -72,7 +72,7 @@ class StructuralElementRecursionHelper
/**
* Deletes the $element and all its subelements recursivly.
*
* @param StructuralDBElement $element The element which should be deleted.
* @param StructuralDBElement $element the element which should be deleted
* @param bool $flush When set to true the changes will also be flushed to DB. Set to false if you want to flush
* later.
*/

View file

@ -22,8 +22,7 @@
namespace App\Services\TFA;
/**
* This class generates random backup codes for two factor authentication
* @package App\Services\TFA
* This class generates random backup codes for two factor authentication.
*/
class BackupCodeGenerator
{
@ -32,8 +31,9 @@ class BackupCodeGenerator
/**
* BackupCodeGenerator constructor.
* @param int $code_length How many characters a single code should have.
* @param int $code_count How many codes are generated for a whole backup set.
*
* @param int $code_length How many characters a single code should have.
* @param int $code_count How many codes are generated for a whole backup set.
*/
public function __construct(int $code_length, int $code_count)
{
@ -50,28 +50,31 @@ class BackupCodeGenerator
/**
* Generates a single backup code.
* It is a random hexadecimal value with the digit count configured in constructor
* It is a random hexadecimal value with the digit count configured in constructor.
*
* @return string The generated backup code (e.g. 1f3870be2)
*
* @throws \Exception If no entropy source is available.
*/
public function generateSingleCode() : string
public function generateSingleCode(): string
{
$bytes = random_bytes(32);
return substr(md5($bytes), 0, $this->code_length);
}
/**
* Returns a full backup code set. The code count can be configured in the constructor
* Returns a full backup code set. The code count can be configured in the constructor.
*
* @return string[] An array containing different backup codes.
*/
public function generateCodeSet() : array
public function generateCodeSet(): array
{
$array = [];
for($n=0; $n<$this->code_count; $n++) {
for ($n = 0; $n < $this->code_count; ++$n) {
$array[] = $this->generateSingleCode();
}
return $array;
}
}
}

View file

@ -21,12 +21,10 @@
namespace App\Services\TFA;
use App\Entity\UserSystem\User;
/**
* This services offers methods to manage backup codes for two factor authentication
* @package App\Services\TFA
* This services offers methods to manage backup codes for two factor authentication.
*/
class BackupCodeManager
{
@ -39,23 +37,21 @@ class BackupCodeManager
/**
* Enable backup codes for the given user, by generating a set of backup codes.
* If the backup codes were already enabled before, they a
* @param User $user
* If the backup codes were already enabled before, they a.
*/
public function enableBackupCodes(User $user)
{
if(empty($user->getBackupCodes())) {
$this->regenerateBackupCodes($user);
if (empty($user->getBackupCodes())) {
$this->regenerateBackupCodes($user);
}
}
/**
* Disable (remove) the backup codes when no other 2 factor authentication methods are enabled.
* @param User $user
*/
public function disableBackupCodesIfUnused(User $user)
{
if($user->isGoogleAuthenticatorEnabled()) {
if ($user->isGoogleAuthenticatorEnabled()) {
return;
}
@ -65,11 +61,12 @@ class BackupCodeManager
/**
* Generates a new set of backup codes for the user. If no backup codes were available before, new ones are
* generated.
* @param User $user The user for which the backup codes should be regenerated
*
* @param User $user The user for which the backup codes should be regenerated
*/
public function regenerateBackupCodes(User $user)
{
$codes = $this->backupCodeGenerator->generateCodeSet();
$user->setBackupCodes($codes);
}
}
}

View file

@ -52,7 +52,7 @@ class TagFinder
* @param string $keyword The keyword the tag must begin with
* @param array $options Some options specifying the search behavior. See configureOptions for possible options.
*
* @return string[] An array containing the tags that match the given keyword.
* @return string[] an array containing the tags that match the given keyword
*/
public function searchTags(string $keyword, array $options = [])
{

View file

@ -21,17 +21,12 @@
namespace App\Services\Trees;
use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement;
use App\Helpers\Trees\TreeViewNode;
use App\Repository\StructuralDBElementRepository;
use App\Services\EntityURLGenerator;
use App\Services\UserCacheKeyGenerator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* This service gives you a flat list containing all structured entities in the order of the structure.
@ -42,7 +37,7 @@ class NodesListBuilder
protected $cache;
protected $keyGenerator;
public function __construct( EntityManagerInterface $em, TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator)
public function __construct(EntityManagerInterface $em, TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator)
{
$this->em = $em;
$this->keyGenerator = $keyGenerator;

View file

@ -21,12 +21,11 @@
namespace App\Services\Trees;
use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement;
use App\Helpers\Trees\TreeViewNodeIterator;
use App\Helpers\Trees\TreeViewNode;
use App\Helpers\Trees\TreeViewNodeIterator;
use App\Repository\StructuralDBElementRepository;
use App\Services\EntityURLGenerator;
use App\Services\UserCacheKeyGenerator;
@ -37,7 +36,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class TreeViewGenerator
{
protected $urlGenerator;
protected $em;
protected $cache;
@ -56,14 +54,16 @@ class TreeViewGenerator
/**
* Gets a TreeView list for the entities of the given class.
* @param string $class The class for which the treeView should be generated
* @param StructuralDBElement|null $parent The root nodes in the tree should have this element as parent (use null, if you want to get all entities)
* @param string $href_type The link type that will be generated for the hyperlink section of each node (see EntityURLGenerator for possible values).
* Set to empty string, to disable href field.
* @param DBElement|null $selectedElement The element that should be selected. If set to null, no element will be selected.
*
* @param string $class The class for which the treeView should be generated
* @param StructuralDBElement|null $parent The root nodes in the tree should have this element as parent (use null, if you want to get all entities)
* @param string $href_type The link type that will be generated for the hyperlink section of each node (see EntityURLGenerator for possible values).
* Set to empty string, to disable href field.
* @param DBElement|null $selectedElement The element that should be selected. If set to null, no element will be selected.
*
* @return TreeViewNode[] An array of TreeViewNode[] elements of the root elements.
*/
public function getTreeView(string $class, ?StructuralDBElement $parent = null, string $href_type = 'list_parts', DBElement $selectedElement = null) : array
public function getTreeView(string $class, ?StructuralDBElement $parent = null, string $href_type = 'list_parts', DBElement $selectedElement = null): array
{
$head = [];
@ -89,8 +89,8 @@ class TreeViewGenerator
$recursiveIterator = new \RecursiveIteratorIterator($treeIterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($recursiveIterator as $item) {
/** @var $item TreeViewNode */
if ($selectedElement !== null && $item->getId() === $selectedElement->getID()) {
$item->setSelected(true);
if (null !== $selectedElement && $item->getId() === $selectedElement->getID()) {
$item->setSelected(true);
}
if (!empty($item->getNodes())) {
@ -111,16 +111,17 @@ class TreeViewGenerator
* Gets a tree of TreeViewNode elements. The root elements has $parent as parent.
* The treeview is generic, that means the href are null and ID values are set.
*
* @param string $class The class for which the tree should be generated
* @param StructuralDBElement|null $parent The parent the root elements should have.
* @param string $class The class for which the tree should be generated
* @param StructuralDBElement|null $parent The parent the root elements should have.
*
* @return TreeViewNode[]
*/
public function getGenericTree(string $class, ?StructuralDBElement $parent = null) : array
public function getGenericTree(string $class, ?StructuralDBElement $parent = null): array
{
if(!is_a($class, NamedDBElement::class, true)) {
if (!is_a($class, NamedDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
}
if($parent !== null && !is_a($parent, $class)) {
if (null !== $parent && !is_a($parent, $class)) {
throw new \InvalidArgumentException('$parent must be of the type $class!');
}
@ -128,8 +129,8 @@ class TreeViewGenerator
$repo = $this->em->getRepository($class);
//If we just want a part of a tree, dont cache it
if ($parent !== null) {
return $repo->getGenericNodeTree($parent);
if (null !== $parent) {
return $repo->getGenericNodeTree($parent);
}
$secure_class_name = str_replace('\\', '_', $class);
@ -138,9 +139,10 @@ class TreeViewGenerator
$ret = $this->cache->get($key, function (ItemInterface $item) use ($repo, $parent, $secure_class_name) {
// Invalidate when groups, a element with the class or the user changes
$item->tag(['groups', 'tree_treeview', $this->keyGenerator->generateKey(), $secure_class_name]);
return $repo->getGenericNodeTree($parent);
});
return $ret;
}
}
}

View file

@ -41,8 +41,6 @@ class UserCacheKeyGenerator
*
* @param User|null $user The user for which the key should be generated. When set to null, the currently logged in
* user is used.
*
* @return string
*/
public function generateKey(User $user = null): string
{