Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -65,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
* "Supplier" = "SupplierAttachment", "User" = "UserAttachment"
* })
* @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"})
*
*/
abstract class Attachment extends NamedDBElement
{
@ -75,7 +73,7 @@ abstract class Attachment extends NamedDBElement
* It will be used to determine if a attachment is a picture and therefore will be shown to user as preview.
*/
public const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png',
'svg', 'webp'];
'svg', 'webp', ];
/**
* A list of extensions that will be treated as a 3D Model that can be shown to user directly in Part-DB.
@ -83,7 +81,7 @@ abstract class Attachment extends NamedDBElement
public const MODEL_EXTS = ['x3d'];
/**
* When the path begins with one of this placeholders
* When the path begins with one of this placeholders.
*/
public const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%', '%SECURE%'];
@ -109,7 +107,7 @@ abstract class Attachment extends NamedDBElement
protected $original_filename;
/**
* ORM mapping is done in sub classes (like PartAttachment)
* ORM mapping is done in sub classes (like PartAttachment).
*/
protected $element;
@ -129,7 +127,7 @@ abstract class Attachment extends NamedDBElement
public function __construct()
{
//parent::__construct();
if (static::ALLOWED_ELEMENT_CLASS === '') {
if ('' === static::ALLOWED_ELEMENT_CLASS) {
throw new \LogicException('An *Attachment class must override the ALLOWED_ELEMENT_CLASS const!');
}
}
@ -154,15 +152,16 @@ abstract class Attachment extends NamedDBElement
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
return in_array(strtolower($extension), static::PICTURE_EXTS, true);
return \in_array(strtolower($extension), static::PICTURE_EXTS, true);
}
/**
* Check if this attachment is a 3D model and therfore can be directly shown to user.
* If the attachment is external, false is returned (3D Models must be internal).
*
* @return bool
*/
public function is3DModel() : bool
public function is3DModel(): bool
{
//We just assume that 3D Models are internally saved, otherwise we get problems loading them.
if ($this->isExternal()) {
@ -171,14 +170,15 @@ abstract class Attachment extends NamedDBElement
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
return in_array(strtolower($extension), static::MODEL_EXTS, true);
return \in_array(strtolower($extension), static::MODEL_EXTS, true);
}
/**
* Checks if the attachment file is externally saved (the database saves an URL)
* Checks if the attachment file is externally saved (the database saves an URL).
*
* @return bool true, if the file is saved externally
*/
public function isExternal() : bool
public function isExternal(): bool
{
//When path is empty, this attachment can not be external
if (empty($this->path)) {
@ -186,38 +186,40 @@ abstract class Attachment extends NamedDBElement
}
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode("/", $this->path);
$tmp = explode('/', $this->path);
if (empty($tmp)) {
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);
}
/**
* Check if this attachment is saved in a secure place.
* This means that it can not be accessed directly via a web request, but must be viewed via a controller.
*
* @return bool True, if the file is secure.
*/
public function isSecure() : bool
public function isSecure(): bool
{
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode("/", $this->path);
$tmp = explode('/', $this->path);
if (empty($tmp)) {
return false;
}
return $tmp[0] === '%SECURE%';
return '%SECURE%' === $tmp[0];
}
/**
* Checks if the attachment file is using a builtin file. (see BUILTIN_PLACEHOLDERS const for possible placeholders)
* If a file is built in, the path is shown to user in url field (no sensitive infos are provided)
* If a file is built in, the path is shown to user in url field (no sensitive infos are provided).
*
* @return bool True if the attachment is uning an builtin file.
*/
public function isBuiltIn() : bool
public function isBuiltIn(): bool
{
return static::checkIfBuiltin($this->path);
}
@ -232,9 +234,10 @@ abstract class Attachment extends NamedDBElement
* Returns the extension of the file referenced via the attachment.
* For a path like %BASE/path/foo.bar, bar will be returned.
* If this attachment is external null is returned.
*
* @return string|null The file extension in lower case.
*/
public function getExtension() : ?string
public function getExtension(): ?string
{
if ($this->isExternal()) {
return null;
@ -260,6 +263,7 @@ abstract class Attachment extends NamedDBElement
/**
* The URL to the external file, or the path to the built in file.
* Returns null, if the file is not external (and not builtin).
*
* @return string|null
*/
public function getURL(): ?string
@ -274,6 +278,7 @@ abstract class Attachment extends NamedDBElement
/**
* Returns the hostname where the external file is stored.
* Returns null, if the file is not external.
*
* @return string|null
*/
public function getHost(): ?string
@ -319,16 +324,19 @@ abstract class Attachment extends NamedDBElement
/**
* Sets the filename that is shown for this attachment. Useful when the internal path is some generated value.
*
* @param string|null $new_filename The filename that should be shown.
* Set to null to generate the filename from path.
* Set to null to generate the filename from path.
*
* @return Attachment
*/
public function setFilename(?string $new_filename): Attachment
public function setFilename(?string $new_filename): self
{
if ($new_filename === "") {
if ('' === $new_filename) {
$new_filename = null;
}
$this->original_filename = $new_filename;
return $this;
}
@ -347,7 +355,6 @@ abstract class Attachment extends NamedDBElement
* Get the type of this attachement.
*
* @return AttachmentType the type of this attachement
*
*/
public function getAttachmentType(): ?AttachmentType
{
@ -370,8 +377,6 @@ abstract class Attachment extends NamedDBElement
****************************************************************************************************/
/**
* @param bool $show_in_table
*
* @return self
*/
public function setShowInTable(bool $show_in_table): self
@ -381,51 +386,48 @@ abstract class Attachment extends NamedDBElement
return $this;
}
public function setElement(AttachmentContainingDBElement $element) : Attachment
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!', \get_class($this), static::ALLOWED_ELEMENT_CLASS));
}
$this->element = $element;
return $this;
}
/**
* @param string $path
* @return Attachment
*/
public function setPath(string $path): Attachment
public function setPath(string $path): self
{
$this->path = $path;
return $this;
}
/**
* @param AttachmentType $attachement_type
* @return Attachment
*/
public function setAttachmentType(AttachmentType $attachement_type): Attachment
public function setAttachmentType(AttachmentType $attachement_type): self
{
$this->attachment_type = $attachement_type;
return $this;
}
/**
* Sets the url associated with this attachment.
* If the url is empty nothing is changed, to not override the file path.
* @param string|null $url
*
* @return Attachment
*/
public function setURL(?string $url) : Attachment
public function setURL(?string $url): self
{
//Only set if the URL is not empty
if (!empty($url)) {
if (strpos($url, '%BASE%') !== false || strpos($url, '%MEDIA%') !== false) {
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!');
}
@ -437,17 +439,18 @@ abstract class Attachment extends NamedDBElement
return $this;
}
/*****************************************************************************************************
* Static functions
*****************************************************************************************************/
/**
* Checks if the given path is a path to a builtin ressource.
*
* @param string $path The path that should be checked
*
* @return bool True if the path is pointing to a builtin ressource.
*/
public static function checkIfBuiltin(string $path) : bool
public static function checkIfBuiltin(string $path): bool
{
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode('/', $path);
@ -455,22 +458,25 @@ abstract class Attachment extends NamedDBElement
if (empty($tmp)) {
return false;
}
return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
return \in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
}
/**
* 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.*
*
* @return bool True if the string is a valid URL. False, if the string is not an URL or invalid.
*/
public static function isURL(string $string, bool $path_required = true, bool $only_http = true) : bool
public static function isURL(string $string, bool $path_required = true, bool $only_http = true): bool
{
if ($only_http) { //Check if scheme is HTTPS or HTTP
$scheme = parse_url($string, PHP_URL_SCHEME);
if ($scheme !== 'http' && $scheme !== 'https') {
if ('http' !== $scheme && 'https' !== $scheme) {
return false; //All other schemes are not valid.
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -48,7 +47,6 @@ use App\Entity\Base\NamedDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\MappedSuperclass()
@ -59,8 +57,8 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
/**
* @var Attachment[]
* //TODO
* //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element")
* //TODO
* //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element")
*
* Mapping is done in sub classes like part
*/
@ -79,34 +77,39 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
/**
* Gets all attachments associated with this element.
*
* @return Attachment[]|Collection
*/
public function getAttachments() : Collection
public function getAttachments(): Collection
{
return $this->attachments;
}
/**
* Adds an attachment to this element
* Adds an attachment to this element.
*
* @param Attachment $attachment Attachment
*
* @return $this
*/
public function addAttachment(Attachment $attachment) : self
public function addAttachment(Attachment $attachment): self
{
//Attachment must be associated with this element
$attachment->setElement($this);
$this->attachments->add($attachment);
return $this;
}
/**
* Removes the given attachment from this element
* @param Attachment $attachment
* Removes the given attachment from this element.
*
* @return $this
*/
public function removeAttachment(Attachment $attachment) : self
public function removeAttachment(Attachment $attachment): self
{
$this->attachments->removeElement($attachment);
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -44,10 +43,10 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Base\StructuralDBElement;
use App\Validator\Constraints\ValidFileFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Validator\Constraints\ValidFileFilter;
/**
* Class AttachmentType.
@ -85,7 +84,7 @@ class AttachmentType extends StructuralDBElement
* @ORM\Column(type="text")
* @ValidFileFilter
*/
protected $filetype_filter = "";
protected $filetype_filter = '';
public function __construct()
{
@ -97,7 +96,7 @@ class AttachmentType extends StructuralDBElement
* Get all attachments ("Attachment" objects) with this type.
*
* @return Collection|Attachment[] all attachements with this type, as a one-dimensional array of Attachements
* (sorted by their names)
* (sorted by their names)
*/
public function getAttachmentsForType(): Collection
{
@ -108,6 +107,7 @@ class AttachmentType extends StructuralDBElement
* Gets an filter, which file types are allowed for attachment files.
* Must be in the format of <input type=file> accept attribute
* (See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers).
*
* @return string
*/
public function getFiletypeFilter(): string
@ -116,12 +116,12 @@ class AttachmentType extends StructuralDBElement
}
/**
* @param string $filetype_filter
* @return AttachmentType
*/
public function setFiletypeFilter(string $filetype_filter): AttachmentType
public function setFiletypeFilter(string $filetype_filter): self
{
$this->filetype_filter = $filetype_filter;
return $this;
}
@ -133,6 +133,6 @@ class AttachmentType extends StructuralDBElement
*/
public function getIDString(): string
{
return 'AT' . sprintf('%09d', $this->getID());
return 'AT'.sprintf('%09d', $this->getID());
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,22 +17,19 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to an attachmentType element.
* @package App\Entity
*
* @ORM\Entity()
*/
class AttachmentTypeAttachment extends Attachment
{
/**
* @var AttachmentType The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments")
@ -40,5 +37,5 @@ class AttachmentTypeAttachment extends Attachment
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
}
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a category element.
* @package App\Entity
*
* @ORM\Entity()
*/
class CategoryAttachment extends Attachment
{
/**
* @var Category The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments")
@ -43,4 +39,4 @@ class CategoryAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Category::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,28 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a currency element.
* @package App\Entity
*
* @ORM\Entity()
*/
class CurrencyAttachment extends Attachment
{
/**
* @var Currency The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments")
@ -47,4 +39,4 @@ class CurrencyAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Currency::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a device element.
* @package App\Entity
*
* @ORM\Entity()
*/
class DeviceAttachment extends Attachment
@ -41,4 +39,4 @@ class DeviceAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Device::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a footprint element.
* @package App\Entity
*
* @ORM\Entity()
*/
class FootprintAttachment extends Attachment
{
/**
* @var Footprint The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments")
@ -43,4 +39,4 @@ class FootprintAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Footprint::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,30 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a Group element.
* @package App\Entity
*
* @ORM\Entity()
*/
class GroupAttachment extends Attachment
{
/**
* @var Group The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a manufacturer element.
* @package App\Entity
*
* @ORM\Entity()
*/
class ManufacturerAttachment extends Attachment
{
/**
* @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments")
@ -43,4 +39,4 @@ class ManufacturerAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Manufacturer::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,25 +17,21 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a measurement unit element.
* @package App\Entity
*
* @ORM\Entity()
*/
class MeasurementUnitAttachment extends Attachment
{
/**
* @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments")
@ -44,4 +40,4 @@ class MeasurementUnitAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
@ -27,12 +26,11 @@ use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a part element.
* @package App\Entity
*
* @ORM\Entity()
*/
class PartAttachment extends Attachment
{
/**
* @var Part The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments")
@ -41,4 +39,4 @@ class PartAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Part::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,27 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpKernel\HttpCache\Store;
/**
* A attachment attached to a measurement unit element.
* @package App\Entity
*
* @ORM\Entity()
*/
class StorelocationAttachment extends Attachment
{
/**
* @var Storelocation The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments")
@ -46,4 +39,4 @@ class StorelocationAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,27 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a supplier element.
* @package App\Entity
*
* @ORM\Entity()
*/
class SupplierAttachment extends Attachment
{
/**
* @var Supplier The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments")
@ -46,4 +39,4 @@ class SupplierAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Supplier::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,29 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a user element.
* @package App\Entity
*
* @ORM\Entity()
*/
class UserAttachment extends Attachment
{
/**
* @var User The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments")
@ -48,4 +39,4 @@ class UserAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = User::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -104,7 +103,6 @@ abstract class DBElement
* 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;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,20 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Base;
use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A entity with this class has a master attachment, which is used as a preview image for this object.
* @package App\Entity\Parts\PartTraits
*/
trait MasterAttachmentTrait
{
@ -42,10 +38,10 @@ trait MasterAttachmentTrait
*/
protected $master_picture_attachment;
/**
* Get the master picture "Attachment"-object of this part (if there is one).
* The master picture should be used as a visual description/representation of this part.
*
* @return Attachment the master picture Attachement of this part (if there is one)
*/
public function getMasterPictureAttachment(): ?Attachment
@ -55,14 +51,13 @@ trait MasterAttachmentTrait
/**
* Sets the new master picture for this part.
* @param Attachment|null $new_master_attachment
*
* @return Part
*/
public function setMasterPictureAttachment(?Attachment $new_master_attachment): self
{
$this->master_picture_attachment = $new_master_attachment;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -44,8 +43,8 @@ declare(strict_types=1);
namespace App\Entity\Base;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* All subclasses of this class have an attribute "name".
@ -55,7 +54,6 @@ use Symfony\Component\Serializer\Annotation\Groups;
*/
abstract class NamedDBElement extends DBElement
{
use TimestampTrait;
/**
@ -73,7 +71,8 @@ abstract class NamedDBElement extends DBElement
*********************************************************************************/
/**
* Get the name of this element
* Get the name of this element.
*
* @return string the name of this element
*/
public function getName(): string
@ -91,6 +90,7 @@ abstract class NamedDBElement extends DBElement
* Change the name of this element.
*
* @param string $new_name the new name
*
* @return self
*/
public function setName(string $new_name): self

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -68,9 +67,10 @@ abstract class PartsContainingDBElement extends StructuralDBElement
/**
* Returns the parts associated with this element.
*
* @return Collection|Part[]
*/
public function getParts() : Collection
public function getParts(): Collection
{
return $this->parts;
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -44,9 +43,9 @@ declare(strict_types=1);
namespace App\Entity\Base;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Validator\Constraints\NoneOfItsChildren;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use App\Validator\Constraints\NoneOfItsChildren;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
@ -95,7 +94,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* @var bool If this property is set, this element can not be selected for part properties.
* Useful if this element should be used only for grouping, sorting.
* Useful if this element should be used only for grouping, sorting.
* @ORM\Column(type="boolean")
*/
protected $not_selectable = false;
@ -107,12 +106,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** @var string[] all names of all parent elements as a array of strings,
* the last array element is the name of the element itself
*
*/
private $full_path_strings;
public function __construct()
{
parent::__construct();
@ -127,19 +123,19 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* Check if this element is a child of another element (recursive).
*
* @param StructuralDBElement $another_element the object to compare
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
*
* @return bool True, if this element is child of $another_element.
*
* @throws \InvalidArgumentException if there was an error
*/
public function isChildOf(StructuralDBElement $another_element) : bool
public function isChildOf(self $another_element): bool
{
$class_name = \get_class($this);
//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!');
}
@ -153,12 +149,13 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
}
/**
* Checks if this element is an root element (has no parent)
* Checks if this element is an root element (has no parent).
*
* @return bool True if the this element is an root element.
*/
public function isRoot() : bool
public function isRoot(): bool
{
return $this->parent === null;
return null === $this->parent;
}
/******************************************************************************
@ -180,6 +177,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* Get the comment of the element.
*
* @return string the comment
*/
public function getComment(): ?string
@ -194,21 +192,21 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*
* @return int the level of this element (zero means a most top element
* [a subelement of the root node])
*
*/
public function getLevel(): int
{
/**
/*
* Only check for nodes that have a parent. In the other cases zero is correct.
*/
if (0 === $this->level && $this->parent !== null) {
if (0 === $this->level && null !== $this->parent) {
$element = $this->parent;
while ($element !== null) {
while (null !== $element) {
/** @var StructuralDBElement $element */
$element = $element->parent;
++$this->level;
}
}
return $this->level;
}
@ -218,12 +216,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* @param string $delimeter the delimeter of the returned string
*
* @return string the full path (incl. the name of this element), delimeted by $delimeter
*
*/
public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string
{
if (!\is_array($this->full_path_strings)) {
$this->full_path_strings = array();
$this->full_path_strings = [];
$this->full_path_strings[] = $this->getName();
$element = $this;
@ -233,7 +230,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$element = $element->parent;
$this->full_path_strings[] = $element->getName();
//Decrement to prevent mem overflow.
$overflow--;
--$overflow;
}
$this->full_path_strings = array_reverse($this->full_path_strings);
@ -242,11 +239,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return implode($delimeter, $this->full_path_strings);
}
/**
* Gets the path to this element (including the element itself)
* Gets the path to this element (including the element itself).
*
* @return self[] An array with all (recursivily) parent elements (including this one),
* ordered from the lowest levels (root node) first to the highest level (the element itself)
* ordered from the lowest levels (root node) first to the highest level (the element itself)
*/
public function getPathArray(): array
{
@ -254,7 +251,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;
}
@ -293,11 +290,13 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
******************************************************************************/
/**
* Sets the new parent object
* Sets the new parent object.
*
* @param self $new_parent The new parent object
*
* @return StructuralDBElement
*/
public function setParent(?self $new_parent) : self
public function setParent(?self $new_parent): self
{
/*
if ($new_parent->isChildOf($this)) {
@ -311,7 +310,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* Set the comment.
*
* @param string $new_comment the new comment
*
* @return StructuralDBElement
*/
public function setComment(?string $new_comment): self
@ -321,7 +322,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return $this;
}
public function setChildren(array $element) : self
public function setChildren(array $element): self
{
$this->children = $element;
@ -329,16 +330,16 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
}
/**
* @param bool $not_selectable
* @return StructuralDBElement
*/
public function setNotSelectable(bool $not_selectable): StructuralDBElement
public function setNotSelectable(bool $not_selectable): self
{
$this->not_selectable = $not_selectable;
return $this;
}
public function clearChildren() : self
public function clearChildren(): self
{
$this->children = new ArrayCollection();

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,17 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Base;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* A entity with these trait contains informations about, when it was created and edited last time
* @package App\Entity\Base
* A entity with these trait contains informations about, when it was created and edited last time.
*/
trait TimestampTrait
{
@ -80,4 +77,4 @@ trait TimestampTrait
$this->addedDate = new \DateTime('now');
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Devices;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Entity\Attachments\DeviceAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -66,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Device extends PartsContainingDBElement
{
/**
* @var Collection|DeviceAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\DeviceAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -137,8 +134,6 @@ class Device extends PartsContainingDBElement
* Set the order quantity.
*
* @param int $new_order_quantity the new order quantity
*
* @return self
*/
public function setOrderQuantity(int $new_order_quantity): self
{
@ -154,8 +149,6 @@ class Device extends PartsContainingDBElement
* 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
{

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -90,7 +89,6 @@ class DevicePart extends DBElement
*/
protected $mountnames;
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -56,7 +55,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Category extends PartsContainingDBElement
{
/**
* @var Collection|CategoryAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CategoryAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -147,12 +145,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $partname_hint
* @return Category
*/
public function setPartnameHint(string $partname_hint): Category
public function setPartnameHint(string $partname_hint): self
{
$this->partname_hint = $partname_hint;
return $this;
}
@ -165,12 +163,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $partname_regex
* @return Category
*/
public function setPartnameRegex(string $partname_regex): Category
public function setPartnameRegex(string $partname_regex): self
{
$this->partname_regex = $partname_regex;
return $this;
}
@ -183,12 +181,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_footprints
* @return Category
*/
public function setDisableFootprints(bool $disable_footprints): Category
public function setDisableFootprints(bool $disable_footprints): self
{
$this->disable_footprints = $disable_footprints;
return $this;
}
@ -201,12 +199,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_manufacturers
* @return Category
*/
public function setDisableManufacturers(bool $disable_manufacturers): Category
public function setDisableManufacturers(bool $disable_manufacturers): self
{
$this->disable_manufacturers = $disable_manufacturers;
return $this;
}
@ -219,12 +217,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_autodatasheets
* @return Category
*/
public function setDisableAutodatasheets(bool $disable_autodatasheets): Category
public function setDisableAutodatasheets(bool $disable_autodatasheets): self
{
$this->disable_autodatasheets = $disable_autodatasheets;
return $this;
}
@ -237,12 +235,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_properties
* @return Category
*/
public function setDisableProperties(bool $disable_properties): Category
public function setDisableProperties(bool $disable_properties): self
{
$this->disable_properties = $disable_properties;
return $this;
}
@ -255,12 +253,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $default_description
* @return Category
*/
public function setDefaultDescription(string $default_description): Category
public function setDefaultDescription(string $default_description): self
{
$this->default_description = $default_description;
return $this;
}
@ -273,14 +271,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $default_comment
* @return Category
*/
public function setDefaultComment(string $default_comment): Category
public function setDefaultComment(string $default_comment): self
{
$this->default_comment = $default_comment;
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -112,9 +110,10 @@ class Footprint extends PartsContainingDBElement
/**
* Returns the 3D Model associated with this footprint.
*
* @return FootprintAttachment|null
*/
public function getFootprint3d() : ?FootprintAttachment
public function getFootprint3d(): ?FootprintAttachment
{
return $this->footprint_3d;
}
@ -127,13 +126,13 @@ class Footprint extends PartsContainingDBElement
/**
* Sets the 3D Model associated with this footprint.
* @param FootprintAttachment|null $new_attachment
*
* @return Footprint
*/
public function setFootprint3d(?FootprintAttachment $new_attachment) : Footprint
public function setFootprint3d(?FootprintAttachment $new_attachment): self
{
$this->footprint_3d = $new_attachment;
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Base\Company;
use Doctrine\Common\Collections\Collection;
@ -72,7 +70,6 @@ class Manufacturer extends Company
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent")
*/

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,13 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -35,14 +32,12 @@ use Symfony\Component\Validator\Constraints as Assert;
* This unit represents the unit in which the amount of parts in stock are measured.
* This could be something like N, gramms, meters, etc...
*
* @package App\Entity
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
* @ORM\Table(name="`measurement_units`")
* @UniqueEntity("unit")
*/
class MeasurementUnit extends PartsContainingDBElement
{
/**
* @var Collection|MeasurementUnitAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -51,7 +46,7 @@ class MeasurementUnit extends PartsContainingDBElement
/**
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for gramms)
* or m (for meters).
* or m (for meters).
* @ORM\Column(type="string", name="unit", nullable=true)
* @Assert\Length(max=10)
*/
@ -59,14 +54,14 @@ class MeasurementUnit extends PartsContainingDBElement
/**
* @var bool Determines if the amount value associated with this unit should be treated as integer.
* Set to false, to measure continuous sizes likes masses or lengthes.
* Set to false, to measure continuous sizes likes masses or lengthes.
* @ORM\Column(type="boolean", name="is_integer")
*/
protected $is_integer = false;
/**
* @var bool Determines if the unit can be used with SI Prefixes (kilo, giga, milli, etc.).
* Useful for sizes like meters.
* Useful for sizes like meters.
* @ORM\Column(type="boolean", name="use_si_prefix")
*/
protected $use_si_prefix = false;
@ -92,11 +87,10 @@ class MeasurementUnit extends PartsContainingDBElement
* 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 'MU' . $this->getID();
return 'MU'.$this->getID();
}
/**
@ -109,11 +103,13 @@ class MeasurementUnit extends PartsContainingDBElement
/**
* @param string $unit
*
* @return MeasurementUnit
*/
public function setUnit(?string $unit): MeasurementUnit
public function setUnit(?string $unit): self
{
$this->unit = $unit;
return $this;
}
@ -126,12 +122,12 @@ class MeasurementUnit extends PartsContainingDBElement
}
/**
* @param bool $isInteger
* @return MeasurementUnit
*/
public function setIsInteger(bool $isInteger): MeasurementUnit
public function setIsInteger(bool $isInteger): self
{
$this->is_integer = $isInteger;
return $this;
}
@ -144,12 +140,12 @@ class MeasurementUnit extends PartsContainingDBElement
}
/**
* @param bool $usesSIPrefixes
* @return MeasurementUnit
*/
public function setUseSIPrefix(bool $usesSIPrefixes): MeasurementUnit
public function setUseSIPrefix(bool $usesSIPrefixes): self
{
$this->use_si_prefix = $usesSIPrefixes;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -54,9 +53,9 @@ namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Devices\Device;
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
use App\Entity\Parts\PartTraits\InstockTrait;
use App\Entity\Parts\PartTraits\ManufacturerTrait;
@ -64,7 +63,6 @@ use App\Entity\Parts\PartTraits\OrderTrait;
use App\Security\Annotations\ColumnSecurity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -143,7 +141,7 @@ class Part extends AttachmentContainingDBElement
*/
public function getIDString(): string
{
return 'P' . sprintf('%06d', $this->getID());
return 'P'.sprintf('%06d', $this->getID());
}
/**
@ -152,11 +150,9 @@ class Part extends AttachmentContainingDBElement
* @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
*
*/
public function getDevices(): array
{
return $this->devices;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts;
use App\Entity\Base\DBElement;
use App\Entity\Base\TimestampTrait;
use App\Entity\Parts\PartTraits\InstockTrait;
@ -34,7 +32,7 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity describes a lot where parts can be stored.
* It is the connection between a part and its store locations.
* @package App\Entity\Parts
*
* @ORM\Entity()
* @ORM\Table(name="part_lots")
* @ORM\HasLifecycleCallbacks()
@ -42,7 +40,6 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class PartLot extends DBElement
{
use TimestampTrait;
/**
@ -59,7 +56,7 @@ class PartLot extends DBElement
/**
* @var ?\DateTime Set a time until when the lot must be used.
* Set to null, if the lot can be used indefinitley.
* Set to null, if the lot can be used indefinitley.
* @ORM\Column(type="datetime", name="expiration_date", nullable=true)
*/
protected $expiration_date;
@ -86,7 +83,6 @@ class PartLot extends DBElement
*/
protected $instock_unknown = false;
/**
* @var float For continuos sizes (length, volume, etc.) the instock is saved here.
* @ORM\Column(type="float")
@ -95,7 +91,7 @@ class PartLot extends DBElement
protected $amount = 0;
/**
* @var boolean Determines if this lot was manually marked for refilling.
* @var bool Determines if this lot was manually marked for refilling.
* @ORM\Column(type="boolean")
*/
protected $needs_refill = false;
@ -105,21 +101,21 @@ class PartLot extends DBElement
* 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 'PL' . $this->getID();
return 'PL'.$this->getID();
}
/**
* Check if the current part lot is expired.
* This is the case, if the expiration date is greater the the current date.
*
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
*/
public function isExpired(): ?bool
{
if ($this->expiration_date === null) {
if (null === $this->expiration_date) {
return null;
}
@ -129,6 +125,7 @@ class PartLot extends DBElement
/**
* Gets the description of the part lot. Similar to a "name" of the part lot.
*
* @return string
*/
public function getDescription(): string
@ -138,17 +135,19 @@ class PartLot extends DBElement
/**
* Sets the description of the part lot.
* @param string $description
*
* @return PartLot
*/
public function setDescription(string $description): PartLot
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
/**
* Gets the comment for this part lot.
*
* @return string
*/
public function getComment(): string
@ -158,17 +157,19 @@ class PartLot extends DBElement
/**
* Sets the comment for this part lot.
* @param string $comment
*
* @return PartLot
*/
public function setComment(string $comment): PartLot
public function setComment(string $comment): self
{
$this->comment = $comment;
return $this;
}
/**
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
*
* @return \DateTime|null
*/
public function getExpirationDate(): ?\DateTime
@ -178,17 +179,21 @@ class PartLot extends DBElement
/**
* Sets the expiration date for the part lot. Set to null, if the part lot does not expires.
*
* @param \DateTime $expiration_date
*
* @return PartLot
*/
public function setExpirationDate(?\DateTime $expiration_date): PartLot
public function setExpirationDate(?\DateTime $expiration_date): self
{
$this->expiration_date = $expiration_date;
return $this;
}
/**
* Gets the storage locatiion, where this part lot is stored.
*
* @return Storelocation|null The store location where this part is stored
*/
public function getStorageLocation(): ?Storelocation
@ -197,18 +202,20 @@ class PartLot extends DBElement
}
/**
* Sets the storage location, where this part lot is stored
* @param Storelocation|null $storage_location
* Sets the storage location, where this part lot is stored.
*
* @return PartLot
*/
public function setStorageLocation(?Storelocation $storage_location): PartLot
public function setStorageLocation(?Storelocation $storage_location): self
{
$this->storage_location = $storage_location;
return $this;
}
/**
* Return the part that is stored in this part lot.
*
* @return Part
*/
public function getPart(): Part
@ -218,12 +225,15 @@ class PartLot extends DBElement
/**
* Sets the part that is stored in this part lot.
*
* @param Part|InstockTrait $part
*
* @return PartLot
*/
public function setPart(Part $part): PartLot
public function setPart(Part $part): self
{
$this->part = $part;
return $this;
}
@ -239,12 +249,13 @@ class PartLot extends DBElement
/**
* Set the unknown instock status of this part lot.
* @param bool $instock_unknown
*
* @return PartLot
*/
public function setInstockUnknown(bool $instock_unknown): PartLot
public function setInstockUnknown(bool $instock_unknown): self
{
$this->instock_unknown = $instock_unknown;
return $this;
}
@ -256,17 +267,17 @@ class PartLot extends DBElement
if ($this->part instanceof Part && !$this->part->useFloatAmount()) {
return round($this->amount);
}
return (float) $this->amount;
}
public function setAmount(float $new_amount): PartLot
public function setAmount(float $new_amount): self
{
$this->amount = $new_amount;
$this->amount = $new_amount;
return $this;
}
/**
* @return bool
*/
@ -276,14 +287,12 @@ class PartLot extends DBElement
}
/**
* @param bool $needs_refill
* @return PartLot
*/
public function setNeedsRefill(bool $needs_refill): PartLot
public function setNeedsRefill(bool $needs_refill): self
{
$this->needs_refill = $needs_refill;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
/**
* Advanced properties of a part, not related to a more specific group.
* @package App\Entity\Parts\PartTraits
*/
trait AdvancedPropertyTrait
{
@ -56,6 +53,7 @@ trait AdvancedPropertyTrait
/**
* Checks if this part is marked, for that it needs further review.
*
* @return bool
*/
public function isNeedsReview(): bool
@ -65,18 +63,19 @@ trait AdvancedPropertyTrait
/**
* Sets the "needs review" status of this part.
* @param bool $needs_review
*
* @return Part|self
*/
public function setNeedsReview(bool $needs_review): self
{
$this->needs_review = $needs_review;
return $this;
}
/**
* Gets a comma separated list, of tags, that are assigned to this part
* Gets a comma separated list, of tags, that are assigned to this part.
*
* @return string
*/
public function getTags(): string
@ -86,18 +85,20 @@ trait AdvancedPropertyTrait
/**
* Sets a comma separated list of tags, that are assigned to this part.
* @param string $tags
*
* @return self
*/
public function setTags(string $tags): self
{
$this->tags = $tags;
return $this;
}
/**
* Returns the mass of a single part unit.
* Returns null, if the mass is unknown/not set yet
* Returns null, if the mass is unknown/not set yet.
*
* @return float|null
*/
public function getMass(): ?float
@ -108,14 +109,13 @@ trait AdvancedPropertyTrait
/**
* Sets the mass of a single part unit.
* Sett to null, if the mass is unknown.
* @param float|null $mass
*
* @return self
*/
public function setMass(?float $mass): self
{
$this->mass = $mass;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
@ -60,7 +58,7 @@ trait BasicPropertyTrait
/**
* @var Category The category this part belongs too (e.g. Resistors). Use tags, for more complex grouping.
* Every part must have a category.
* Every part must have a category.
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts")
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
* @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category")
@ -80,6 +78,7 @@ trait BasicPropertyTrait
/**
* Get the description string like it is saved in the database.
* This can contain BBCode, it is not parsed yet.
*
* @return string the description
*/
public function getDescription(): string
@ -89,6 +88,7 @@ trait BasicPropertyTrait
/**
* Get the comment associated with this part.
*
* @return string The raw/unparsed comment
*/
public function getComment(): string
@ -99,6 +99,7 @@ trait BasicPropertyTrait
/**
* Get if this part is visible.
* This property is not used yet.
*
* @return bool true if this part is visible
* false if this part isn't visible
*/
@ -109,6 +110,7 @@ trait BasicPropertyTrait
/**
* Check if this part is a favorite.
*
* @return bool * true if this part is a favorite
* * false if this part is not a favorite.
*/
@ -117,10 +119,10 @@ trait BasicPropertyTrait
return $this->favorite;
}
/**
* Get the category of this part (e.g. Resistors).
* There is always a category, for each part!
*
* @return Category the category of this part
*/
public function getCategory(): ?Category
@ -129,7 +131,8 @@ trait BasicPropertyTrait
}
/**
* Gets the Footprint of this part (e.g. DIP8)
* Gets the Footprint of this part (e.g. DIP8).
*
* @return Footprint|null The footprint of this part. Null if this part should no have a footprint.
*/
public function getFootprint(): ?Footprint
@ -139,36 +142,44 @@ trait BasicPropertyTrait
/**
* Sets the description of this part.
*
* @param string $new_description the new description
*
* @return self
*/
public function setDescription(?string $new_description): self
{
$this->description = $new_description;
return $this;
}
/**
* Sets the comment property of this part.
*
* @param string $new_comment the new comment
*
* @return self
*/
public function setComment(string $new_comment): self
{
$this->comment = $new_comment;
return $this;
}
/**
* Set the category of this Part.
* The category property is required for every part, so you can not pass null like the other properties (footprints)
* The category property is required for every part, so you can not pass null like the other properties (footprints).
*
* @param Category $category The new category of this part
*
* @return self
*/
public function setCategory(Category $category): self
{
$this->category = $category;
return $this;
}
@ -183,6 +194,7 @@ trait BasicPropertyTrait
public function setFootprint(?Footprint $new_footprint): self
{
$this->footprint = $new_footprint;
return $this;
}
@ -197,7 +209,7 @@ trait BasicPropertyTrait
public function setFavorite(bool $new_favorite_status): self
{
$this->favorite = $new_favorite_status;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot;
use App\Security\Annotations\ColumnSecurity;
@ -30,7 +28,6 @@ use Doctrine\Common\Collections\Collection;
/**
* This trait collects all aspects of a part related to instock, part lots.
* @package App\Entity\Parts\PartTraits
*/
trait InstockTrait
{
@ -44,7 +41,7 @@ trait InstockTrait
/**
* @var float The minimum amount of the part that has to be instock, otherwise more is ordered.
* Given in the partUnit.
* Given in the partUnit.
* @ORM\Column(type="float")
* @Assert\PositiveOrZero()
* @ColumnSecurity(prefix="mininstock", type="integer")
@ -61,9 +58,10 @@ trait InstockTrait
/**
* Get all part lots where this part is stored.
*
* @return PartLot[]|Collection
*/
public function getPartLots() : Collection
public function getPartLots(): Collection
{
return $this->partLots;
}
@ -71,30 +69,35 @@ trait InstockTrait
/**
* Adds the given part lot, to the list of part lots.
* The part lot is assigned to this part.
* @param PartLot $lot
*
* @return self
*/
public function addPartLot(PartLot $lot): self
{
$lot->setPart($this);
$this->partLots->add($lot);
return $this;
}
/**
* Removes the given part lot from the list of part lots.
*
* @param PartLot $lot The part lot that should be deleted.
*
* @return self
*/
public function removePartLot(PartLot $lot): self
{
$this->partLots->removeElement($lot);
return $this;
}
/**
* Gets the measurement unit in which the part's amount should be measured.
* Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers.
*
* @return MeasurementUnit|null
*/
public function getPartUnit(): ?MeasurementUnit
@ -105,18 +108,19 @@ trait InstockTrait
/**
* Sets the measurement unit in which the part's amount should be measured.
* Set to null, if the part should be measured in quantities.
* @param MeasurementUnit|null $partUnit
*
* @return self
*/
public function setPartUnit(?MeasurementUnit $partUnit): self
{
$this->partUnit = $partUnit;
return $this;
}
/**
* Get the count of parts which must be in stock at least.
* If a integer-based part unit is selected, the value will be rounded to integers
* If a integer-based part unit is selected, the value will be rounded to integers.
*
* @return float count of parts which must be in stock at least
*/
@ -132,6 +136,7 @@ trait InstockTrait
/**
* Checks if this part uses the float amount .
* This setting is based on the part unit (see MeasurementUnit->isInteger()).
*
* @return bool True if the float amount field should be used. False if the integer instock field should be used.
*/
public function useFloatAmount(): bool
@ -146,10 +151,11 @@ trait InstockTrait
/**
* Returns the summed amount of this part (over all part lots)
* Part Lots that have unknown value or are expired, are not used for this value
* Part Lots that have unknown value or are expired, are not used for this value.
*
* @return float The amount of parts given in partUnit
*/
public function getAmountSum() : float
public function getAmountSum(): float
{
//TODO: Find a method to do this natively in SQL, the current method could be a bit slow
$sum = 0;
@ -172,12 +178,15 @@ trait InstockTrait
/**
* Set the minimum amount of parts that have to be instock.
* See getPartUnit() for the associated unit.
*
* @param float $new_minamount the new count of parts which should be in stock at least
*
* @return self
*/
public function setMinAmount(float $new_minamount): self
{
$this->minamount = $new_minamount;
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
@ -30,7 +28,6 @@ use App\Validator\Constraints\Selectable;
/**
* In this trait all manufacturer related properties of a part are collected (like MPN, manufacturer URL).
* @package App\Entity\Parts\PartTraits
*/
trait ManufacturerTrait
{
@ -70,6 +67,7 @@ trait ManufacturerTrait
* Get the link to the website of the article on the manufacturers website
* When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part
* automatically.
*
* @return string the link to the article
*/
public function getManufacturerProductUrl(): string
@ -87,6 +85,7 @@ trait ManufacturerTrait
/**
* Similar to getManufacturerProductUrl, but here only the database value is returned.
*
* @return string The manufacturer url saved in DB for this part.
*/
public function getCustomProductURL(): string
@ -103,7 +102,8 @@ trait ManufacturerTrait
* * "active": Part is in production and will be for the forseeable future
* * "nrfnd": Not recommended for new designs.
* * "eol": Part will become discontinued soon
* * "discontinued": Part is obsolete/discontinued by the manufacturer
* * "discontinued": Part is obsolete/discontinued by the manufacturer.
*
* @return string
*/
public function getManufacturingStatus(): ?string
@ -114,12 +114,13 @@ trait ManufacturerTrait
/**
* Sets the manufacturing status for this part
* See getManufacturingStatus() for valid values.
* @param string $manufacturing_status
*
* @return Part
*/
public function setManufacturingStatus(string $manufacturing_status): self
{
$this->manufacturing_status = $manufacturing_status;
return $this;
}
@ -133,9 +134,9 @@ trait ManufacturerTrait
return $this->manufacturer;
}
/**
* Returns the assigned manufacturer product number (MPN) for this part.
*
* @return string
*/
public function getManufacturerProductNumber(): string
@ -145,19 +146,22 @@ trait ManufacturerTrait
/**
* Sets the manufacturer product number (MPN) for this part.
* @param string $manufacturer_product_number
*
* @return Part
*/
public function setManufacturerProductNumber(string $manufacturer_product_number): self
{
$this->manufacturer_product_number = $manufacturer_product_number;
return $this;
}
/**
* 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
@ -181,5 +185,4 @@ trait ManufacturerTrait
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity;
@ -30,7 +28,6 @@ use Doctrine\Common\Collections\Collection;
/**
* This trait collects all aspects of a part related to orders and priceinformations.
* @package App\Entity\Parts\PartTraits
*/
trait OrderTrait
{
@ -67,6 +64,7 @@ trait OrderTrait
/**
* Get the selected order orderdetails of this part.
*
* @return Orderdetail the selected order orderdetails
*/
public function getOrderOrderdetails(): ?Orderdetail
@ -76,6 +74,7 @@ trait OrderTrait
/**
* Get the order quantity of this part.
*
* @return int the order quantity
*/
public function getOrderQuantity(): int
@ -99,11 +98,10 @@ trait OrderTrait
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
*
* @return Collection|Orderdetail[] * 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
*
* (empty array if there are no ones)
* * the array is sorted by the suppliers names / minimum order quantity
*/
public function getOrderdetails(bool $hide_obsolete = false) : Collection
public function getOrderdetails(bool $hide_obsolete = false): Collection
{
//If needed hide the obsolete entries
if ($hide_obsolete) {
@ -123,38 +121,42 @@ trait OrderTrait
/**
* Adds the given orderdetail to list of orderdetails.
* The orderdetail is assigned to this part.
*
* @param Orderdetail $orderdetail The orderdetail that should be added.
*
* @return self
*/
public function addOrderdetail(Orderdetail $orderdetail) : self
public function addOrderdetail(Orderdetail $orderdetail): self
{
$orderdetail->setPart($this);
$this->orderdetails->add($orderdetail);
return $this;
}
/**
* Removes the given orderdetail from the list of orderdetails.
* @param Orderdetail $orderdetail
*
* @return OrderTrait
*/
public function removeOrderdetail(Orderdetail $orderdetail) : self
public function removeOrderdetail(Orderdetail $orderdetail): self
{
$this->orderdetails->removeElement($orderdetail);
return $this;
}
/**
* Set the "manual_order" attribute.
*
* @param bool $new_manual_order the new "manual_order" attribute
* @param int $new_order_quantity the new order quantity
* @param bool $new_manual_order the new "manual_order" attribute
* @param int $new_order_quantity the new order quantity
* @param Orderdetail|null $new_order_orderdetail * 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")
* * 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
*/
@ -183,7 +185,7 @@ trait OrderTrait
{
$all_orderdetails = $this->getOrderdetails();
if (0 === count($all_orderdetails)) {
if (0 === \count($all_orderdetails)) {
return false;
}
@ -195,5 +197,4 @@ trait OrderTrait
return true;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -66,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Storelocation extends PartsContainingDBElement
{
/**
* @var Collection|StorelocationAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -148,12 +145,12 @@ class Storelocation extends PartsContainingDBElement
}
/**
* @param bool $only_single_part
* @return Storelocation
*/
public function setOnlySinglePart(bool $only_single_part): Storelocation
public function setOnlySinglePart(bool $only_single_part): self
{
$this->only_single_part = $only_single_part;
return $this;
}
@ -168,12 +165,12 @@ class Storelocation extends PartsContainingDBElement
}
/**
* @param bool $limit_to_existing_parts
* @return Storelocation
*/
public function setLimitToExistingParts(bool $limit_to_existing_parts): Storelocation
public function setLimitToExistingParts(bool $limit_to_existing_parts): self
{
$this->limit_to_existing_parts = $limit_to_existing_parts;
return $this;
}
@ -186,17 +183,15 @@ class Storelocation extends PartsContainingDBElement
}
/**
* @param MeasurementUnit|null $storage_type
* @return Storelocation
*/
public function setStorageType(?MeasurementUnit $storage_type): Storelocation
public function setStorageType(?MeasurementUnit $storage_type): self
{
$this->storage_type = $storage_type;
return $this;
}
/********************************************************************************
*
* Setters
@ -211,9 +206,10 @@ class Storelocation extends PartsContainingDBElement
*
* @param bool $new_is_full * true means that the storelocation is full
* * false means that the storelocation isn't full
*
* @return Storelocation
*/
public function setIsFull(bool $new_is_full): Storelocation
public function setIsFull(bool $new_is_full): self
{
$this->is_full = $new_is_full;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\Company;
use App\Entity\PriceInformations\Currency;
@ -93,7 +91,7 @@ class Supplier extends Company
/**
* @var Currency|null The currency that should be used by default for order informations with this supplier.
* Set to null, to use global base currency.
* Set to null, to use global base currency.
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
* @ORM\JoinColumn(name="default_currency_id", referencedColumnName="id", nullable=true)
* @Selectable()
@ -101,7 +99,7 @@ class Supplier extends Company
protected $default_currency;
/**
* @var float|null The shipping costs that have to be paid, when ordering via this supplier.
* @var float|null the shipping costs that have to be paid, when ordering via this supplier
* @ORM\Column(name="shipping_costs", nullable=true, type="decimal", precision=11, scale=5)
* @Assert\PositiveOrZero()
*/
@ -118,45 +116,48 @@ class Supplier extends Company
/**
* Gets the currency that should be used by default, when creating a orderdetail with this supplier.
*
* @return ?Currency
*/
public function getDefaultCurrency() : ?Currency
public function getDefaultCurrency(): ?Currency
{
return $this->default_currency;
}
/**
* Sets the default currency.
*
* @param ?Currency $default_currency
* @return Supplier
*/
public function setDefaultCurrency(?Currency $default_currency) : Supplier
public function setDefaultCurrency(?Currency $default_currency): self
{
$this->default_currency = $default_currency;
return $this;
}
/**
* Gets the shipping costs for an order with this supplier, given in base currency.
*
* @return string|null A bcmath string with the shipping costs
*/
public function getShippingCosts() : ?string
public function getShippingCosts(): ?string
{
return $this->shipping_costs;
}
/**
* Sets the shipping costs for an order with this supplier.
* @param string|null $shipping_costs A bcmath string with the shipping costs.
* @return Supplier
*
* @param string|null $shipping_costs a bcmath string with the shipping costs
*/
public function setShippingCosts(?string $shipping_costs) : Supplier
public function setShippingCosts(?string $shipping_costs): self
{
$this->shipping_costs = $shipping_costs;
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.

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\PriceInformations;
use App\Entity\Attachments\CurrencyAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\StructuralDBElement;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -33,14 +30,13 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity describes a currency that can be used for price informations.
* @package App\Entity
*
* @UniqueEntity("iso_code")
* @ORM\Entity()
* @ORM\Table(name="currencies")
*/
class Currency extends StructuralDBElement
{
public const PRICE_SCALE = 5;
/**
@ -58,7 +54,7 @@ class Currency extends StructuralDBElement
/**
* @var string|null The exchange rate between this currency and the base currency
* (how many base units the current currency is worth)
* (how many base units the current currency is worth)
* @ORM\Column(type="decimal", precision=11, scale=5, nullable=true)
* @Assert\Positive()
*/
@ -76,7 +72,8 @@ class Currency extends StructuralDBElement
protected $parent;
/**
* Returns the 3 letter ISO code of this currency
* Returns the 3 letter ISO code of this currency.
*
* @return string
*/
public function getIsoCode(): ?string
@ -86,23 +83,26 @@ class Currency extends StructuralDBElement
/**
* @param string $iso_code
*
* @return Currency
*/
public function setIsoCode(?string $iso_code): Currency
public function setIsoCode(?string $iso_code): self
{
$this->iso_code = $iso_code;
return $this;
}
/**
* Returns the inverse exchange rate (how many of the current currency the base unit is worth)
* Returns the inverse exchange rate (how many of the current currency the base unit is worth).
*
* @return string|null
*/
public function getInverseExchangeRate(): ?string
{
$tmp = $this->getExchangeRate();
if ($tmp === null || $tmp === "0") {
if (null === $tmp || '0' === $tmp) {
return null;
}
@ -111,7 +111,8 @@ class Currency extends StructuralDBElement
/**
* Returns The exchange rate between this currency and the base currency
* (how many base units the current currency is worth)
* (how many base units the current currency is worth).
*
* @return string|null
*/
public function getExchangeRate(): ?string
@ -120,25 +121,23 @@ class Currency extends StructuralDBElement
}
/**
* @param string|null $exchange_rate
* @return Currency
*/
public function setExchangeRate(?string $exchange_rate): Currency
public function setExchangeRate(?string $exchange_rate): self
{
$this->exchange_rate = $exchange_rate;
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 'C' . $this->getID();
return 'C'.$this->getID();
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -193,7 +192,7 @@ class Orderdetail extends DBElement
return $this->supplier_product_url;
}
if ($this->getSupplier() === null) {
if (null === $this->getSupplier()) {
return '';
}
@ -204,7 +203,7 @@ class Orderdetail extends DBElement
* Get all pricedetails.
*
* @return Pricedetail[]|Collection all pricedetails as a one-dimensional array of Pricedetails objects,
* sorted by minimum discount quantity
* sorted by minimum discount quantity
*/
public function getPricedetails(): Collection
{
@ -212,36 +211,41 @@ class Orderdetail extends DBElement
}
/**
* Adds an pricedetail to this orderdetail
* Adds an pricedetail to this orderdetail.
*
* @param Pricedetail $pricedetail The pricedetail to add
*
* @return Orderdetail
*/
public function addPricedetail(Pricedetail $pricedetail) : Orderdetail
public function addPricedetail(Pricedetail $pricedetail): self
{
$pricedetail->setOrderdetail($this);
$this->pricedetails->add($pricedetail);
return $this;
}
/**
* Removes an pricedetail from this orderdetail
* @param Pricedetail $pricedetail
* Removes an pricedetail from this orderdetail.
*
* @return Orderdetail
*/
public function removePricedetail(Pricedetail $pricedetail) : Orderdetail
public function removePricedetail(Pricedetail $pricedetail): self
{
$this->pricedetails->removeElement($pricedetail);
return $this;
}
/**
* Find the pricedetail that is correct for the desired amount (the one with the greatest discount value with a
* minimum order amount of the wished quantity)
* @param float $quantity this is the quantity to choose the correct pricedetails
* minimum order amount of the wished quantity).
*
* @param float $quantity this is the quantity to choose the correct pricedetails
*
* @return Pricedetail|null: the price as a bcmath string. Null if there are no orderdetails for the given quantity
*/
public function findPriceForQty(float $quantity = 1) : ?Pricedetail
public function findPriceForQty(float $quantity = 1): ?Pricedetail
{
if ($quantity <= 0) {
return null;
@ -269,30 +273,34 @@ class Orderdetail extends DBElement
*********************************************************************************/
/**
* Sets a new part with which this orderdetail is associated
* @param Part $part
* Sets a new part with which this orderdetail is associated.
*
* @return Orderdetail
*/
public function setPart(Part $part) : Orderdetail
public function setPart(Part $part): self
{
$this->part = $part;
return $this;
}
/**
* Sets the new supplier associated with this orderdetail.
* @param Supplier $new_supplier
*
* @return Orderdetail
*/
public function setSupplier(Supplier $new_supplier) : Orderdetail
public function setSupplier(Supplier $new_supplier): self
{
$this->supplier = $new_supplier;
return $this;
}
/**
* Set the supplier part-nr.
*
* @param string $new_supplierpartnr the new supplier-part-nr
*
* @return Orderdetail
* @return Orderdetail
*/
@ -305,7 +313,9 @@ class Orderdetail extends DBElement
/**
* Set if the part is obsolete at the supplier of that orderdetails.
*
* @param bool $new_obsolete true means that this part is obsolete
*
* @return Orderdetail
* @return Orderdetail
*/
@ -319,10 +329,12 @@ 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.
*
* @return Orderdetail
*/
public function setSupplierProductUrl(string $new_url) : Orderdetail
public function setSupplierProductUrl(string $new_url): self
{
//Only change the internal URL if it is not the auto generated one
if ($new_url === $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) {

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -69,7 +68,6 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class Pricedetail extends DBElement
{
public const PRICE_PRECISION = 5;
use TimestampTrait;
@ -91,7 +89,7 @@ class Pricedetail extends DBElement
/**
* @var ?Currency The currency used for the current price information.
* If this is null, the global base unit is assumed.
* If this is null, the global base unit is assumed.
* @ORM\ManyToOne(targetEntity="Currency")
* @ORM\JoinColumn(name="id_currency", referencedColumnName="id", nullable=true)
* @Selectable()
@ -142,9 +140,10 @@ class Pricedetail extends DBElement
/**
* Returns the price associated with this pricedetail.
* It is given in current currency and for the price related quantity.
*
* @return string The price as string, like returned raw from DB.
*/
public function getPrice() : string
public function getPrice(): string
{
return $this->price;
}
@ -152,18 +151,19 @@ class Pricedetail extends DBElement
/**
* Get the price for a single unit in the currency associated with this price detail.
*
* @param float|string $multiplier The returned price (float or string) will be multiplied
* with this multiplier.
* @param float|string $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 string the price as a bcmath string
* @return string the price as a bcmath string
*/
public function getPricePerUnit($multiplier = 1.0) : string
public function getPricePerUnit($multiplier = 1.0): string
{
$multiplier = (string) $multiplier;
$tmp = bcmul($this->price, $multiplier, static::PRICE_PRECISION);
return bcdiv($tmp, (string) $this->price_related_quantity, static::PRICE_PRECISION);
//return ($this->price * $multiplier) / $this->price_related_quantity;
}
@ -180,10 +180,12 @@ 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;
}
return $this->price_related_quantity;
}
@ -203,6 +205,7 @@ class Pricedetail extends DBElement
{
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->min_discount_quantity);
return $tmp < 1 ? 1 : $tmp;
}
@ -212,6 +215,7 @@ class Pricedetail extends DBElement
/**
* Returns the currency associated with this price information.
* Returns null, if no specific currency is selected and the global base currency should be assumed.
*
* @return Currency|null
*/
public function getCurrency(): ?Currency
@ -227,24 +231,26 @@ class Pricedetail extends DBElement
/**
* Sets the orderdetail to which this pricedetail belongs to.
* @param Orderdetail $orderdetail
*
* @return $this
*/
public function setOrderdetail(Orderdetail $orderdetail) : self
public function setOrderdetail(Orderdetail $orderdetail): self
{
$this->orderdetail = $orderdetail;
return $this;
}
/**
* Sets the currency associated with the price informations.
* Set to null, to use the global base currency.
* @param Currency|null $currency
*
* @return Pricedetail
*/
public function setCurrency(?Currency $currency): Pricedetail
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
@ -259,7 +265,7 @@ class Pricedetail extends DBElement
*
* @return self
*/
public function setPrice(string $new_price): Pricedetail
public function setPrice(string $new_price): self
{
//Assert::natural($new_price, 'The new price must be positive! Got %s!');
@ -322,6 +328,6 @@ class Pricedetail extends DBElement
*/
public function getIDString(): string
{
return 'PD' . sprintf('%06d', $this->getID());
return 'PD'.sprintf('%06d', $this->getID());
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,13 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\UserSystem;
use App\Entity\Attachments\GroupAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\StructuralDBElement;
use App\Security\Interfaces\HasPermissionsInterface;
use App\Validator\Constraints\ValidPermission;
@ -38,7 +36,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Group extends StructuralDBElement implements HasPermissionsInterface
{
/**
* @var Collection|GroupAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\UserSystem;
@ -293,10 +292,12 @@ class PermissionsEmbed
/**
* Checks whether a permission with the given name is valid for this object.
* @param string $permission_name The name of the permission which should be checked for.
* @return bool True if the permission is existing on this object.
*
* @param string $permission_name the name of the permission which should be checked for
*
* @return bool true if the permission is existing on this object
*/
public function isValidPermissionName(string $permission_name) : bool
public function isValidPermissionName(string $permission_name): bool
{
return isset($this->$permission_name);
}
@ -304,8 +305,8 @@ class PermissionsEmbed
/**
* Returns the bit pair value of the given permission.
*
* @param string $permission_name The name of the permission, for which the bit pair should be returned.
* @param int $bit_n The (lower) bit number of the bit pair, which should be read.
* @param string $permission_name the name of the permission, for which the bit pair should be returned
* @param int $bit_n the (lower) bit number of the bit pair, which should be read
*
* @return int The value of the bit pair. Compare to the INHERIT, ALLOW, and DISALLOW consts in this class.
*/
@ -323,8 +324,8 @@ 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 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
*
* @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.
@ -345,19 +346,21 @@ class PermissionsEmbed
/**
* Sets the value of the given permission and operation.
* @param string $permission_name The name of the permission, for which the bit pair should be written.
* @param int $bit_n The (lower) bit number of the bit pair, which should be written.
* @param bool|null $new_value The new value for the operation:
* True, if the given operation is allowed, false if disallowed
* and null if it should inherit from parent.
* @return PermissionsEmbed The instance itself.
*
* @param string $permission_name the name of the permission, for which the bit pair should be written
* @param int $bit_n the (lower) bit number of the bit pair, which should be written
* @param bool|null $new_value the new value for the operation:
* True, if the given operation is allowed, false if disallowed
* and null if it should inherit from parent
*
* @return PermissionsEmbed the instance itself
*/
public function setPermissionValue(string $permission_name, int $bit_n, ?bool $new_value) : self
public function setPermissionValue(string $permission_name, int $bit_n, ?bool $new_value): self
{
//Determine which bit value the given value is.
if ($new_value === true) {
if (true === $new_value) {
$bit_value = static::ALLOW;
} elseif ($new_value === false) {
} elseif (false === $new_value) {
$bit_value = static::DISALLOW;
} else {
$bit_value = static::INHERIT;
@ -370,12 +373,14 @@ class PermissionsEmbed
/**
* Sets the bit value of the given permission and operation.
* @param string $permission_name The name of the permission, for which the bit pair should be written.
* @param int $bit_n The (lower) bit number of the bit pair, which should be written.
* @param int $new_value The new (bit) value of the bit pair, which should be written.
* @return PermissionsEmbed The instance itself.
*
* @param string $permission_name the name of the permission, for which the bit pair should be written
* @param int $bit_n the (lower) bit number of the bit pair, which should be written
* @param int $new_value the new (bit) value of the bit pair, which should be written
*
* @return PermissionsEmbed the instance itself
*/
public function setBitValue(string $permission_name, int $bit_n, int $new_value) : self
public function setBitValue(string $permission_name, int $bit_n, int $new_value): self
{
if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!');
@ -387,12 +392,14 @@ class PermissionsEmbed
}
/**
* Returns the given permission as raw int (all bit at once)
* Returns the given permission as raw int (all bit at once).
*
* @param string $permission_name The name of the permission, which should be retrieved.
* If this is not existing an exception is thrown.
* @return int The raw permission value.
* If this is not existing an exception is thrown.
*
* @return int the raw permission value
*/
public function getRawPermissionValue(string $permission_name) : int
public function getRawPermissionValue(string $permission_name): int
{
if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!');
@ -403,30 +410,33 @@ class PermissionsEmbed
/**
* Sets the given permission to the value.
* @param string $permission_name The name of the permission to that should be set.
* @param int $value The new value of the permsission
*
* @param string $permission_name the name of the permission to that should be set
* @param int $value The new value of the permsission
*
* @return $this
*/
public function setRawPermissionValue(string $permission_name, int $value) : self
public function setRawPermissionValue(string $permission_name, int $value): self
{
if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException(
sprintf('No permission with the given name %s is existing!', $permission_name)
);
throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
}
$this->$permission_name = $value;
return $this;
}
/**
* Sets multiple permissions at once.
* @param array $values An array in the form ['perm_name' => $value], containing the new data
* @param array|null $values2 If this array is not null, the first array will treated of list of perm names,
* and this array as an array of new values.
*
* @param array $values An array in the form ['perm_name' => $value], containing the new data
* @param array|null $values2 if this array is not null, the first array will treated of list of perm names,
* and this array as an array of new values
*
* @return $this
*/
public function setRawPermissionValues(array $values, array $values2 = null) : self
public function setRawPermissionValues(array $values, array $values2 = null): self
{
if (!empty($values2)) {
$values = array_combine($values, $values2);
@ -435,16 +445,17 @@ class PermissionsEmbed
foreach ($values as $key => $value) {
$this->setRawPermissionValue($key, $value);
}
return $this;
}
/**
* Reads a bit pair from $data.
*
* @param $data int The data from where the bits should be extracted from.
* @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.
* @return int the value of the bit pair
*/
final protected static function readBitPair(int $data, int $n): int
{
@ -460,11 +471,11 @@ 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 $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.
* @return int the new data with the modified pair
*/
final protected static function writeBitPair(int $data, int $n, int $new): int
{

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -53,7 +52,6 @@ declare(strict_types=1);
namespace App\Entity\UserSystem;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Base\NamedDBElement;
use App\Entity\PriceInformations\Currency;
@ -82,7 +80,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public const AVAILABLE_THEMES = ['bootstrap', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal',
'litera', 'lumen', 'lux', 'materia', 'minty', 'pulse', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar',
'spacelab', 'united', 'yeti'];
'spacelab', 'united', 'yeti', ];
/**
* @var Collection|UserAttachment[]
@ -182,9 +180,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* @var Currency|null The currency the user wants to see prices in.
* Dont use fetch=EAGER here, this will cause problems with setting the currency setting.
* TODO: This is most likely a bug in doctrine/symfony related to the UniqueEntity constraint (it makes a db call).
* TODO: Find a way to use fetch EAGER (this improves performance a bit)
* Dont use fetch=EAGER here, this will cause problems with setting the currency setting.
* TODO: This is most likely a bug in doctrine/symfony related to the UniqueEntity constraint (it makes a db call).
* TODO: Find a way to use fetch EAGER (this improves performance a bit)
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
* @ORM\JoinColumn(name="currency_id", referencedColumnName="id")
* @Selectable()
@ -225,7 +223,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
protected $disabled = false;
public function __construct()
{
parent::__construct();
@ -284,8 +281,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Sets the password hash for this user.
*
* @param string $password
*
* @return User
*/
public function setPassword(string $password): self
@ -314,6 +309,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Gets the currency the user prefers when showing him prices.
*
* @return Currency|null The currency the user prefers, or null if the global currency should be used.
*/
public function getCurrency(): ?Currency
@ -323,17 +319,19 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Sets the currency the users prefers to see prices in.
* @param Currency|null $currency
*
* @return User
*/
public function setCurrency(?Currency $currency): User
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
/**
* Checks if this user is disabled (user cannot login any more).
*
* @return bool True, if the user is disabled.
*/
public function isDisabled(): bool
@ -343,17 +341,18 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Sets the status if a user is disabled.
*
* @param bool $disabled True if the user should be disabled.
*
* @return User
*/
public function setDisabled(bool $disabled): User
public function setDisabled(bool $disabled): self
{
$this->disabled = $disabled;
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.
@ -371,7 +370,8 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
}
/**
* Check if the user needs a password change
* Check if the user needs a password change.
*
* @return bool
*/
public function isNeedPwChange(): bool
@ -381,12 +381,13 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Set the status, if the user needs a password change.
* @param bool $need_pw_change
*
* @return User
*/
public function setNeedPwChange(bool $need_pw_change): User
public function setNeedPwChange(bool $need_pw_change): self
{
$this->need_pw_change = $need_pw_change;
return $this;
}
@ -394,8 +395,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* Getters
************************************************/
/**
* Returns the full name in the format FIRSTNAME LASTNAME [(USERNAME)].
* Example: Max Muster (m.muster).
@ -436,7 +435,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setFirstName(?string $first_name): User
public function setFirstName(?string $first_name): self
{
$this->first_name = $first_name;
@ -456,7 +455,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setLastName(?string $last_name): User
public function setLastName(?string $last_name): self
{
$this->last_name = $last_name;
@ -476,7 +475,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setDepartment(?string $department): User
public function setDepartment(?string $department): self
{
$this->department = $department;
@ -496,7 +495,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setEmail(?string $email): User
public function setEmail(?string $email): self
{
$this->email = $email;
@ -516,7 +515,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setLanguage(?string $language): User
public function setLanguage(?string $language): self
{
$this->language = $language;
@ -536,7 +535,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setTimezone(?string $timezone): User
public function setTimezone(?string $timezone): self
{
$this->timezone = $timezone;
@ -556,7 +555,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setTheme(?string $theme): User
public function setTheme(?string $theme): self
{
$this->theme = $theme;
@ -578,6 +577,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public function __toString()
{
$tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true) . $tmp;
return $this->getFullName(true).$tmp;
}
}