Applied code style rules to src/

This commit is contained in:
Jan Böhmer 2020-01-05 15:46:58 +01:00
parent 700c049d26
commit f861de791f
186 changed files with 1462 additions and 1059 deletions

View file

@ -68,6 +68,11 @@ abstract class Attachment extends NamedDBElement
/** @var array Placeholders for attachments which using built in files. */
public const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%'];
/**
* @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses.
*/
public const ALLOWED_ELEMENT_CLASS = '';
/**
* @var bool
* @ORM\Column(type="boolean")
@ -99,11 +104,6 @@ abstract class Attachment extends NamedDBElement
*/
protected $attachment_type;
/**
* @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses.
*/
public const ALLOWED_ELEMENT_CLASS = '';
public function __construct()
{
//parent::__construct();
@ -170,7 +170,7 @@ abstract class Attachment extends NamedDBElement
return true;
}
return !\in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
return ! \in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
}
/**
@ -221,7 +221,7 @@ abstract class Attachment extends NamedDBElement
return null;
}
if (!empty($this->original_filename)) {
if (! empty($this->original_filename)) {
return strtolower(pathinfo($this->original_filename, PATHINFO_EXTENSION));
}
@ -244,7 +244,7 @@ abstract class Attachment extends NamedDBElement
*/
public function getURL(): ?string
{
if (!$this->isExternal() && !$this->isBuiltIn()) {
if (! $this->isExternal() && ! $this->isBuiltIn()) {
return null;
}
@ -257,7 +257,7 @@ abstract class Attachment extends NamedDBElement
*/
public function getHost(): ?string
{
if (!$this->isExternal()) {
if (! $this->isExternal()) {
return null;
}
@ -287,7 +287,7 @@ abstract class Attachment extends NamedDBElement
}
//If we have a stored original filename, then use it
if (!empty($this->original_filename)) {
if (! empty($this->original_filename)) {
return $this->original_filename;
}
@ -362,8 +362,8 @@ abstract class Attachment extends NamedDBElement
*/
public function setElement(AttachmentContainingDBElement $element): self
{
if (!is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', \get_class($this), static::ALLOWED_ELEMENT_CLASS));
if (! is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
}
$this->element = $element;
@ -404,7 +404,7 @@ abstract class Attachment extends NamedDBElement
public function setURL(?string $url): self
{
//Only set if the URL is not empty
if (!empty($url)) {
if (! empty($url)) {
if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) {
throw new \InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
}
@ -443,10 +443,10 @@ abstract class Attachment extends NamedDBElement
/**
* Check if a string is a URL and is valid.
*
* @param $string string The string which should be checked
* @param bool $path_required If true, the string must contain a path to be valid. (e.g. foo.bar would be invalid, foo.bar/test.php would be valid).
* @param $only_http bool Set this to true, if only HTTPS or HTTP schemata should be allowed.
* *Caution: When this is set to false, a attacker could use the file:// schema, to get internal server files, like /etc/passwd.*
* @param string $string The string which should be checked
* @param bool $path_required If true, the string must contain a path to be valid. (e.g. foo.bar would be invalid, foo.bar/test.php would be valid).
* @param bool $only_http Set this to true, if only HTTPS or HTTP schemata should be allowed.
* *Caution: When this is set to false, a attacker could use the file:// schema, to get internal server files, like /etc/passwd.*
*
* @return bool True if the string is a valid URL. False, if the string is not an URL or invalid.
*/

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -30,12 +33,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class AttachmentTypeAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
/**
* @var AttachmentType the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class CategoryAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Category::class;
/**
* @var Category the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Category::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class CurrencyAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Currency::class;
/**
* @var Currency the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Currency::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class DeviceAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Device::class;
/**
* @var Device the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Devices\Device", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Device::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class FootprintAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Footprint::class;
/**
* @var Footprint the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Footprint::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class GroupAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Group::class;
/**
* @var Group the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Group::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class ManufacturerAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Manufacturer::class;
/**
* @var Manufacturer the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Manufacturer::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -32,12 +35,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class MeasurementUnitAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class;
/**
* @var Manufacturer the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class PartAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Part::class;
/**
* @var Part the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Part::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class StorelocationAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
/**
* @var Storelocation the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class SupplierAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Supplier::class;
/**
* @var Supplier the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = Supplier::class;
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class UserAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = User::class;
/**
* @var User the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = User::class;
}

View file

@ -20,6 +20,7 @@
*/
declare(strict_types=1);
/**
* Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer

View file

@ -66,6 +66,12 @@ abstract class DBElement
*/
protected $id;
public function __clone()
{
//Set ID to null, so that an new entry is created
$this->id = null;
}
/**
* Get the ID. The ID can be zero, or even negative (for virtual elements). If an element is virtual, can be
* checked with isVirtualElement().
@ -86,10 +92,4 @@ abstract class DBElement
* @return string The ID as a string;
*/
abstract public function getIDString(): string;
public function __clone()
{
//Set ID to null, so that an new entry is created
$this->id = null;
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*

View file

@ -45,6 +45,17 @@ abstract class NamedDBElement extends DBElement
*/
protected $name = '';
/******************************************************************************
*
* Helpers
*
******************************************************************************/
public function __toString()
{
return $this->getName();
}
/********************************************************************************
*
* Getters
@ -80,15 +91,4 @@ abstract class NamedDBElement extends DBElement
return $this;
}
/******************************************************************************
*
* Helpers
*
******************************************************************************/
public function __toString()
{
return $this->getName();
}
}

View file

@ -113,11 +113,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*/
public function isChildOf(self $another_element): bool
{
$class_name = \get_class($this);
$class_name = static::class;
//Check if both elements compared, are from the same type
// (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
if (!is_a($another_element, $class_name) && !is_a($this, \get_class($another_element))) {
if (! is_a($another_element, $class_name) && ! is_a($this, \get_class($another_element))) {
throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!');
}
@ -201,7 +201,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*/
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
{
if (!\is_array($this->full_path_strings)) {
if (! \is_array($this->full_path_strings)) {
$this->full_path_strings = [];
$this->full_path_strings[] = $this->getName();
$element = $this;
@ -233,7 +233,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$tmp[] = $this;
//We only allow 20 levels depth
while (!end($tmp)->isRoot() && \count($tmp) < 20) {
while (! end($tmp)->isRoot() && \count($tmp) < 20) {
$tmp[] = end($tmp)->parent;
}
@ -243,8 +243,6 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* Get all sub elements of this element.
*
* @param bool $recursive if true, the search is recursive
*
* @return Collection<static> all subelements as an array of objects (sorted by their full path)
*/
public function getSubelements(): iterable

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -266,7 +269,7 @@ class PartLot extends DBElement
*/
public function getAmount(): float
{
if ($this->part instanceof Part && !$this->part->useFloatAmount()) {
if ($this->part instanceof Part && ! $this->part->useFloatAmount()) {
return round($this->amount);
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -192,8 +195,8 @@ trait BasicPropertyTrait
/**
* 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.
* @param bool $new_favorite_status The new favorite status, that should be applied on this part.
* Set this to true, when the part should be a favorite.
*/
public function setFavorite(bool $new_favorite_status): self
{

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -134,7 +137,7 @@ trait InstockTrait
public function useFloatAmount(): bool
{
if ($this->partUnit instanceof MeasurementUnit) {
return !$this->partUnit->isInteger();
return ! $this->partUnit->isInteger();
}
//When no part unit is set, treat it as part count, and so use the integer value.

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -185,7 +188,7 @@ trait OrderTrait
}
foreach ($all_orderdetails as $orderdetails) {
if (!$orderdetails->getObsolete()) {
if (! $orderdetails->getObsolete()) {
return false;
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -104,7 +107,7 @@ class Currency extends StructuralDBElement
return null;
}
return bcdiv(1, $tmp, static::PRICE_SCALE);
return bcdiv('1', $tmp, static::PRICE_SCALE);
}
/**

View file

@ -181,8 +181,8 @@ class Orderdetail extends DBElement
/**
* Get the link to the website of the article on the suppliers website.
*
* @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
* @param bool $no_automatic_url 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
*/
@ -330,7 +330,7 @@ class Orderdetail extends DBElement
* 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
* @param string $new_url The new URL for the supplier URL
*
* @return Orderdetail
*/

View file

@ -68,10 +68,10 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class Pricedetail extends DBElement
{
public const PRICE_PRECISION = 5;
use TimestampTrait;
public const PRICE_PRECISION = 5;
/**
* @var Orderdetail
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
@ -180,7 +180,7 @@ class Pricedetail extends DBElement
*/
public function getPriceRelatedQuantity(): float
{
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
if ($this->orderdetail && $this->orderdetail->getPart() && ! $this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->price_related_quantity);
return $tmp < 1 ? 1 : $tmp;
@ -203,7 +203,7 @@ class Pricedetail extends DBElement
*/
public function getMinDiscountQuantity(): float
{
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
if ($this->orderdetail && $this->orderdetail->getPart() && ! $this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->min_discount_quantity);
return $tmp < 1 ? 1 : $tmp;

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -299,7 +302,7 @@ class PermissionsEmbed
*/
public function isValidPermissionName(string $permission_name): bool
{
return isset($this->$permission_name);
return isset($this->{$permission_name});
}
/**
@ -312,11 +315,11 @@ class PermissionsEmbed
*/
public function getBitValue(string $permission_name, int $bit_n): int
{
if (!$this->isValidPermissionName($permission_name)) {
if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException(sprintf('No permission with the name "%s" is existing!', $permission_name));
}
$perm_int = $this->$permission_name;
$perm_int = (int) $this->{$permission_name};
return static::readBitPair($perm_int, $bit_n);
}
@ -382,11 +385,11 @@ class PermissionsEmbed
*/
public function setBitValue(string $permission_name, int $bit_n, int $new_value): self
{
if (!$this->isValidPermissionName($permission_name)) {
if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!');
}
$this->$permission_name = static::writeBitPair($this->$permission_name, $bit_n, $new_value);
$this->{$permission_name} = static::writeBitPair($this->{$permission_name}, $bit_n, $new_value);
return $this;
}
@ -401,11 +404,11 @@ class PermissionsEmbed
*/
public function getRawPermissionValue(string $permission_name): int
{
if (!$this->isValidPermissionName($permission_name)) {
if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!');
}
return $this->$permission_name;
return $this->{$permission_name};
}
/**
@ -418,11 +421,11 @@ class PermissionsEmbed
*/
public function setRawPermissionValue(string $permission_name, int $value): self
{
if (!$this->isValidPermissionName($permission_name)) {
if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
}
$this->$permission_name = $value;
$this->{$permission_name} = $value;
return $this;
}
@ -436,9 +439,9 @@ class PermissionsEmbed
*
* @return $this
*/
public function setRawPermissionValues(array $values, array $values2 = null): self
public function setRawPermissionValues(array $values, ?array $values2 = null): self
{
if (!empty($values2)) {
if (! empty($values2)) {
$values = array_combine($values, $values2);
}
@ -452,12 +455,12 @@ 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.
* @param int|string $data The data from where the bits should be extracted from
* @param int $n 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
final protected static function readBitPair($data, int $n): int
{
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
if (0 !== $n % 2) {
@ -471,9 +474,9 @@ 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
* @param int $data The data which should be modified
* @param int $n The number of the lower bit of the pair which should be written
* @param int $new The new value of the pair
*
* @return int the new data with the modified pair
*/

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -38,13 +41,6 @@ class U2FKey implements TwoFactorKeyInterface
{
use TimestampTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=64)
*
@ -73,6 +69,13 @@ class U2FKey implements TwoFactorKeyInterface
**/
public $counter;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys")
*
@ -95,62 +98,52 @@ class U2FKey implements TwoFactorKeyInterface
$this->counter = $data->counter;
}
/** {@inheritdoc} */
public function getKeyHandle()
{
return $this->keyHandle;
}
/** {@inheritdoc} */
public function setKeyHandle($keyHandle)
public function setKeyHandle($keyHandle): void
{
$this->keyHandle = $keyHandle;
}
/** {@inheritdoc} */
public function getPublicKey()
{
return $this->publicKey;
}
/** {@inheritdoc} */
public function setPublicKey($publicKey)
public function setPublicKey($publicKey): void
{
$this->publicKey = $publicKey;
}
/** {@inheritdoc} */
public function getCertificate()
{
return $this->certificate;
}
/** {@inheritdoc} */
public function setCertificate($certificate)
public function setCertificate($certificate): void
{
$this->certificate = $certificate;
}
/** {@inheritdoc} */
public function getCounter()
{
return $this->counter;
}
/** {@inheritdoc} */
public function setCounter($counter)
public function setCounter($counter): void
{
$this->counter = $counter;
}
/** {@inheritdoc} */
public function getName()
{
return $this->name;
}
/** {@inheritdoc} */
public function setName($name)
public function setName($name): void
{
$this->name = $name;
}

View file

@ -266,6 +266,19 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
$this->u2fKeys = new ArrayCollection();
}
/**
* Returns a string representation of this user (the full name).
* E.g. 'Jane Doe (j.doe) [DISABLED].
*
* @return string
*/
public function __toString()
{
$tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true).$tmp;
}
/**
* Checks if the current user, is the user which represents the not logged in (anonymous) users.
*
@ -330,7 +343,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* @see UserInterface
*/
public function getSalt()
public function getSalt(): void
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
@ -338,7 +351,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* @see UserInterface
*/
public function eraseCredentials()
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
@ -503,7 +516,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public function setName(string $new_name): NamedDBElement
{
// Anonymous user is not allowed to change its username
if (!$this->isAnonymousUser()) {
if (! $this->isAnonymousUser()) {
$this->name = $new_name;
}
@ -646,8 +659,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Change the timezone of this user.
*
* @param string $timezone|null The new timezone (e.g. 'Europe/Berlin') or null to use the system wide one.
*
* @return $this
*/
public function setTimezone(?string $timezone): self
@ -706,19 +717,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
return $this;
}
/**
* Returns a string representation of this user (the full name).
* E.g. 'Jane Doe (j.doe) [DISABLED].
*
* @return string
*/
public function __toString()
{
$tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true).$tmp;
}
/**
* Return true if the user should do two-factor authentication.
*
@ -771,7 +769,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
public function isBackupCode(string $code): bool
{
return \in_array($code, $this->backupCodes);
return \in_array($code, $this->backupCodes, true);
}
/**
@ -781,7 +779,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
public function invalidateBackupCode(string $code): void
{
$key = array_search($code, $this->backupCodes);
$key = array_search($code, $this->backupCodes, true);
if (false !== $key) {
unset($this->backupCodes[$key]);
}
@ -883,9 +881,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
$this->u2fKeys->removeElement($key);
}
/**
* {@inheritdoc}
*/
public function getPreferredTwoFactorProvider(): ?string
{
//If U2F is available then prefer it